List of usage examples for org.apache.http.params CoreConnectionPNames SO_TIMEOUT
String SO_TIMEOUT
To view the source code for org.apache.http.params CoreConnectionPNames SO_TIMEOUT.
Click Source Link
From source file:org.obiba.opal.rest.client.magma.OpalJavaClient.java
private void createClient() { log.info("Connecting to Opal: {}", opalURI); DefaultHttpClient httpClient = new DefaultHttpClient(); if (keyStore == null) httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, credentials); httpClient.getParams().setParameter(ClientPNames.HANDLE_AUTHENTICATION, Boolean.TRUE); httpClient.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF, Collections.singletonList(OpalAuth.CREDENTIALS_HEADER)); httpClient.getParams().setParameter(ClientPNames.CONNECTION_MANAGER_FACTORY_CLASS_NAME, OpalClientConnectionManagerFactory.class.getName()); httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, connectionTimeout); httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, soTimeout); httpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(DEFAULT_MAX_ATTEMPT, false)); httpClient.getAuthSchemes().register(OpalAuth.CREDENTIALS_HEADER, new OpalAuthScheme.Factory()); try {/*from w ww.j a v a2 s . c om*/ httpClient.getConnectionManager().getSchemeRegistry() .register(new Scheme("https", HTTPS_PORT, getSocketFactory())); } catch (NoSuchAlgorithmException | KeyManagementException e) { throw new RuntimeException(e); } client = enableCaching(httpClient); ctx = new BasicHttpContext(); ctx.setAttribute(ClientContext.COOKIE_STORE, new BasicCookieStore()); }
From source file:org.apache.camel.itest.http.HttpTestServer.java
/** * Obtains a set of reasonable default parameters for a server. * * @return default parameters/*from w w w . ja v a 2 s . c om*/ */ protected HttpParams newDefaultParams() { HttpParams params = new SyncBasicHttpParams(); params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 60000) .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024) .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false) .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true) .setParameter(CoreProtocolPNames.ORIGIN_SERVER, "LocalTestServer/1.1"); return params; }
From source file:edu.isi.misd.tagfiler.client.JakartaClient.java
/** * Initialize the HTTP client//from ww w .j a v a2 s. co m * * @param connections * the maximum number of HTTP connections * @param socketBufferSize * the socket buffer size * @param socketTimeout * the socket buffer timeout */ private void init(int maxConnections, int socketBufferSize, int socketTimeout) throws Throwable { TrustManager easyTrustManager = new X509TrustManager() { public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { // Oh, I am easy! } public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { if (chain != null) { for (int i = 0; i < chain.length; i++) { chain[i].checkValidity(); } } } public X509Certificate[] getAcceptedIssuers() { return null; } }; SSLContext sslcontext = SSLContext.getInstance("SSL"); sslcontext.init(null, new TrustManager[] { easyTrustManager }, null); SSLSocketFactory sf = new SSLSocketFactory(sslcontext); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); BasicHttpParams params = new BasicHttpParams(); params.setParameter("http.protocol.handle-redirects", false); params.setParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, socketBufferSize); params.setParameter(CoreConnectionPNames.SO_TIMEOUT, socketTimeout); // enable parallelism ConnPerRouteBean connPerRoute = new ConnPerRouteBean(maxConnections); ConnManagerParams.setMaxTotalConnections(params, maxConnections >= 2 ? maxConnections : 2); ConnManagerParams.setMaxConnectionsPerRoute(params, connPerRoute); SchemeRegistry schemeRegistry = new SchemeRegistry(); Scheme sch = new Scheme("https", sf, 443); schemeRegistry.register(sch); //schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry); httpclient = new DefaultHttpClient(cm, params); BasicCookieStore cookieStore = new BasicCookieStore(); httpclient.setCookieStore(cookieStore); }
From source file:test.Http.java
/** * post url :??jsonString???json,?json//from www .ja va 2 s . com * * @date * @param url * @param jsonString * @return * @throws Exception */ public static String httpPostWithJson(String url, String jsonString) { String result = ""; DefaultHttpClient httpClient = new DefaultHttpClient(); // httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 6000); // ? httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, 6000); HttpPost httpPost = new HttpPost(url); // ??? try { StringEntity reqEntity = new StringEntity(jsonString, HTTP.UTF_8); httpPost.setHeader("Content-type", "text/xml; charset=utf-8"); // ? httpPost.setEntity(reqEntity); HttpResponse response = httpClient.execute(httpPost);// post HttpEntity entity = response.getEntity(); // BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent(), "UTF-8")); String line = null; result = ""; while ((line = reader.readLine()) != null) { result += line; } } catch (Exception e) { e.printStackTrace(); } return result; }
From source file:org.apache.synapse.transport.nhttp.HttpCoreNIOListener.java
/** * Initialize the transport listener, and execute reactor in new separate thread * @param "cfgCtx" the Axis2 configuration context * @param transportIn the description of the http/s transport from Axis2 configuration * @throws AxisFault on error/*from w w w.j a v a 2 s. com*/ */ public void init(ConfigurationContext ctx, TransportInDescription transportIn) throws AxisFault { cfgCtx = ctx; Map<String, String> o = (Map<String, String>) cfgCtx.getProperty(NhttpConstants.EPR_TO_SERVICE_NAME_MAP); if (o != null) { this.eprToServiceNameMap = o; } else { eprToServiceNameMap = new HashMap<String, String>(); cfgCtx.setProperty(NhttpConstants.EPR_TO_SERVICE_NAME_MAP, eprToServiceNameMap); } NHttpConfiguration cfg = NHttpConfiguration.getInstance(); // Initialize connection factory params = new BasicHttpParams(); params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, cfg.getProperty(NhttpConstants.SO_TIMEOUT_RECEIVER, 60000)) .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, cfg.getProperty(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)) .setParameter(CoreProtocolPNames.ORIGIN_SERVER, "Synapse-HttpComponents-NIO"); // .setParameter(CoreProtocolPNames.HTTP_ELEMENT_CHARSET, // cfg.getStringValue(CoreProtocolPNames.HTTP_ELEMENT_CHARSET, HTTP.DEFAULT_PROTOCOL_CHARSET)); //TODO:This does not works with HTTPCore 4.3 name = transportIn.getName().toUpperCase(Locale.US) + " Listener"; scheme = initScheme(); // Setup listener context listenerContext = new ListenerContextBuilder(transportIn).parse().build(); System.setProperty(transportIn.getName() + ".nio.port", String.valueOf(listenerContext.getPort())); // Setup connection factory HttpHost host = new HttpHost(listenerContext.getHostname(), listenerContext.getPort(), scheme.getName()); connFactory = initConnFactoryBuilder(transportIn, host).build(params); // configure the IO reactor on the specified port try { String prefix = name + " I/O dispatcher"; IOReactorConfig ioReactorConfig = new IOReactorConfig(); ioReactorConfig.setIoThreadCount(cfg.getServerIOWorkers()); ioReactorConfig.setSoTimeout(cfg.getProperty(NhttpConstants.SO_TIMEOUT_RECEIVER, 60000)); ioReactorConfig.setTcpNoDelay(cfg.getProperty(CoreConnectionPNames.TCP_NODELAY, 1) == 1); if (cfg.getBooleanValue("http.nio.interest-ops-queueing", false)) { ioReactorConfig.setInterestOpQueued(true); } ioReactorConfig.setSoReuseAddress(cfg.getBooleanValue(CoreConnectionPNames.SO_REUSEADDR, false)); ioReactor = new DefaultListeningIOReactor(ioReactorConfig, new NativeThreadFactory(new ThreadGroup(prefix + " thread group"), prefix)); ioReactor.setExceptionHandler(new IOReactorExceptionHandler() { public boolean handle(IOException ioException) { log.warn("System may be unstable: IOReactor encountered a checked exception : " + ioException.getMessage(), ioException); return true; } public boolean handle(RuntimeException runtimeException) { log.warn("System may be unstable: IOReactor encountered a runtime exception : " + runtimeException.getMessage(), runtimeException); return true; } }); } catch (IOException e) { handleException("Error creating IOReactor", e); } metrics = new NhttpMetricsCollector(true, transportIn.getName()); handler = new ServerHandler(cfgCtx, scheme, listenerContext, metrics); iodispatch = new ServerIODispatch(handler, connFactory); Parameter param = transportIn.getParameter(NhttpConstants.WSDL_EPR_PREFIX); if (param != null) { serviceEPRPrefix = getServiceEPRPrefix(cfgCtx, (String) param.getValue()); customEPRPrefix = (String) param.getValue(); EPRPrefixCheck = false; } else { serviceEPRPrefix = getServiceEPRPrefix(cfgCtx, listenerContext.getHostname(), listenerContext.getPort()); customEPRPrefix = scheme.getName() + "://" + listenerContext.getHostname() + ":" + (listenerContext.getPort() == scheme.getDefaultPort() ? "" : listenerContext.getPort()) + "/"; } // register to receive updates on services for lifetime management cfgCtx.getAxisConfiguration().addObservers(axisObserver); // register with JMX mbeanSupport = new TransportMBeanSupport(this, "nio-" + transportIn.getName()); mbeanSupport.register(); }
From source file:org.apache.http.localserver.LocalTestServer.java
/** * Obtains a set of reasonable default parameters for a server. * * @return default parameters//from w ww.ja va 2s .c o m */ protected HttpParams newDefaultParams() { HttpParams params = new BasicHttpParams(); params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 60000) .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024) .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false) .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true) .setParameter(CoreProtocolPNames.ORIGIN_SERVER, "org.apache.http.localserver.LocalTestServer/1.1"); return params; }
From source file:com.redblackit.web.client.X509HttpClientFactoryBean.java
/** * Ensure we have keystores and passwords defined. * /*from www . j a v a2 s . c o m*/ * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet() */ @Override public void afterPropertiesSet() throws Exception { if (getKeyStore() == null || getKeyStore().length() == 0 || getKeyStoreType() == null || getKeyStoreType().length() == 0 || getKeyStorePassword() == null || getKeyStorePassword().length() == 0 || getTrustStore() == null || getTrustStore().length() == 0 || getTrustStoreType() == null || getTrustStoreType().length() == 0 || getTrustStorePassword() == null || getTrustStorePassword().length() == 0) { throw new IllegalArgumentException("Missing key/trust store info:" + this); } if (logger.isDebugEnabled()) { logger.debug("afterPropertiesSet:E:this=" + this); } try { final KeyStore keystore = KeyStore.getInstance(getKeyStoreType()); InputStream keystoreInput = new FileInputStream(ResourceUtils.getFile(getKeyStore())); keystore.load(keystoreInput, getKeyStorePassword().toCharArray()); KeyStore truststore = KeyStore.getInstance(getTrustStoreType()); InputStream truststoreInput = new FileInputStream(ResourceUtils.getFile(getTrustStore())); truststore.load(truststoreInput, getTrustStorePassword().toCharArray()); final SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("https", getHttpsPort(), new SSLSocketFactory(keystore, getKeyStorePassword(), truststore))); if (httpParams == null) { httpParams = new BasicHttpParams(); httpParams.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, DEFAULT_READ_TIMEOUT_MILLISECONDS); } httpClient = new DefaultHttpClient(new ThreadSafeClientConnManager(schemeRegistry), httpParams); if (logger.isDebugEnabled()) { logger.debug("afterPropertiesSet:R:this=" + this); } } catch (Throwable t) { throw new RuntimeException(this.toString(), t); } }