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:com.groupon.odo.bmp.http.BrowserMobHttpClient.java
public void setConnectionTimeout(int connectionTimeout) { httpClient.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, connectionTimeout); }
From source file:org.apache.maven.plugin.javadoc.JavadocUtil.java
/** * Creates a new {@code HttpClient} instance. * * @param settings The settings to use for setting up the client or {@code null}. * @param url The {@code URL} to use for setting up the client or {@code null}. * * @return A new {@code HttpClient} instance. * * @see #DEFAULT_TIMEOUT//from w ww. j ava 2s .co m * @since 2.8 */ private static HttpClient createHttpClient(Settings settings, URL url) { DefaultHttpClient httpClient = new DefaultHttpClient(new PoolingClientConnectionManager()); httpClient.getParams().setIntParameter(CoreConnectionPNames.SO_TIMEOUT, DEFAULT_TIMEOUT); httpClient.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, DEFAULT_TIMEOUT); httpClient.getParams().setBooleanParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true); // Some web servers don't allow the default user-agent sent by httpClient httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"); if (settings != null && settings.getActiveProxy() != null) { Proxy activeProxy = settings.getActiveProxy(); ProxyInfo proxyInfo = new ProxyInfo(); proxyInfo.setNonProxyHosts(activeProxy.getNonProxyHosts()); if (StringUtils.isNotEmpty(activeProxy.getHost()) && (url == null || !ProxyUtils.validateNonProxyHosts(proxyInfo, url.getHost()))) { HttpHost proxy = new HttpHost(activeProxy.getHost(), activeProxy.getPort()); httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); if (StringUtils.isNotEmpty(activeProxy.getUsername()) && activeProxy.getPassword() != null) { Credentials credentials = new UsernamePasswordCredentials(activeProxy.getUsername(), activeProxy.getPassword()); httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, credentials); } } } return httpClient; }
From source file:com.nextgis.maplibui.services.HTTPLoader.java
protected String signIn() throws IOException { //1. fix url/*from ww w . ja v a 2s . c o m*/ String url; if (mUrl.startsWith("http")) url = mUrl + "/login"; else url = "http://" + mUrl + "/login"; HttpPost httppost = new HttpPost(url); List<NameValuePair> nameValuePairs = new ArrayList<>(2); nameValuePairs.add(new BasicNameValuePair("login", mLogin)); nameValuePairs.add(new BasicNameValuePair("password", mPassword)); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpClient httpclient = new DefaultHttpClient(); httpclient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, APP_USER_AGENT); httpclient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, TIMEOUT_CONNECTION); httpclient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, TIMEOUT_SOKET); httpclient.getParams().setParameter(ClientPNames.HANDLE_REDIRECTS, Boolean.FALSE); HttpResponse response = httpclient.execute(httppost); //2 get cookie Header head = response.getFirstHeader("Set-Cookie"); if (head == null) return null; return head.getValue(); }
From source file:org.apache.solr.cloud.AbstractFullDistribZkTestBase.java
protected CloudSolrServer createCloudClient(String defaultCollection) throws MalformedURLException { CloudSolrServer server = new CloudSolrServer(zkServer.getZkAddress(), random().nextBoolean()); server.setParallelUpdates(random().nextBoolean()); if (defaultCollection != null) server.setDefaultCollection(defaultCollection); server.getLbServer().getHttpClient().getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 5000);/*from w w w.j a v a2 s . c om*/ server.getLbServer().getHttpClient().getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, 30000); return server; }
From source file:org.apache.synapse.transport.nhttp.HttpCoreNIOSender.java
/** * Initialize the transport sender, and execute reactor in new separate thread * @param cfgCtx the Axis2 configuration context * @param transportOut the description of the http/s transport from Axis2 configuration * @throws AxisFault thrown on an error// ww w . ja va 2 s . c om */ public void init(ConfigurationContext cfgCtx, TransportOutDescription transportOut) throws AxisFault { this.configurationContext = cfgCtx; cfg = NHttpConfiguration.getInstance(); params = new BasicHttpParams(); params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, cfg.getProperty(NhttpConstants.SO_TIMEOUT_SENDER, 60000)) .setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, cfg.getProperty(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000)) .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, cfg.getProperty(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)) .setParameter(CoreProtocolPNames.USER_AGENT, "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 = transportOut.getName().toUpperCase(Locale.US) + " Sender"; ClientConnFactoryBuilder contextBuilder = initConnFactoryBuilder(transportOut); connFactory = contextBuilder.createConnFactory(params); connpool = new ConnectionPool(); proxyConfig = new ProxyConfigBuilder().parse(transportOut).build(); if (log.isInfoEnabled() && proxyConfig.getProxy() != null) { log.info("HTTP Sender using Proxy " + proxyConfig.getProxy() + " bypassing " + proxyConfig.getProxyBypass()); } Parameter param = transportOut.getParameter("warnOnHTTP500"); if (param != null) { String[] warnOnHttp500 = ((String) param.getValue()).split("\\|"); cfgCtx.setNonReplicableProperty("warnOnHTTP500", warnOnHttp500); } IOReactorConfig ioReactorConfig = new IOReactorConfig(); ioReactorConfig.setIoThreadCount(NHttpConfiguration.getInstance().getClientIOWorkers()); ioReactorConfig.setSoTimeout(cfg.getProperty(NhttpConstants.SO_TIMEOUT_RECEIVER, 60000)); ioReactorConfig.setConnectTimeout(cfg.getProperty(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000)); ioReactorConfig.setTcpNoDelay(cfg.getProperty(CoreConnectionPNames.TCP_NODELAY, 1) == 1); if (cfg.getBooleanValue("http.nio.interest-ops-queueing", false)) { ioReactorConfig.setInterestOpQueued(true); } try { String prefix = name + " I/O dispatcher"; ioReactor = new DefaultConnectingIOReactor(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) { log.error("Error starting the IOReactor", e); throw new AxisFault(e.getMessage(), e); } metrics = new NhttpMetricsCollector(false, transportOut.getName()); handler = new ClientHandler(connpool, connFactory, proxyConfig.getCreds(), cfgCtx, params, metrics); iodispatch = new ClientIODispatch(handler, connFactory); final IOEventDispatch ioEventDispatch = iodispatch; // start the Sender in a new seperate thread Thread t = new Thread(new Runnable() { public void run() { try { ioReactor.execute(ioEventDispatch); } catch (InterruptedIOException ex) { log.fatal("Reactor Interrupted"); } catch (IOException e) { log.fatal("Encountered an I/O error: " + e.getMessage(), e); } log.info(name + " Shutdown"); } }, "HttpCoreNIOSender"); t.start(); log.info(name + " starting"); // register with JMX mbeanSupport = new TransportMBeanSupport(this, "nio-" + transportOut.getName()); mbeanSupport.register(); state = BaseConstants.STARTED; }
From source file:org.bigmouth.nvwa.network.http.HttpClientHelper.java
@SuppressWarnings("deprecation") private static HttpClient getHttpClient(File keystore, char[] pwd, ClientConnectionManager ccm, int port, int timeout) throws Exception { SchemeRegistry sr = ccm.getSchemeRegistry(); KeyStore truststore = KeyStore.getInstance(KeyStore.getDefaultType()); truststore.load(new FileInputStream(keystore), pwd); SSLSocketFactory socketFactory = new SSLSocketFactory(truststore); socketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); sr.register(new Scheme("https", port, socketFactory)); HttpClient httpClient = new DefaultHttpClient(ccm); httpClient.getParams().setParameter(CoreConnectionPNames.SO_KEEPALIVE, true); httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, timeout); httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, timeout); return httpClient; }
From source file:org.bigmouth.nvwa.network.http.HttpClientHelper.java
private static HttpClient getHttpClient(SSLContext ctx, ClientConnectionManager ccm, int port, int timeout) { SchemeRegistry sr = ccm.getSchemeRegistry(); sr.register(//ww w . j a v a 2s. com new Scheme("https", port, new SSLSocketFactory(ctx, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER))); HttpClient httpClient = new DefaultHttpClient(ccm); httpClient.getParams().setParameter(CoreConnectionPNames.SO_KEEPALIVE, true); httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, timeout); httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, timeout); return httpClient; }
From source file:org.bigmouth.nvwa.network.http.HttpClientHelper.java
public static HttpClient http(int timeout) { HttpClient httpClient = new DefaultHttpClient(); httpClient.getParams().setParameter(CoreConnectionPNames.SO_KEEPALIVE, true); httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, timeout); httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, timeout); return httpClient; }
From source file:org.eclipse.ecf.provider.filetransfer.httpclient4.HttpClientRetrieveFileTransfer.java
protected void openStreams() throws IncomingFileTransferException { Trace.entering(Activator.PLUGIN_ID, DebugOptions.METHODS_ENTERING, this.getClass(), "openStreams"); //$NON-NLS-1$ final String urlString = getRemoteFileURL().toString(); this.doneFired = false; int code = -1; try {// w w w. ja v a2s.c om httpClient.getParams().setIntParameter(CoreConnectionPNames.SO_TIMEOUT, getSocketReadTimeout()); int connectTimeout = getConnectTimeout(); httpClient.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, connectTimeout); setupAuthentication(urlString); getMethod = new HttpGet(urlString); // Define a CredentialsProvider - found that possibility while debugging in org.apache.commons.httpclient.HttpMethodDirector.processProxyAuthChallenge(HttpMethod) // Seems to be another way to select the credentials. setRequestHeaderValues(); Trace.trace(Activator.PLUGIN_ID, "retrieve=" + urlString); //$NON-NLS-1$ // Set request header for possible gzip encoding, but only if // 1) The file range specification is null (we want the whole file) // 2) The target remote file does *not* end in .gz (see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=280205) if (getFileRangeSpecification() == null && !targetHasGzSuffix(super.getRemoteFileName())) { Trace.trace(Activator.PLUGIN_ID, "Accept-Encoding: gzip,deflate added to request header"); //$NON-NLS-1$ // Add the interceptors to provide the gzip httpClient.addRequestInterceptor(new RequestAcceptEncoding()); httpClient.addResponseInterceptor(new ResponseContentEncoding()); } else { Trace.trace(Activator.PLUGIN_ID, "Accept-Encoding NOT added to header"); //$NON-NLS-1$ } fireConnectStartEvent(); if (checkAndHandleDone()) { return; } connectingSockets.clear(); // Actually execute get and get response code (since redirect is set to true, then // redirect response code handled internally if (connectJob == null) { performConnect(new NullProgressMonitor()); } else { connectJob.schedule(); connectJob.join(); connectJob = null; } if (checkAndHandleDone()) { return; } code = responseCode; responseHeaders = getResponseHeaders(); Trace.trace(Activator.PLUGIN_ID, "retrieve resp=" + code); //$NON-NLS-1$ // Check for NTLM proxy in response headers // This check is to deal with bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=252002 boolean ntlmProxyFound = NTLMProxyDetector.detectNTLMProxy(httpContext); if (ntlmProxyFound && !hasForceNTLMProxyOption()) throw new IncomingFileTransferException( "HttpClient Provider is not configured to support NTLM proxy authentication.", //$NON-NLS-1$ HttpClientOptions.NTLM_PROXY_RESPONSE_CODE); if (NTLMProxyDetector.detectSPNEGOProxy(httpContext)) throw new BrowseFileTransferException( "HttpClient Provider does not support the use of SPNEGO proxy authentication."); //$NON-NLS-1$ if (code == HttpURLConnection.HTTP_PARTIAL || code == HttpURLConnection.HTTP_OK) { getResponseHeaderValues(); setInputStream(httpResponse.getEntity().getContent()); fireReceiveStartEvent(); } else if (code == HttpURLConnection.HTTP_NOT_FOUND) { EntityUtils.consume(httpResponse.getEntity()); throw new IncomingFileTransferException(NLS.bind("File not found: {0}", urlString), code); //$NON-NLS-1$ } else if (code == HttpURLConnection.HTTP_UNAUTHORIZED) { EntityUtils.consume(httpResponse.getEntity()); throw new IncomingFileTransferException(Messages.HttpClientRetrieveFileTransfer_Unauthorized, code); } else if (code == HttpURLConnection.HTTP_FORBIDDEN) { EntityUtils.consume(httpResponse.getEntity()); throw new IncomingFileTransferException("Forbidden", code); //$NON-NLS-1$ } else if (code == HttpURLConnection.HTTP_PROXY_AUTH) { EntityUtils.consume(httpResponse.getEntity()); throw new IncomingFileTransferException(Messages.HttpClientRetrieveFileTransfer_Proxy_Auth_Required, code); } else { Trace.trace(Activator.PLUGIN_ID, EntityUtils.toString(httpResponse.getEntity())); // EntityUtils.consume(httpResponse.getEntity()); throw new IncomingFileTransferException( NLS.bind(Messages.HttpClientRetrieveFileTransfer_ERROR_GENERAL_RESPONSE_CODE, new Integer(code)), code); } } catch (final Exception e) { Trace.throwing(Activator.PLUGIN_ID, DebugOptions.EXCEPTIONS_THROWING, this.getClass(), "openStreams", //$NON-NLS-1$ e); if (code == -1) { if (!isDone()) { setDoneException(e); } fireTransferReceiveDoneEvent(); } else { IncomingFileTransferException ex = (IncomingFileTransferException) ((e instanceof IncomingFileTransferException) ? e : new IncomingFileTransferException( NLS.bind(Messages.HttpClientRetrieveFileTransfer_EXCEPTION_COULD_NOT_CONNECT, urlString), e, code)); throw ex; } } Trace.exiting(Activator.PLUGIN_ID, DebugOptions.METHODS_EXITING, this.getClass(), "openStreams"); //$NON-NLS-1$ }
From source file:org.eclipse.ecf.provider.filetransfer.httpclient4.HttpClientRetrieveFileTransfer.java
private boolean openStreamsForResume() { Trace.entering(Activator.PLUGIN_ID, DebugOptions.METHODS_ENTERING, this.getClass(), "openStreamsForResume"); //$NON-NLS-1$ final String urlString = getRemoteFileURL().toString(); this.doneFired = false; int code = -1; try {//from w w w.j av a 2 s . co m httpClient.getParams().setIntParameter(CoreConnectionPNames.SO_TIMEOUT, getSocketReadTimeout()); int connectTimeout = getConnectTimeout(); httpClient.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, connectTimeout); setupAuthentication(urlString); getMethod = new HttpGet(urlString); // Define a CredentialsProvider - found that possibility while debugging in org.apache.commons.httpclient.HttpMethodDirector.processProxyAuthChallenge(HttpMethod) // Seems to be another way to select the credentials. setResumeRequestHeaderValues(); Trace.trace(Activator.PLUGIN_ID, "resume=" + urlString); //$NON-NLS-1$ // Gzip encoding is not an option for resume fireConnectStartEvent(); if (checkAndHandleDone()) { return false; } connectingSockets.clear(); // Actually execute get and get response code (since redirect is set to true, then // redirect response code handled internally if (connectJob == null) { performConnect(new NullProgressMonitor()); } else { connectJob.schedule(); connectJob.join(); connectJob = null; } if (checkAndHandleDone()) { return false; } code = responseCode; responseHeaders = getResponseHeaders(); Trace.trace(Activator.PLUGIN_ID, "retrieve resp=" + code); //$NON-NLS-1$ if (code == HttpURLConnection.HTTP_PARTIAL || code == HttpURLConnection.HTTP_OK) { getResumeResponseHeaderValues(); setInputStream(httpResponse.getEntity().getContent()); this.paused = false; fireReceiveResumedEvent(); } else if (code == HttpURLConnection.HTTP_NOT_FOUND) { EntityUtils.consume(httpResponse.getEntity()); throw new IncomingFileTransferException(NLS.bind("File not found: {0}", urlString), code, //$NON-NLS-1$ responseHeaders); } else if (code == HttpURLConnection.HTTP_UNAUTHORIZED) { EntityUtils.consume(httpResponse.getEntity()); throw new IncomingFileTransferException(Messages.HttpClientRetrieveFileTransfer_Unauthorized, code, responseHeaders); } else if (code == HttpURLConnection.HTTP_FORBIDDEN) { EntityUtils.consume(httpResponse.getEntity()); throw new IncomingFileTransferException("Forbidden", code, responseHeaders); //$NON-NLS-1$ } else if (code == HttpURLConnection.HTTP_PROXY_AUTH) { EntityUtils.consume(httpResponse.getEntity()); throw new IncomingFileTransferException(Messages.HttpClientRetrieveFileTransfer_Proxy_Auth_Required, code, responseHeaders); } else { EntityUtils.consume(httpResponse.getEntity()); throw new IncomingFileTransferException( NLS.bind(Messages.HttpClientRetrieveFileTransfer_ERROR_GENERAL_RESPONSE_CODE, new Integer(code)), code, responseHeaders); } Trace.exiting(Activator.PLUGIN_ID, DebugOptions.METHODS_EXITING, this.getClass(), "openStreamsForResume", Boolean.TRUE); //$NON-NLS-1$ return true; } catch (final Exception e) { Trace.catching(Activator.PLUGIN_ID, DebugOptions.EXCEPTIONS_CATCHING, this.getClass(), "openStreamsForResume", e); //$NON-NLS-1$ if (code == -1) { if (!isDone()) { setDoneException(e); } } else { setDoneException((e instanceof IncomingFileTransferException) ? e : new IncomingFileTransferException( NLS.bind(Messages.HttpClientRetrieveFileTransfer_EXCEPTION_COULD_NOT_CONNECT, urlString), e, code, responseHeaders)); } fireTransferReceiveDoneEvent(); Trace.exiting(Activator.PLUGIN_ID, DebugOptions.METHODS_EXITING, this.getClass(), "openStreamsForResume", Boolean.FALSE); //$NON-NLS-1$ return false; } }