List of usage examples for org.apache.commons.httpclient HostConfiguration getParams
public HostParams getParams()
From source file:com.eviware.soapui.impl.wsdl.monitor.jettyproxy.TunnelServlet.java
public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException { monitor.fireOnRequest(request, response); if (response.isCommitted()) return;/* w w w . jav a2 s . c o m*/ ExtendedHttpMethod postMethod; // for this create ui server and port, properties. InetSocketAddress inetAddress = new InetSocketAddress(sslEndPoint, sslPort); HttpServletRequest httpRequest = (HttpServletRequest) request; if (httpRequest.getMethod().equals("GET")) postMethod = new ExtendedGetMethod(); else postMethod = new ExtendedPostMethod(); JProxyServletWsdlMonitorMessageExchange capturedData = new JProxyServletWsdlMonitorMessageExchange(project); capturedData.setRequestHost(httpRequest.getRemoteHost()); capturedData.setRequestHeader(httpRequest); capturedData.setTargetURL(this.prot + inetAddress.getHostName()); CaptureInputStream capture = new CaptureInputStream(httpRequest.getInputStream()); // copy headers Enumeration<?> headerNames = httpRequest.getHeaderNames(); while (headerNames.hasMoreElements()) { String hdr = (String) headerNames.nextElement(); String lhdr = hdr.toLowerCase(); if ("host".equals(lhdr)) { Enumeration<?> vals = httpRequest.getHeaders(hdr); while (vals.hasMoreElements()) { String val = (String) vals.nextElement(); if (val.startsWith("127.0.0.1")) { postMethod.addRequestHeader(hdr, sslEndPoint); } } continue; } Enumeration<?> vals = httpRequest.getHeaders(hdr); while (vals.hasMoreElements()) { String val = (String) vals.nextElement(); if (val != null) { postMethod.addRequestHeader(hdr, val); } } } if (postMethod instanceof ExtendedPostMethod) ((ExtendedPostMethod) postMethod) .setRequestEntity(new InputStreamRequestEntity(capture, request.getContentType())); HostConfiguration hostConfiguration = new HostConfiguration(); httpRequest.getProtocol(); hostConfiguration.getParams().setParameter(SoapUIHostConfiguration.SOAPUI_SSL_CONFIG, settings.getString(SecurityTabForm.SSLTUNNEL_KEYSTOREPATH, "") + " " + settings.getString(SecurityTabForm.SSLTUNNEL_KEYSTOREPASSWORD, "")); hostConfiguration.setHost(new URI(this.prot + sslEndPoint, true)); hostConfiguration = ProxyUtils.initProxySettings(settings, httpState, hostConfiguration, prot + sslEndPoint, new DefaultPropertyExpansionContext(project)); if (sslEndPoint.indexOf("/") < 0) postMethod.setPath("/"); else postMethod.setPath(sslEndPoint.substring(sslEndPoint.indexOf("/"), sslEndPoint.length())); monitor.fireBeforeProxy(request, response, postMethod, hostConfiguration); if (settings.getBoolean(LaunchForm.SSLTUNNEL_REUSESTATE)) { if (httpState == null) httpState = new HttpState(); HttpClientSupport.getHttpClient().executeMethod(hostConfiguration, postMethod, httpState); } else { HttpClientSupport.getHttpClient().executeMethod(hostConfiguration, postMethod); } capturedData.stopCapture(); capturedData.setRequest(capture.getCapturedData()); capturedData.setRawResponseBody(postMethod.getResponseBody()); capturedData.setResponseHeader(postMethod); capturedData.setRawRequestData(getRequestToBytes(request.toString(), postMethod, capture)); capturedData.setRawResponseData( getResponseToBytes(response.toString(), postMethod, capturedData.getRawResponseBody())); monitor.fireAfterProxy(request, response, postMethod, capturedData); StringToStringsMap responseHeaders = capturedData.getResponseHeaders(); // copy headers to response HttpServletResponse httpResponse = (HttpServletResponse) response; for (String name : responseHeaders.keySet()) { for (String header : responseHeaders.get(name)) httpResponse.addHeader(name, header); } IO.copy(new ByteArrayInputStream(capturedData.getRawResponseBody()), httpResponse.getOutputStream()); postMethod.releaseConnection(); synchronized (this) { monitor.addMessageExchange(capturedData); } capturedData = null; }
From source file:com.twinsoft.convertigo.engine.ProxyManager.java
public void setProxy(HostConfiguration hostConfiguration, HttpState httpState, URL url) throws EngineException { // Proxy configuration Boolean needProxy = true;//w w w . jav a 2 s . co m String[] bpDomains = getBypassDomains(); String urlHost = url.getHost(); for (String domain : bpDomains) { if (domain.equals(urlHost)) { needProxy = false; } } hostConfiguration.getParams().setParameter("hostConfId", this.hostConfId); if (isEnabled()) { if (needProxy) { if (proxyMode == ProxyMode.manual) { if (!proxyServer.equals("")) { hostConfiguration.setProxy(proxyServer, proxyPort); Engine.logProxyManager .debug("(ProxyManager) Using proxy: " + proxyServer + ":" + proxyPort); } else { disableProxy(hostConfiguration); } } else if (proxyMode == ProxyMode.auto) { // String result = pacUtils.evaluate(url.toString(), url.getHost()); // // if (result.startsWith("PROXY")) { // result = result.replaceAll("PROXY\\s*", ""); // String pacServer = result.split(":")[0]; // int pacPort = Integer.parseInt(result.split(":")[1]); // this.proxyServer = pacServer; // this.proxyPort = pacPort; // hostConfiguration.setProxy(pacServer, pacPort); // Engine.logProxyManager.debug("(ProxyManager) Using proxy from auto configuration file: " + proxyServer + ":" + proxyPort); // } // else { // hostConfiguration.setProxyHost(null); // } PacInfos pacInfos = getPacInfos(url.toString(), url.getHost()); if (pacInfos != null) { proxyServer = pacInfos.getServer(); proxyPort = pacInfos.getPort(); hostConfiguration.setProxy(proxyServer, proxyPort); Engine.logProxyManager.debug("(ProxyManager) Using proxy from auto configuration file: " + proxyServer + ":" + proxyPort); } else { disableProxy(hostConfiguration); } } if (proxyMethod == ProxyMethod.basic) { setBasicAuth(httpState); } else if (proxyMethod == ProxyMethod.ntlm) { int indexSlash = this.proxyUser.indexOf("\\"); if (indexSlash != -1) { setNtlmAuth(httpState); } else { throw new EngineException( "\nWrong username, please indicate the domain name for ntlm authentication. (eg: domain\\user)\n"); } } else { setAnonymAuth(httpState); } } else { disableProxy(hostConfiguration); } } }
From source file:com.iflytek.spider.protocol.httpclient.Http.java
/** * Configures the HTTP client//from ww w .j a v a2 s . c o m */ private void configureClient() { // Set up an HTTPS socket factory that accepts self-signed certs. Protocol https = new Protocol("https", new DummySSLProtocolSocketFactory(), 443); Protocol.registerProtocol("https", https); HttpConnectionManagerParams params = connectionManager.getParams(); params.setConnectionTimeout(timeout); params.setSoTimeout(timeout); params.setSendBufferSize(BUFFER_SIZE); params.setReceiveBufferSize(BUFFER_SIZE); params.setMaxTotalConnections(maxThreadsTotal); params.setDefaultMaxConnectionsPerHost(maxThreadsTotal); // executeMethod(HttpMethod) seems to ignore the connection timeout on // the connection manager. // set it explicitly on the HttpClient. client.getParams().setConnectionManagerTimeout(timeout); HostConfiguration hostConf = client.getHostConfiguration(); ArrayList headers = new ArrayList(); // Set the User Agent in the header headers.add(new Header("User-Agent", userAgent)); // prefer English headers.add(new Header("Accept-Language", acceptLanguage)); // prefer UTF-8 headers.add(new Header("Accept-Charset", "utf-8,ISO-8859-1;q=0.7,*;q=0.7")); // prefer understandable formats headers.add(new Header("Accept", "text/html,application/xml;q=0.9,application/xhtml+xml,text/xml;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5")); // accept gzipped content headers.add(new Header("Accept-Encoding", "x-gzip, gzip, deflate")); hostConf.getParams().setParameter("http.default-headers", headers); // HTTP proxy server details if (useProxy) { hostConf.setProxy(proxyHost, proxyPort); if (proxyUsername.length() > 0) { AuthScope proxyAuthScope = getAuthScope(this.proxyHost, this.proxyPort, this.proxyRealm); NTCredentials proxyCredentials = new NTCredentials(this.proxyUsername, this.proxyPassword, this.agentHost, this.proxyRealm); client.getState().setProxyCredentials(proxyAuthScope, proxyCredentials); } } }
From source file:com.iflytek.spider.protocol.httpclient.HttpSimply.java
/** * Configures the HTTP client// w w w . j a v a 2 s . c om */ private void configureClient() { // Set up an HTTPS socket factory that accepts self-signed certs. Protocol https = new Protocol("https", new DummySSLProtocolSocketFactory(), 443); Protocol.registerProtocol("https", https); HttpConnectionManagerParams params = connectionManager.getParams(); params.setConnectionTimeout(timeout); //params.setSoTimeout(timeout); timeouttimeout params.setSendBufferSize(BUFFER_SIZE); params.setReceiveBufferSize(BUFFER_SIZE); params.setMaxTotalConnections(maxThreadsTotal); params.setDefaultMaxConnectionsPerHost(maxThreadsTotal); // executeMethod(HttpMethod) seems to ignore the connection timeout on // the connection manager. // set it explicitly on the HttpClient. client.getParams().setConnectionManagerTimeout(timeout); HostConfiguration hostConf = client.getHostConfiguration(); ArrayList headers = new ArrayList(); // Set the User Agent in the header headers.add(new Header("User-Agent", userAgent)); // prefer English headers.add(new Header("Accept-Language", acceptLanguage)); // prefer UTF-8 headers.add(new Header("Accept-Charset", "utf-8,ISO-8859-1;q=0.7,*;q=0.7")); // prefer understandable formats headers.add(new Header("Accept", "text/html,application/xml;q=0.9,application/xhtml+xml,text/xml;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5")); // accept gzipped content headers.add(new Header("Accept-Encoding", "x-gzip, gzip, deflate")); hostConf.getParams().setParameter("http.default-headers", headers); // HTTP proxy server details if (useProxy) { hostConf.setProxy(proxyHost, proxyPort); if (proxyUsername.length() > 0) { AuthScope proxyAuthScope = getAuthScope(this.proxyHost, this.proxyPort, this.proxyRealm); NTCredentials proxyCredentials = new NTCredentials(this.proxyUsername, this.proxyPassword, this.agentHost, this.proxyRealm); client.getState().setProxyCredentials(proxyAuthScope, proxyCredentials); } } }
From source file:flex.messaging.services.http.HTTPProxyAdapter.java
private void initHttpConnectionManagerParams(HTTPConnectionManagerSettings settings) { connectionParams = new HttpConnectionManagerParams(); connectionParams.setMaxTotalConnections(settings.getMaxTotalConnections()); connectionParams.setDefaultMaxConnectionsPerHost(settings.getDefaultMaxConnectionsPerHost()); if (!settings.getCookiePolicy().equals(CookiePolicy.DEFAULT)) { HttpClientParams httpClientParams = (HttpClientParams) connectionParams.getDefaults(); httpClientParams.setCookiePolicy(settings.getCookiePolicy()); }// www.j a va 2 s . c o m if (settings.getConnectionTimeout() >= 0) connectionParams.setConnectionTimeout(settings.getConnectionTimeout()); if (settings.getSocketTimeout() >= 0) connectionParams.setSoTimeout(settings.getSocketTimeout()); connectionParams.setStaleCheckingEnabled(settings.isStaleCheckingEnabled()); if (settings.getSendBufferSize() > 0) connectionParams.setSendBufferSize(settings.getSendBufferSize()); if (settings.getReceiveBufferSize() > 0) connectionParams.setReceiveBufferSize(settings.getReceiveBufferSize()); connectionParams.setTcpNoDelay(settings.isTcpNoDelay()); connectionParams.setLinger(settings.getLinger()); if (settings.getMaxConnectionsPerHost() != null) { Iterator it = settings.getMaxConnectionsPerHost().iterator(); while (it.hasNext()) { HostConfigurationSettings hcs = (HostConfigurationSettings) it.next(); HostConfiguration hostConfig = new HostConfiguration(); if (hcs.getProtocol() != null) { Protocol protocol = Protocol.getProtocol(hcs.getProtocol()); hostConfig.setHost(hcs.getHost(), hcs.getPort(), protocol); } else if (hcs.getProtocolFactory() != null) { Protocol protocol = hcs.getProtocolFactory().getProtocol(); if (hcs.getPort() > 0) hostConfig.setHost(hcs.getHost(), hcs.getPort(), protocol); else hostConfig.setHost(hcs.getHost(), protocol.getDefaultPort(), protocol); } else { if (hcs.getPort() > 0) hostConfig.setHost(hcs.getHost(), hcs.getPort()); else hostConfig.setHost(hcs.getHost()); } if (hcs.getVirtualHost() != null) { HostParams params = hostConfig.getParams(); if (params != null) params.setVirtualHost(hcs.getVirtualHost()); } if (hcs.getProxyHost() != null) { hostConfig.setProxy(hcs.getProxyHost(), hcs.getProxyPort()); } try { InetAddress addr = InetAddress.getByName(hcs.getLocalAddress()); hostConfig.setLocalAddress(addr); } catch (UnknownHostException ex) { } connectionParams.setMaxConnectionsPerHost(hostConfig, hcs.getMaximumConnections()); } } }
From source file:ch.cyberduck.core.http.HTTP3Session.java
protected HostConfiguration getHostConfiguration(Host host) { int port = host.getPort(); final HostConfiguration configuration = new StickyHostConfiguration(); if ("https".equals(host.getProtocol().getScheme())) { if (-1 == port) { port = 443;//w w w.j a v a2 s . c om } // Configuration with custom socket factory using the trust manager configuration.setHost(host.getHostname(), port, new org.apache.commons.httpclient.protocol.Protocol(host.getProtocol().getScheme(), new SSLSocketFactory(this.getTrustManager(host.getHostname())), port)); if (Preferences.instance().getBoolean("connection.proxy.enable")) { final Proxy proxy = ProxyFactory.instance(); if (proxy.isHTTPSProxyEnabled(host)) { configuration.setProxy(proxy.getHTTPSProxyHost(host), proxy.getHTTPSProxyPort(host)); } } } else if ("http".equals(host.getProtocol().getScheme())) { if (-1 == port) { port = 80; } configuration.setHost(host.getHostname(), port, new org.apache.commons.httpclient.protocol.Protocol( host.getProtocol().getScheme(), new DefaultProtocolSocketFactory(), port)); if (Preferences.instance().getBoolean("connection.proxy.enable")) { final Proxy proxy = ProxyFactory.instance(); if (proxy.isHTTPProxyEnabled(host)) { configuration.setProxy(proxy.getHTTPProxyHost(host), proxy.getHTTPProxyPort(host)); } } } final HostParams parameters = configuration.getParams(); parameters.setParameter(HttpMethodParams.USER_AGENT, this.getUserAgent()); parameters.setParameter(HttpMethodParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); parameters.setParameter(HttpMethodParams.SO_TIMEOUT, this.timeout()); parameters.setParameter(HttpMethodParams.CREDENTIAL_CHARSET, "ISO-8859-1"); parameters.setParameter(HttpClientParams.MAX_REDIRECTS, 10); return configuration; }
From source file:com.liferay.portal.util.HttpImpl.java
public HostConfiguration getHostConfiguration(String location) throws IOException { if (_log.isDebugEnabled()) { _log.debug("Location is " + location); }// www .j ava2 s.c om HostConfiguration hostConfiguration = new HostConfiguration(); hostConfiguration.setHost(new URI(location, false)); if (isProxyHost(hostConfiguration.getHost())) { hostConfiguration.setProxy(_PROXY_HOST, _PROXY_PORT); } HttpConnectionManager httpConnectionManager = _httpClient.getHttpConnectionManager(); HttpConnectionManagerParams httpConnectionManagerParams = httpConnectionManager.getParams(); int defaultMaxConnectionsPerHost = httpConnectionManagerParams.getMaxConnectionsPerHost(hostConfiguration); int maxConnectionsPerHost = GetterUtil.getInteger(PropsUtil.get( HttpImpl.class.getName() + ".max.connections.per.host", new Filter(hostConfiguration.getHost()))); if ((maxConnectionsPerHost > 0) && (maxConnectionsPerHost != defaultMaxConnectionsPerHost)) { httpConnectionManagerParams.setMaxConnectionsPerHost(hostConfiguration, maxConnectionsPerHost); } int timeout = GetterUtil.getInteger( PropsUtil.get(HttpImpl.class.getName() + ".timeout", new Filter(hostConfiguration.getHost()))); if (timeout > 0) { HostParams hostParams = hostConfiguration.getParams(); hostParams.setIntParameter(HttpConnectionParams.CONNECTION_TIMEOUT, timeout); hostParams.setIntParameter(HttpConnectionParams.SO_TIMEOUT, timeout); } return hostConfiguration; }
From source file:org.apache.any23.http.DefaultHTTPClient.java
private void ensureClientInitialized() { if (configuration == null) throw new IllegalStateException("client must be initialized first."); if (client != null) return;//ww w .j a v a 2 s . c o m client = new HttpClient(manager); HttpConnectionManager connectionManager = client.getHttpConnectionManager(); HttpConnectionManagerParams params = connectionManager.getParams(); params.setConnectionTimeout(configuration.getDefaultTimeout()); params.setSoTimeout(configuration.getDefaultTimeout()); params.setMaxTotalConnections(configuration.getMaxConnections()); HostConfiguration hostConf = client.getHostConfiguration(); List<Header> headers = new ArrayList<Header>(); headers.add(new Header("User-Agent", configuration.getUserAgent())); if (configuration.getAcceptHeader() != null) { headers.add(new Header("Accept", configuration.getAcceptHeader())); } headers.add(new Header("Accept-Language", "en-us,en-gb,en,*;q=0.3")); //TODO: this must become parametric. headers.add(new Header("Accept-Charset", "utf-8,iso-8859-1;q=0.7,*;q=0.5")); // headers.add(new Header("Accept-Encoding", "x-gzip, gzip")); hostConf.getParams().setParameter("http.default-headers", headers); }
From source file:org.apache.nutch.protocol.httpclient.Http.java
/** * Configures the HTTP client// www . j a v a2 s. c om */ private void configureClient() { // Set up an HTTPS socket factory that accepts self-signed certs. // ProtocolSocketFactory factory = new SSLProtocolSocketFactory(); ProtocolSocketFactory factory = new DummySSLProtocolSocketFactory(); Protocol https = new Protocol("https", factory, 443); Protocol.registerProtocol("https", https); HttpConnectionManagerParams params = connectionManager.getParams(); params.setConnectionTimeout(timeout); params.setSoTimeout(timeout); params.setSendBufferSize(BUFFER_SIZE); params.setReceiveBufferSize(BUFFER_SIZE); // -------------------------------------------------------------------------------- // NUTCH-1836: Modification to increase the number of available connections // for multi-threaded crawls. // -------------------------------------------------------------------------------- params.setMaxTotalConnections(conf.getInt("mapreduce.tasktracker.map.tasks.maximum", 5) * conf.getInt("fetcher.threads.fetch", maxThreadsTotal)); // Also set max connections per host to maxThreadsTotal since all threads // might be used to fetch from the same host - otherwise timeout errors can // occur params.setDefaultMaxConnectionsPerHost(conf.getInt("fetcher.threads.fetch", maxThreadsTotal)); // executeMethod(HttpMethod) seems to ignore the connection timeout on the // connection manager. // set it explicitly on the HttpClient. client.getParams().setConnectionManagerTimeout(timeout); HostConfiguration hostConf = client.getHostConfiguration(); ArrayList<Header> headers = new ArrayList<Header>(); // Note: some header fields (e.g., "User-Agent") are set per GET request if (!acceptLanguage.isEmpty()) { headers.add(new Header("Accept-Language", acceptLanguage)); } if (!acceptCharset.isEmpty()) { headers.add(new Header("Accept-Charset", acceptCharset)); } if (!accept.isEmpty()) { headers.add(new Header("Accept", accept)); } // accept gzipped content headers.add(new Header("Accept-Encoding", "x-gzip, gzip, deflate")); hostConf.getParams().setParameter("http.default-headers", headers); // HTTP proxy server details if (useProxy) { hostConf.setProxy(proxyHost, proxyPort); if (proxyUsername.length() > 0) { AuthScope proxyAuthScope = getAuthScope(this.proxyHost, this.proxyPort, this.proxyRealm); NTCredentials proxyCredentials = new NTCredentials(this.proxyUsername, this.proxyPassword, Http.agentHost, this.proxyRealm); client.getState().setProxyCredentials(proxyAuthScope, proxyCredentials); } } }
From source file:org.apache.nutch.protocol.httpclient.HttpBak.java
/** * Configures the HTTP client/*www . j a v a 2 s . c o m*/ */ private void configureClient() { // Set up an HTTPS socket factory that accepts self-signed certs. Protocol https = new Protocol("https", new DummySSLProtocolSocketFactory(), 443); Protocol.registerProtocol("https", https); HttpConnectionManagerParams params = connectionManager.getParams(); params.setConnectionTimeout(timeout); params.setSoTimeout(timeout); params.setSendBufferSize(BUFFER_SIZE); params.setReceiveBufferSize(BUFFER_SIZE); params.setMaxTotalConnections(maxThreadsTotal); // executeMethod(HttpMethod) seems to ignore the connection timeout on the connection manager. // set it explicitly on the HttpClient. client.getParams().setConnectionManagerTimeout(timeout); HostConfiguration hostConf = client.getHostConfiguration(); ArrayList headers = new ArrayList(); // Set the User Agent in the header headers.add(new Header("User-Agent", userAgent)); // prefer English headers.add(new Header("Accept-Language", acceptLanguage)); // prefer UTF-8 headers.add(new Header("Accept-Charset", "utf-8,ISO-8859-1;q=0.7,*;q=0.7")); // prefer understandable formats headers.add(new Header("Accept", "text/html,application/xml;q=0.9,application/xhtml+xml,text/xml;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5")); // accept gzipped content headers.add(new Header("Accept-Encoding", "x-gzip, gzip, deflate")); hostConf.getParams().setParameter("http.default-headers", headers); // HTTP proxy server details if (useProxy) { hostConf.setProxy(proxyHost, proxyPort); if (proxyUsername.length() > 0) { AuthScope proxyAuthScope = getAuthScope(this.proxyHost, this.proxyPort, this.proxyRealm); NTCredentials proxyCredentials = new NTCredentials(this.proxyUsername, this.proxyPassword, this.agentHost, this.proxyRealm); client.getState().setProxyCredentials(proxyAuthScope, proxyCredentials); } } }