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:marytts.server.http.MaryHttpServer.java
public void run() { logger.info("Starting server."); int localPort = MaryProperties.needInteger("socket.port"); HttpParams params = new BasicHttpParams(); params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 0) // 0 means no timeout, any positive value means time out in miliseconds (i.e. 50000 for 50 seconds) .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024) .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false) .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true) .setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpComponents/1.1"); BasicHttpProcessor httpproc = new BasicHttpProcessor(); httpproc.addInterceptor(new ResponseDate()); httpproc.addInterceptor(new ResponseServer()); httpproc.addInterceptor(new ResponseContent()); httpproc.addInterceptor(new ResponseConnControl()); BufferingHttpServiceHandler handler = new BufferingHttpServiceHandler(httpproc, new DefaultHttpResponseFactory(), new DefaultConnectionReuseStrategy(), params); // Set up request handlers HttpRequestHandlerRegistry registry = new HttpRequestHandlerRegistry(); registry.register("/process", new SynthesisRequestHandler()); InfoRequestHandler infoRH = new InfoRequestHandler(); registry.register("/version", infoRH); registry.register("/datatypes", infoRH); registry.register("/locales", infoRH); registry.register("/voices", infoRH); registry.register("/audioformats", infoRH); registry.register("/exampletext", infoRH); registry.register("/audioeffects", infoRH); registry.register("/audioeffect-default-param", infoRH); registry.register("/audioeffect-full", infoRH); registry.register("/audioeffect-help", infoRH); registry.register("/audioeffect-is-hmm-effect", infoRH); registry.register("/features", infoRH); registry.register("/features-discrete", infoRH); registry.register("/vocalizations", infoRH); registry.register("/styles", infoRH); registry.register("*", new FileRequestHandler()); handler.setHandlerResolver(registry); // Provide an event logger handler.setEventListener(new EventLogger()); IOEventDispatch ioEventDispatch = new DefaultServerIOEventDispatch(handler, params); int numParallelThreads = MaryProperties.getInteger("server.http.parallelthreads", 5); logger.info("Waiting for client to connect on port " + localPort); try {/*w w w . java 2 s.co m*/ ListeningIOReactor ioReactor = new DefaultListeningIOReactor(numParallelThreads, params); ioReactor.listen(new InetSocketAddress(localPort)); isReady = true; ioReactor.execute(ioEventDispatch); } catch (InterruptedIOException ex) { logger.info("Interrupted", ex); } catch (IOException e) { logger.info("Problem with HTTP connection", e); } logger.debug("Shutdown"); }
From source file:org.openrepose.core.services.httpclient.impl.HttpConnectionPoolServiceImpl.java
@Override public int getSocketTimeout(String clientId) { if (poolMap.containsKey(clientId)) { return poolMap.get(clientId).getParams().getIntParameter(CoreConnectionPNames.SO_TIMEOUT, 0); } else if (poolMap.containsKey(defaultClientId)) { return poolMap.get(defaultClientId).getParams().getIntParameter(CoreConnectionPNames.SO_TIMEOUT, 0); } else {//from ww w . j av a 2 s . c om return DEFAULT_POOL.getHttpSocketTimeout(); } }
From source file:org.apache.oozie.action.callback.CallbackActionExecutor.java
private HttpClient getHttpClient() { CallbackActionService callbackActionService = Services.get().get(CallbackActionService.class); HttpClient client = new DefaultHttpClient(callbackActionService.getConnectionManager()); client.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, ConfigurationService.getInt(CallbackActionExecutor.CALLBACK_ACTION_HTTP_CONNECTION_TIMEOUT_SECS) * 1000);// w w w . j a v a 2s . c om client.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, ConfigurationService.getInt(CallbackActionExecutor.CALLBACK_ACTION_HTTP_SOCKET_TIMEOUT_SECS) * 1000); client.getParams().setParameter(CoreConnectionPNames.SO_KEEPALIVE, ConfigurationService.getInt(CallbackActionExecutor.CALLBACK_ACTION_KEEPALIVE_SECS) * 1000); return client; }
From source file:org.apache.solr.cloud.FullSolrCloudTest.java
protected void initCloud() throws Exception { if (zkStateReader == null) { synchronized (this) { if (zkStateReader != null) { return; }//from w ww . ja va 2 s .c o m zkStateReader = new ZkStateReader(zkServer.getZkAddress(), 10000, AbstractZkTestCase.TIMEOUT); zkStateReader.createClusterStateWatchersAndUpdate(); } chaosMonkey = new ChaosMonkey(zkServer, zkStateReader, DEFAULT_COLLECTION, shardToJetty, shardToClient, shardToLeaderClient, shardToLeaderJetty, random()); } // wait until shards have started registering... while (!zkStateReader.getCloudState().getCollections().contains(DEFAULT_COLLECTION)) { Thread.sleep(500); } while (zkStateReader.getCloudState().getSlices(DEFAULT_COLLECTION).size() != sliceCount) { Thread.sleep(500); } // use the distributed solrj client if (cloudClient == null) { synchronized (this) { if (cloudClient != null) { return; } try { CloudSolrServer server = new CloudSolrServer(zkServer.getZkAddress()); server.setDefaultCollection(DEFAULT_COLLECTION); server.getLbServer().getHttpClient().getParams() .setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 5000); server.getLbServer().getHttpClient().getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, 15000); cloudClient = server; } catch (MalformedURLException e) { throw new RuntimeException(e); } } } }
From source file:test.Http.java
/** * post url :??jsonString???json,?json//from ww w. j a va 2s.c o m * * @date * @param url * @param jsonString * @return * @throws Exception */ public static String httpPostWithJsons(String url, String jsonString) throws Exception { System.out.println("==url++" + url + "==jsonString" + jsonString); String responseBodyData = null; HttpClient httpClient = new DefaultHttpClient(); // httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 6000); // ? httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, 6000); HttpPost httpPost = new HttpPost(url); httpPost.addHeader("Content-Type", "text/html"); // byte[] requestStrings = jsonString.toString().getBytes("UTF-8"); ByteArrayEntity byteArrayEntity = new ByteArrayEntity(requestStrings); httpPost.setEntity(byteArrayEntity); try { HttpResponse response = httpClient.execute(httpPost);// post if (response.getStatusLine().getStatusCode() == 200) { responseBodyData = EntityUtils.toString(response.getEntity()); } else { responseBodyData = null; } } catch (Exception e) { } finally { httpPost.abort(); httpClient = null; } return responseBodyData; }
From source file:org.graphity.core.util.jena.HttpQuery.java
private InputStream execGet() throws QueryExceptionHTTP { URL target = null;//from w w w . jav a 2 s. c o m String qs = getQueryString(); ARQ.getHttpRequestLogger().trace(qs); try { if (count() == 0) target = new URL(serviceURL); else target = new URL(serviceURL + (serviceParams ? "&" : "?") + qs); } catch (MalformedURLException malEx) { throw new QueryExceptionHTTP(0, "Malformed URL: " + malEx); } log.trace("GET " + target.toExternalForm()); try { try { this.client = new SystemDefaultHttpClient(); // Always apply a 10 second timeout to obtaining a connection lease from HTTP Client // This prevents a potential lock up this.client.getParams().setLongParameter(ConnManagerPNames.TIMEOUT, TimeUnit.SECONDS.toMillis(10)); // If user has specified time outs apply them now if (this.connectTimeout > 0) this.client.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, this.connectTimeout); if (this.readTimeout > 0) this.client.getParams().setIntParameter(CoreConnectionPNames.SO_TIMEOUT, this.readTimeout); // Enable compression support appropriately HttpContext context = new BasicHttpContext(); if (allowGZip || allowDeflate) { // Apply auth early as the decompressing client we're about // to add will block this being applied later HttpOp.applyAuthentication((AbstractHttpClient) client, serviceURL, context, authenticator); client = new DecompressingHttpClient(client); } // Get the actual response stream TypedInputStream stream = HttpOp.execHttpGet(target.toString(), contentTypeResult, client, context, this.authenticator); if (stream == null) throw new QueryExceptionHTTP(404); return execCommon(stream); } catch (HttpException httpEx) { // Back-off and try POST if something complain about long URIs if (httpEx.getResponseCode() == 414) return execPost(); throw httpEx; } } catch (HttpException httpEx) { // Unwrap and re-wrap the HTTP exception responseCode = httpEx.getResponseCode(); throw new QueryExceptionHTTP(responseCode, "Error making the query, see cause for details", httpEx.getCause()); } }
From source file:org.bedework.util.http.BasicHttpClient.java
/** * @param host default host or null//from ww w.j ava2 s . co m * @param port default port if host supplied or -1 for default * @param scheme default scheme if host supplied or null for default * @param timeOut - millisecs, 0 for no timeout * @param followRedirects true for auto handling * @throws HttpException */ public BasicHttpClient(final String host, final int port, final String scheme, final int timeOut, final boolean followRedirects) throws HttpException { super(connManager, null); setKeepAliveStrategy(kas); if (sslDisabled) { warn("*******************************************************"); warn(" SSL disabled"); warn("*******************************************************"); } final HttpParams params = getParams(); if (host != null) { hostSpecified = true; final HttpHost httpHost = new HttpHost(host, port, scheme); params.setParameter(ClientPNames.DEFAULT_HOST, httpHost); } params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, timeOut); // XXX Should have separate value for this. params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, timeOut * 2); params.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, followRedirects); }
From source file:org.apache.commons.vfs2.util.NHttpServer.java
public void runBlock(final int port, final File docRoot) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException, UnrecoverableKeyException, KeyManagementException { if (docRoot == null) { throw new IllegalArgumentException("No doc root specified."); }//w w w . ja v a 2 s. c om // HTTP parameters for the server final HttpParams params = new SyncBasicHttpParams(); params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000) .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024) .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true) .setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpTest/1.1"); // Create HTTP protocol processing chain final HttpProcessor httpproc = new ImmutableHttpProcessor(new HttpResponseInterceptor[] { // Use standard server-side protocol interceptors new ResponseDate(), new ResponseServer(), new ResponseContent(), new ResponseConnControl() }); // Create request handler registry final HttpAsyncRequestHandlerRegistry reqistry = new HttpAsyncRequestHandlerRegistry(); // Register the default handler for all URIs reqistry.register("*", new HttpFileHandler(docRoot)); // Create server-side HTTP protocol handler final HttpAsyncService protocolHandler = new HttpAsyncService(httpproc, new DefaultConnectionReuseStrategy(), reqistry, params) { @Override public void closed(final NHttpServerConnection conn) { NHttpServer.debug(conn + ": connection closed"); super.closed(conn); } @Override public void connected(final NHttpServerConnection conn) { NHttpServer.debug(conn + ": connection open"); super.connected(conn); } }; // Create HTTP connection factory NHttpConnectionFactory<DefaultNHttpServerConnection> connFactory; if (port == 8443) { // Initialize SSL context final ClassLoader cl = NHttpServer.class.getClassLoader(); final URL url = cl.getResource("my.keystore"); if (url == null) { NHttpServer.debug("Keystore not found"); System.exit(1); } final KeyStore keystore = KeyStore.getInstance("jks"); keystore.load(url.openStream(), "secret".toCharArray()); final KeyManagerFactory kmfactory = KeyManagerFactory .getInstance(KeyManagerFactory.getDefaultAlgorithm()); kmfactory.init(keystore, "secret".toCharArray()); final KeyManager[] keymanagers = kmfactory.getKeyManagers(); final SSLContext sslcontext = SSLContext.getInstance("TLS"); sslcontext.init(keymanagers, null, null); connFactory = new SSLNHttpServerConnectionFactory(sslcontext, null, params); } else { connFactory = new DefaultNHttpServerConnectionFactory(params); } // Create server-side I/O event dispatch final IOEventDispatch ioEventDispatch = new DefaultHttpServerIODispatch(protocolHandler, connFactory); // Create server-side I/O reactor this.ioReactor = new DefaultListeningIOReactor(); try { // Listen of the given port this.ioReactor.listen(new InetSocketAddress(port)); // Ready to go! this.ioReactor.execute(ioEventDispatch); } catch (final InterruptedIOException ex) { System.err.println("Interrupted"); } catch (final IOException e) { System.err.println("I/O error: " + e.getMessage()); } NHttpServer.debug("Shutdown"); }
From source file:org.alfresco.provision.ActiveMQService.java
private CloseableHttpClient buildClient() { CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(activeMQHost, activeMQPort), new UsernamePasswordCredentials(username, password)); PoolingHttpClientConnectionManager poolingConnManager = new PoolingHttpClientConnectionManager(); poolingConnManager.setMaxTotal(200); CloseableHttpClient client = HttpClients.custom().setConnectionManager(poolingConnManager) .setDefaultCredentialsProvider(credsProvider).build(); client.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 5); client.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, 5); return client; }