List of usage examples for org.apache.http.client.methods HttpUriRequest getParams
@Deprecated HttpParams getParams();
From source file:com.tek271.reverseProxy.servlet.ProxyFilter.java
private static void printParams(HttpUriRequest request) { HttpParams params = request.getParams(); System.out.println(params); }
From source file:com.android.internal.location.GpsXtraDownloader.java
protected static byte[] doDownload(String url, boolean isProxySet, String proxyHost, int proxyPort) { AndroidHttpClient client = null;/*from w ww . j a v a 2 s . c o m*/ try { client = AndroidHttpClient.newInstance("Android"); HttpUriRequest req = new HttpGet(url); if (isProxySet) { HttpHost proxy = new HttpHost(proxyHost, proxyPort); ConnRouteParams.setDefaultProxy(req.getParams(), proxy); } req.addHeader("Accept", "*/*, application/vnd.wap.mms-message, application/vnd.wap.sic"); req.addHeader("x-wap-profile", "http://www.openmobilealliance.org/tech/profiles/UAPROF/ccppschema-20021212#"); HttpResponse response = client.execute(req); StatusLine status = response.getStatusLine(); if (status.getStatusCode() != 200) { // HTTP 200 is success. Log.d(TAG, "HTTP error: " + status.getReasonPhrase()); return null; } HttpEntity entity = response.getEntity(); byte[] body = null; if (entity != null) { try { if (entity.getContentLength() > 0) { body = new byte[(int) entity.getContentLength()]; DataInputStream dis = new DataInputStream(entity.getContent()); try { dis.readFully(body); } finally { try { dis.close(); } catch (IOException e) { Log.e(TAG, "Unexpected IOException.", e); } } } } finally { if (entity != null) { entity.consumeContent(); } } } return body; } catch (Exception e) { Log.d(TAG, "error " + e); } finally { if (client != null) { client.close(); } } return null; }
From source file:com.android.server.location.GpsXtraDownloader.java
protected static byte[] doDownload(String url, boolean isProxySet, String proxyHost, int proxyPort) { if (DEBUG)//from w ww.j av a2s . c o m Log.d(TAG, "Downloading XTRA data from " + url); AndroidHttpClient client = null; try { client = AndroidHttpClient.newInstance("Android"); HttpUriRequest req = new HttpGet(url); if (isProxySet) { HttpHost proxy = new HttpHost(proxyHost, proxyPort); ConnRouteParams.setDefaultProxy(req.getParams(), proxy); } req.addHeader("Accept", "*/*, application/vnd.wap.mms-message, application/vnd.wap.sic"); req.addHeader("x-wap-profile", "http://www.openmobilealliance.org/tech/profiles/UAPROF/ccppschema-20021212#"); HttpResponse response = client.execute(req); StatusLine status = response.getStatusLine(); if (status.getStatusCode() != 200) { // HTTP 200 is success. if (DEBUG) Log.d(TAG, "HTTP error: " + status.getReasonPhrase()); return null; } HttpEntity entity = response.getEntity(); byte[] body = null; if (entity != null) { try { if (entity.getContentLength() > 0) { body = new byte[(int) entity.getContentLength()]; DataInputStream dis = new DataInputStream(entity.getContent()); try { dis.readFully(body); } finally { try { dis.close(); } catch (IOException e) { Log.e(TAG, "Unexpected IOException.", e); } } } } finally { if (entity != null) { entity.consumeContent(); } } } return body; } catch (Exception e) { if (DEBUG) Log.d(TAG, "error " + e); } finally { if (client != null) { client.close(); } } return null; }
From source file:com.dropbox.client2.RESTUtility.java
/** * Executes an {@link HttpUriRequest} with the given {@link Session} and * returns an {@link HttpResponse}.//from www.j a v a2s . co m * * @param session the session to use. * @param req the request to execute. * @param socketTimeoutOverrideMs if >= 0, the socket timeout to set on * this request. Does nothing if set to a negative number. * * @return an {@link HttpResponse}. * * @throws DropboxServerException if the server responds with an error * code. See the constants in {@link DropboxServerException} for * the meaning of each error code. * @throws DropboxIOException if any network-related error occurs. * @throws DropboxUnlinkedException if the user has revoked access. * @throws DropboxException for any other unknown errors. This is also a * superclass of all other Dropbox exceptions, so you may want to * only catch this exception which signals that some kind of error * occurred. */ public static HttpResponse execute(Session session, HttpUriRequest req, int socketTimeoutOverrideMs) throws DropboxException { HttpClient client = updatedHttpClient(session); // Set request timeouts. session.setRequestTimeout(req); if (socketTimeoutOverrideMs >= 0) { HttpParams reqParams = req.getParams(); HttpConnectionParams.setSoTimeout(reqParams, socketTimeoutOverrideMs); } boolean repeatable = isRequestRepeatable(req); try { HttpResponse response = null; for (int retries = 0; retries < 5; retries++) { /* * The try/catch is a workaround for a bug in the HttpClient * libraries. It should be returning null instead when an * error occurs. Fixed in HttpClient 4.1, but we're stuck with * this for now. See: * http://code.google.com/p/android/issues/detail?id=5255 */ try { response = client.execute(req); } catch (NullPointerException e) { // Leave 'response' as null. This is handled below. } if (response != null) break; /* * We've potentially connected to a different network, but are * still using the old proxy settings. Refresh proxy settings * so that we can retry this request. */ updateClientProxy(client, session); if (!repeatable) { throw new DropboxProxyChangeException(); } } if (response == null) { // This is from that bug, and retrying hasn't fixed it. throw new DropboxIOException("Apache HTTPClient encountered an error. No response, try again."); } int statusCode = response.getStatusLine().getStatusCode(); if (statusCode != DropboxServerException._200_OK && statusCode != DropboxServerException._206_PARTIAL_CONTENT) { // This will throw the right thing: either a DropboxServerException or a DropboxProxyException parseAsJSON(response); } return response; } catch (SSLException e) { throw new DropboxSSLException(e); } catch (IOException e) { // Quite common for network going up & down or the request being // cancelled, so don't worry about logging this throw new DropboxIOException(e); } catch (OutOfMemoryError e) { throw new DropboxException(e); } }
From source file:org.apache.olingo.samples.client.core.http.ParametersHttpUriRequestFactory.java
@Override public HttpUriRequest create(final HttpMethod method, final URI uri) { final HttpUriRequest request = super.create(method, uri); request.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_0); request.getParams().setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, "UTF-8"); final int timeout = 1000; HttpConnectionParams.setConnectionTimeout(request.getParams(), timeout); HttpConnectionParams.setSoTimeout(request.getParams(), timeout); return request; }
From source file:com.snda.mymarket.providers.downloads.HttpClientStack.java
@Override public HttpResponse performRequest(HttpUriRequest httpRequest) throws IOException { HttpParams httpParams = httpRequest.getParams(); // TODO: Reevaluate this connection timeout based on more wide-scale // data collection and possibly different for wifi vs. 3G. HttpConnectionParams.setConnectionTimeout(httpParams, TIMEOUT_MSECONDES); HttpConnectionParams.setSoTimeout(httpParams, TIMEOUT_MSECONDES); return mClient.execute(httpRequest); }
From source file:bbd.basesimplenet.net.httpstacks.HttpClientStack.java
/** * ?,?../* w w w . j ava 2s. c o m*/ * * @param httpUriRequest */ private void setConnectionParams(HttpUriRequest httpUriRequest) { HttpParams httpParams = httpUriRequest.getParams(); HttpConnectionParams.setConnectionTimeout(httpParams, mConfig.connTimeOut); HttpConnectionParams.setSoTimeout(httpParams, mConfig.soTimeOut); }
From source file:cc.alessandro.jpocket.session.AbstractSession.java
/** * {@inheritDoc} <br/>//from w w w .ja v a 2 s.c o m * <br/> * The default implementation always sets a 30 second timeout. */ @Override public void setRequestTimeout(HttpUriRequest request) { HttpParams reqParams = request.getParams(); HttpConnectionParams.setSoTimeout(reqParams, DEFAULT_TIMEOUT_MILLIS); HttpConnectionParams.setConnectionTimeout(reqParams, DEFAULT_TIMEOUT_MILLIS); }
From source file:org.getwheat.harvest.library.RequestProcessor.java
private void addBasicAuthHeaders(final HttpUriRequest request, final UserCredentials credentials) { request.addHeader(KEY_AUTHORIZATION, VALUE_BASIC + credentials.getBase64Value()); HttpProtocolParams.setUserAgent(request.getParams(), VALUE_USER_AGENT); }
From source file:ai.eve.volley.stack.HttpClientStack.java
@Override public HttpResponse performRequest(Request<?> request) throws IOException, AuthFailureError { HttpUriRequest httpRequest = createHttpRequest(request); onPrepareRequest(httpRequest);/*from www. j av a 2 s . c o m*/ addHeaders(httpRequest, request.getHeaders()); HttpParams httpParams = httpRequest.getParams(); int timeoutMs = request.getTimeoutMs(); // TODO: Reevaluate this connection timeout based on more wide-scale // data collection and possibly different for wifi vs. 3G. HttpConnectionParams.setConnectionTimeout(httpParams, 5000); HttpConnectionParams.setSoTimeout(httpParams, timeoutMs); return mClient.execute(httpRequest); }