List of usage examples for org.apache.http.params CoreConnectionPNames CONNECTION_TIMEOUT
String CONNECTION_TIMEOUT
To view the source code for org.apache.http.params CoreConnectionPNames CONNECTION_TIMEOUT.
Click Source Link
From source file:anhttpclient.impl.DefaultWebBrowser.java
/** * {@inheritDoc}/*from w w w . j a v a 2 s .co m*/ */ public void setConnectionTimeout(Integer connectionTimeout) { initHttpClient(); this.connectionTimeout = connectionTimeout; httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, connectionTimeout); }
From source file:com.drive.student.xutils.HttpUtils.java
/** * * HttpClient??post?./*from www. j a v a 2s. c o m*/ */ public HttpResponse sendHttpPost(String url, Map<String, String> params, boolean isGzip) { try { List<NameValuePair> param = new ArrayList<NameValuePair>(); // ? if (params != null) { for (Entry<String, String> entry : params.entrySet()) { param.add(new BasicNameValuePair(entry.getKey(), entry.getValue())); } } HttpPost request = new HttpPost(url); buildHttpHeaderForPost(request);// if (isGzip) { request.addHeader("accept-encoding", "gzip"); } HttpEntity entity = new UrlEncodedFormEntity(param, "UTF-8"); request.setEntity(entity); HttpClient client = new DefaultHttpClient(); client.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, HttpUtils.DEFAULT_CONN_TIMEOUT); // client.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, HttpUtils.DEFAULT_SO_TIMEOUT); // ? HttpResponse response = client.execute(request, httpContext); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { LogUtil.e("hxk", "upload file success -->>"); return response; } else { LogUtil.e("hxk", "upload fail -->>" + response.getStatusLine().getStatusCode()); } } catch (Exception e) { e.printStackTrace(); } LogUtil.e("hxk", "upload fail -->>"); return null; }
From source file:org.dasein.cloud.zimory.ZimoryMethod.java
private @Nonnull HttpClient getClient(URI uri) throws InternalException, CloudException { ProviderContext ctx = provider.getContext(); if (ctx == null) { throw new NoContextException(); }//from w w w . j a va2 s. co m boolean ssl = uri.getScheme().startsWith("https"); int targetPort = uri.getPort(); if (targetPort < 1) { targetPort = (ssl ? 443 : 80); } HttpParams params = new BasicHttpParams(); SchemeRegistry registry = new SchemeRegistry(); try { registry.register( new Scheme(ssl ? "https" : "http", targetPort, new X509SSLSocketFactory(new X509Store(ctx)))); } catch (KeyManagementException e) { e.printStackTrace(); throw new InternalException(e); } catch (UnrecoverableKeyException e) { e.printStackTrace(); throw new InternalException(e); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); throw new InternalException(e); } catch (KeyStoreException e) { e.printStackTrace(); throw new InternalException(e); } HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); //noinspection deprecation HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); HttpProtocolParams.setUserAgent(params, ""); params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000); params.setParameter(CoreConnectionPNames.SO_TIMEOUT, 300000); Properties p = ctx.getCustomProperties(); if (p != null) { String proxyHost = p.getProperty("proxyHost"); String proxyPort = p.getProperty("proxyPort"); if (proxyHost != null) { int port = 0; if (proxyPort != null && proxyPort.length() > 0) { port = Integer.parseInt(proxyPort); } params.setParameter(ConnRoutePNames.DEFAULT_PROXY, new HttpHost(proxyHost, port, ssl ? "https" : "http")); } } ClientConnectionManager ccm = new ThreadSafeClientConnManager(registry); return new DefaultHttpClient(ccm, params); }
From source file:net.java.sip.communicator.service.httputil.HttpUtils.java
/** * Returns the preconfigured http client, * using CertificateVerificationService, timeouts, user-agent, * hostname verifier, proxy settings are used from global java settings, * if protected site is hit asks for credentials * using util.swing.AuthenticationWindow. * @param usernamePropertyName the property to use to retrieve/store * username value if protected site is hit, for username * ConfigurationService service is used. * @param passwordPropertyName the property to use to retrieve/store * password value if protected site is hit, for password * CredentialsStorageService service is used. * @param credentialsProvider if not null provider will bre reused * in the new client// w w w . j av a 2s. com * @param address the address we will be connecting to */ public static DefaultHttpClient getHttpClient(String usernamePropertyName, String passwordPropertyName, final String address, CredentialsProvider credentialsProvider) throws IOException { HttpParams params = new BasicHttpParams(); params.setParameter(CoreConnectionPNames.SO_TIMEOUT, 10000); params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000); params.setParameter(ClientPNames.MAX_REDIRECTS, MAX_REDIRECTS); DefaultHttpClient httpClient = new DefaultHttpClient(params); HttpProtocolParams.setUserAgent(httpClient.getParams(), System.getProperty("sip-communicator.application.name") + "/" + System.getProperty("sip-communicator.version")); SSLContext sslCtx; try { sslCtx = HttpUtilActivator.getCertificateVerificationService() .getSSLContext(HttpUtilActivator.getCertificateVerificationService().getTrustManager(address)); } catch (GeneralSecurityException e) { throw new IOException(e.getMessage()); } // note to any reviewer concerned about ALLOW_ALL_HOSTNAME_VERIFIER: // the SSL context obtained from the certificate service takes care of // certificate validation try { Scheme sch = new Scheme("https", 443, new SSLSocketFactoryEx(sslCtx)); httpClient.getConnectionManager().getSchemeRegistry().register(sch); } catch (Throwable t) { logger.error("Error creating ssl socket factory", t); } // set proxy from default jre settings ProxySelectorRoutePlanner routePlanner = new ProxySelectorRoutePlanner( httpClient.getConnectionManager().getSchemeRegistry(), ProxySelector.getDefault()); httpClient.setRoutePlanner(routePlanner); if (credentialsProvider == null) credentialsProvider = new HTTPCredentialsProvider(usernamePropertyName, passwordPropertyName); httpClient.setCredentialsProvider(credentialsProvider); // enable retry connecting with default retry handler // when connecting has prompted for authentication // connection can be disconnected nefore user answers and // we need to retry connection, using the credentials provided httpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(3, true)); return httpClient; }
From source file:com.ucai.test.control.DeviceControlActivity.java
private int sendDataByPost(MedicalData data) { if (null == data) { return 0; }//from www . j av a 2s . co m boolean DEBUG_SWL = true; if (DEBUG_SWL) { Log.i(TAG, "run--------sendDataByPost----------");//post??? } JSONObject obj = transToJson(data);//??json? HttpResponse httpResponse = null; HttpPost httpPost = new HttpPost(Constant.URL_USER_DATA); HttpClient client = new DefaultHttpClient(); client.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 3000); // client.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, 3000); //? try { httpPost.setEntity(new StringEntity(obj.toString())); httpResponse = new DefaultHttpClient().execute(httpPost); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } if (null == httpResponse) { // Toast.makeText(this, "", Toast.LENGTH_SHORT).show(); return -1; // } if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { if (DEBUG_SWL) { Log.i(TAG, "httpResponse.getStatusLine().getStatusCode() == 200"); } try { String result = EntityUtils.toString(httpResponse.getEntity()); if (DEBUG_SWL) { Log.i(TAG, "result---------------" + result); } } catch (ParseException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return 1; //post? } else { return 2; //post } }
From source file:org.apache.axis2.transport.http.impl.httpclient4.HTTPSenderImpl.java
/** * This is used to get the dynamically set time out values from the message * context. If the values are not available or invalid then the default * values or the values set by the configuration will be used * * @param msgContext the active MessageContext * @param httpClient/*from ww w . ja v a 2s .c o m*/ */ protected void initializeTimeouts(MessageContext msgContext, AbstractHttpClient httpClient) { // If the SO_TIMEOUT of CONNECTION_TIMEOUT is set by dynamically the // override the static config Integer tempSoTimeoutProperty = (Integer) msgContext.getProperty(HTTPConstants.SO_TIMEOUT); Integer tempConnTimeoutProperty = (Integer) msgContext.getProperty(HTTPConstants.CONNECTION_TIMEOUT); long timeout = msgContext.getOptions().getTimeOutInMilliSeconds(); if (tempConnTimeoutProperty != null) { int connectionTimeout = tempConnTimeoutProperty.intValue(); // timeout for initial connection httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, connectionTimeout); } else { // set timeout in client if (timeout > 0) { httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, (int) timeout); } } if (tempSoTimeoutProperty != null) { int soTimeout = tempSoTimeoutProperty.intValue(); // SO_TIMEOUT -- timeout for blocking reads httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, soTimeout); } else { // set timeout in client if (timeout > 0) { httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, (int) timeout); } } }
From source file:org.apache.axis2.transport.http.impl.httpclient4.HTTPSenderImpl.java
/** * This is used to get the dynamically set time out values from the message * context. If the values are not available or invalid then the default * values or the values set by the configuration will be used * * @param msgContext the active MessageContext * @param httpMethod method/*from w ww.j a va2s . c o m*/ */ protected void setTimeouts(MessageContext msgContext, HttpRequestBase httpMethod) { // If the SO_TIMEOUT of CONNECTION_TIMEOUT is set by dynamically the // override the static config Integer tempSoTimeoutProperty = (Integer) msgContext.getProperty(HTTPConstants.SO_TIMEOUT); Integer tempConnTimeoutProperty = (Integer) msgContext.getProperty(HTTPConstants.CONNECTION_TIMEOUT); long timeout = msgContext.getOptions().getTimeOutInMilliSeconds(); if (tempConnTimeoutProperty != null) { // timeout for initial connection httpMethod.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, tempConnTimeoutProperty); } if (tempSoTimeoutProperty != null) { // SO_TIMEOUT -- timeout for blocking reads httpMethod.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, tempSoTimeoutProperty); } else { // set timeout in client if (timeout > 0) { httpMethod.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, (int) timeout); } } }