List of usage examples for org.apache.http.client HttpClient getParams
@Deprecated HttpParams getParams();
From source file:com.investoday.code.util.aliyun.api.gateway.util.HttpUtil.java
/** * HTTP PUT/*from w ww . j a va 2 s . c om*/ * * @param url http://host+path+query * @param headers Http * @param bytes * @param appKey APP KEY * @param appSecret APP * @param timeout * @param signHeaderPrefixList ???Header? * @return * @throws Exception */ public static HttpResponse httpPut(String url, Map<String, String> headers, byte[] bytes, String appKey, String appSecret, int timeout, List<String> signHeaderPrefixList) throws Exception { headers = initialBasicHeader(headers, appKey, appSecret, HttpMethod.PUT, url, null, signHeaderPrefixList); HttpClient httpClient = new DefaultHttpClient(); httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, getTimeout(timeout)); HttpPut put = new HttpPut(url); for (Map.Entry<String, String> e : headers.entrySet()) { put.addHeader(e.getKey(), e.getValue()); } if (bytes != null) { put.setEntity(new ByteArrayEntity(bytes)); } return httpClient.execute(put); }
From source file:org.carrot2.util.httpclient.HttpClientFactory.java
/** * Configure HTTP proxy from system properties, if available. *///from ww w.j a v a 2 s .c o m private static void configureProxy(HttpClient httpClient) { final String proxyHost = System.getProperty(PROPERTY_NAME_PROXY_HOST); final String proxyPort = System.getProperty(PROPERTY_NAME_PROXY_PORT); if (!StringUtils.isEmpty(proxyHost) && !StringUtils.isEmpty(proxyPort)) { try { final int port = Integer.parseInt(proxyPort); httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, new HttpHost(proxyHost, port)); } catch (NumberFormatException e) { // Ignore. } } }
From source file:com.investoday.code.util.aliyun.api.gateway.util.HttpUtil.java
/** * HTTP PUT?//from w w w . j a v a 2s . c o m * * @param url http://host+path+query * @param headers Http * @param formParam ?? * @param appKey APP KEY * @param appSecret APP * @param timeout * @param signHeaderPrefixList ???Header? * @return * @throws Exception */ public static HttpResponse httpPut(String url, Map<String, String> headers, Map<String, String> formParam, String appKey, String appSecret, int timeout, List<String> signHeaderPrefixList) throws Exception { headers = initialBasicHeader(headers, appKey, appSecret, HttpMethod.PUT, url, formParam, signHeaderPrefixList); HttpClient httpClient = new DefaultHttpClient(); httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, getTimeout(timeout)); HttpPut put = new HttpPut(url); for (Map.Entry<String, String> e : headers.entrySet()) { put.addHeader(e.getKey(), e.getValue()); } UrlEncodedFormEntity formEntity = buildFormEntity(formParam); if (formEntity != null) { put.setEntity(formEntity); } return httpClient.execute(put); }
From source file:com.investoday.code.util.aliyun.api.gateway.util.HttpUtil.java
/** * HTTP POST?/*from w w w . j a v a 2s . c om*/ * * @param url http://host+path+query * @param headers Http * @param formParam ?? * @param appKey APP KEY * @param appSecret APP * @param timeout * @param signHeaderPrefixList ???Header? * @return * @throws Exception */ public static HttpResponse httpPost(String url, Map<String, String> headers, Map<String, String> formParam, String appKey, String appSecret, int timeout, List<String> signHeaderPrefixList) throws Exception { if (headers == null) { headers = new HashMap<String, String>(); } headers.put(HttpHeader.HTTP_HEADER_CONTENT_TYPE, ContentType.CONTENT_TYPE_FORM); headers = initialBasicHeader(headers, appKey, appSecret, HttpMethod.POST, url, formParam, signHeaderPrefixList); HttpClient httpClient = new DefaultHttpClient(); httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, getTimeout(timeout)); HttpPost post = new HttpPost(url); for (Map.Entry<String, String> e : headers.entrySet()) { post.addHeader(e.getKey(), e.getValue()); } UrlEncodedFormEntity formEntity = buildFormEntity(formParam); if (formEntity != null) { post.setEntity(formEntity); } return httpClient.execute(post); }
From source file:com.mingsoft.weixin.http.HttpClientConnectionManager.java
/** * ?SSL?HttpClient//from w w w. jav a 2 s .c om * * @param httpClient * @return */ public static HttpClient getSSLInstance(HttpClient httpClient) { ClientConnectionManager ccm = httpClient.getConnectionManager(); SchemeRegistry sr = ccm.getSchemeRegistry(); sr.register(new Scheme("https", 443, WeixinSSLSocketFactory.getInstance())); httpClient = new DefaultHttpClient(ccm, httpClient.getParams()); return httpClient; }
From source file:com.google.code.jerseyclients.httpclientfour.ApacheHttpClientFour.java
/** * Create a default Apache HTTP client handler. * //from w ww .j ava 2 s .c o m * @return a default Apache HTTP client handler. */ private static ApacheHttpClientFourHandler createDefaultClientHander(JerseyHttpClientConfig config, ThreadSafeClientConnManager threadSafeClientConnManager) { if (threadSafeClientConnManager == null) { throw new IllegalArgumentException("threadSafeClientConnManager cannot be null"); } HttpParams httpParams = new BasicHttpParams(); HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1); HttpClient client = new DefaultHttpClient(threadSafeClientConnManager, httpParams); if (config.getProxyInformation() != null) { HttpHost proxy = new HttpHost(config.getProxyInformation().getProxyHost(), config.getProxyInformation().getProxyPort(), "http"); client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); } HttpConnectionParams.setConnectionTimeout(httpParams, config == null ? 60000 : config.getConnectionTimeOut()); // FIXME //HttpParams params = new BasicHttpParams(); //params.setParameter( ConnManagerPNames.TIMEOUT, config == null ? 50000 : config //.getConnectionPoolTimeOut() ); //client.setHttpConnectionFactoryTimeout( config == null ? 0 : config.getConnectionPoolTimeOut() ); return new ApacheHttpClientFourHandler(client, config); }
From source file:net.opentracker.android.OTSend.java
/** * Sends the key value pairs to Opentracker's logging/ analytics engines via * HTTP POST requests./* www.java 2 s . c o m*/ * * Based on sending key value pairs documentated at: * http://api.opentracker.net/api/inserts/insert_event.jsp * * @param keyValuePairs * the key value pairs (plain text utf-8 strings) to send to the * logging service. * * @return the response as string, null if an exception is caught */ protected static String send(HashMap<String, String> keyValuePairs) { LogWrapper.v(TAG, "send(HashMap<String, String> keyValuePairs)"); // http://www.wikihow.com/Execute-HTTP-POST-Requests-in-Android // http://hc.apache.org/httpclient-3.x/tutorial.html HttpClient client = new DefaultHttpClient(); // time to wait before throwing timeout exception client.getParams().setParameter("http.socket.timeout", new Integer(HTTP_SOCKET_TIMEOUT)); HttpPost post = new HttpPost(DEFAULT_LOG_URL); post.getParams().setParameter("http.socket.timeout", new Integer(HTTP_SOCKET_TIMEOUT)); Iterator<Entry<String, String>> it = keyValuePairs.entrySet().iterator(); List<NameValuePair> pairs = new ArrayList<NameValuePair>(); while (it.hasNext()) { Map.Entry<String, String> pair = (Map.Entry<String, String>) it.next(); pairs.add(new BasicNameValuePair(pair.getKey(), pair.getValue())); if (pair.getKey().equals("ots") || pair.getKey().equals("otui")) LogWrapper.v(TAG, pair.getKey() + " = " + pair.getValue()); else LogWrapper.v(TAG, pair.getKey() + " = " + pair.getValue()); } String responseText = null; try { post.setEntity(new UrlEncodedFormEntity(pairs)); HttpResponse response = client.execute(post); HttpEntity entity = response.getEntity(); // http://hc.apache.org/httpclient-3.x/tutorial.html // It is vital that the response body is always read regardless of // the status returned by the server. responseText = getResponseBody(entity); LogWrapper.v(TAG, "Success url:" + post.getURI()); LogWrapper.v(TAG, "Success url:" + pairs); return responseText; } catch (UnsupportedEncodingException e) { e.printStackTrace(); LogWrapper.w(TAG, "Failed:" + e); } catch (UnknownHostException e) { e.printStackTrace(); LogWrapper.w(TAG, "Failed:" + e); } catch (IOException e) { e.printStackTrace(); LogWrapper.w(TAG, "Failed:" + e); } catch (ParseException e) { e.printStackTrace(); LogWrapper.w(TAG, "Failed:" + e); } LogWrapper.e(TAG, "Got response " + responseText); return responseText; }
From source file:com.mpower.mintel.android.utilities.WebUtils.java
public static final HttpClient createHttpClient(int timeout) { // configure connection HttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, timeout); HttpConnectionParams.setSoTimeout(params, timeout); // support redirecting to handle http: => https: transition HttpClientParams.setRedirecting(params, true); // support authenticating HttpClientParams.setAuthenticating(params, true); // if possible, bias toward digest auth (may not be in 4.0 beta 2) List<String> authPref = new ArrayList<String>(); authPref.add(AuthPolicy.DIGEST);//from ww w. ja v a2 s . c o m authPref.add(AuthPolicy.BASIC); // does this work in Google's 4.0 beta 2 snapshot? params.setParameter("http.auth-target.scheme-pref", authPref); // setup client HttpClient httpclient = new DefaultHttpClient(params); httpclient.getParams().setParameter(ClientPNames.MAX_REDIRECTS, 1); httpclient.getParams().setParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true); return httpclient; }
From source file:com.mpower.daktar.android.utilities.WebUtils.java
public static final HttpClient createHttpClient(final int timeout) { // configure connection final HttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, timeout); HttpConnectionParams.setSoTimeout(params, timeout); // support redirecting to handle http: => https: transition HttpClientParams.setRedirecting(params, true); // support authenticating HttpClientParams.setAuthenticating(params, true); // if possible, bias toward digest auth (may not be in 4.0 beta 2) final List<String> authPref = new ArrayList<String>(); authPref.add(AuthPolicy.DIGEST);// w w w . ja v a 2 s .c o m authPref.add(AuthPolicy.BASIC); // does this work in Google's 4.0 beta 2 snapshot? params.setParameter("http.auth-target.scheme-pref", authPref); // setup client final HttpClient httpclient = new DefaultHttpClient(params); httpclient.getParams().setParameter(ClientPNames.MAX_REDIRECTS, 1); httpclient.getParams().setParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true); return httpclient; }
From source file:com.payu.sdk.helper.HttpClientHelper.java
/** * Sends the post request to the server// www. ja v a2 s .com * * @param request * The request to be sent to the server * @param requestMethod * The request method to be sent to the server * @param the socket time out. * @return The response in a xml format * @throws ConnectionException * @throws SDKException */ public static String sendRequest(Request request, RequestMethod requestMethod, Integer socketTimeOut) throws PayUException, ConnectionException { HttpClient httpClient = new DefaultHttpClient(); setHttpClientParameters(httpClient.getParams(), socketTimeOut); httpClient = WebClientDevWrapper.wrapClient(httpClient); try { HttpRequestBase httpRequest = createHttpRequest(request, requestMethod); HttpResponse httpResponse = httpClient.execute(httpRequest); if (httpResponse == null) { throw new ConnectionException("No response from server"); } Integer httpStatus = httpResponse.getStatusLine().getStatusCode(); Integer[] successStatus = { HttpStatus.SC_OK, HttpStatus.SC_CREATED, HttpStatus.SC_ACCEPTED }; if (Arrays.asList(successStatus).contains(httpStatus)) { return getXmlResponse(httpResponse); } else { return manageResponse(httpResponse); } } catch (PayUException e) { throw e; } catch (Exception e) { throw new ConnectionException(e.getMessage(), e); } finally { httpClient.getConnectionManager().shutdown(); } }