List of usage examples for org.apache.commons.httpclient HostConfiguration setHost
public void setHost(String paramString, int paramInt, Protocol paramProtocol)
From source file:org.parosproxy.paros.network.HttpSender.java
public int executeMethod(HttpMethod method, HttpState state) throws IOException { int responseCode = -1; String hostName;/* w w w . ja v a 2s .co m*/ hostName = method.getURI().getHost(); method.setDoAuthentication(true); HostConfiguration hc = null; HttpClient requestClient; if (param.isUseProxy(hostName)) { requestClient = clientViaProxy; } else { // ZAP: use custom client on upgrade connection and on event-source data type Header connectionHeader = method.getRequestHeader("connection"); boolean isUpgrade = connectionHeader != null && connectionHeader.getValue().toLowerCase().contains("upgrade"); // ZAP: try to apply original handling of ParosProxy requestClient = client; if (isUpgrade) { // Unless upgrade, when using another client that allows us to expose the socket // connection. requestClient = new HttpClient(new ZapHttpConnectionManager()); } } if (this.initiator == CHECK_FOR_UPDATES_INITIATOR) { // Use the 'strict' SSLConnector, ie one that performs all the usual cert checks // The 'standard' one 'trusts' everything // This is to ensure that all 'check-for update' calls are made to the expected https urls // without this is would be possible to intercept and change the response which could result // in the user downloading and installing a malicious add-on hc = new HostConfiguration() { @Override public synchronized void setHost(URI uri) { try { setHost(new HttpHost(uri.getHost(), uri.getPort(), getProtocol())); } catch (URIException e) { throw new IllegalArgumentException(e.toString()); } }; }; hc.setHost(hostName, method.getURI().getPort(), new Protocol("https", (ProtocolSocketFactory) new SSLConnector(false), 443)); if (param.isUseProxy(hostName)) { hc.setProxyHost(new ProxyHost(param.getProxyChainName(), param.getProxyChainPort())); if (param.isUseProxyChainAuth()) { requestClient.getState().setProxyCredentials(getAuthScope(param), getNTCredentials(param)); } } } // ZAP: Check if a custom state is being used if (state != null) { // Make sure cookies are enabled method.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY); } responseCode = requestClient.executeMethod(hc, method, state); return responseCode; }
From source file:org.redpill.alfresco.pdfapilot.client.PdfaPilotClientImpl.java
private HttpClient createHttpClient(int retries, int connectionTimeoutInMillis) { MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); HttpClient client = new HttpClient(connectionManager); client.getHttpConnectionManager().getParams().setTcpNoDelay(true); client.getHttpConnectionManager().getParams().setConnectionTimeout(connectionTimeoutInMillis); client.getHttpConnectionManager().getParams().setSoTimeout(_transformationTimeout * 1000); client.getHttpConnectionManager().getParams().setMaxTotalConnections(_maxTotalConnections); client.getHttpConnectionManager().getParams().setDefaultMaxConnectionsPerHost(_maxConcurrentConnections); URI uri;/*from w w w. j av a2s.c om*/ try { uri = new URI(_serverUrl); } catch (URISyntaxException e) { throw new RuntimeException(e); } HostConfiguration hostConfiguration = new HostConfiguration(); hostConfiguration.setHost(uri.getHost(), uri.getPort(), uri.getScheme()); client.getHttpConnectionManager().getParams().setMaxConnectionsPerHost(hostConfiguration, _maxConcurrentConnections); client.getState().setCredentials(new AuthScope(null, -1, null), new UsernamePasswordCredentials(_username, _password)); client.getParams().setAuthenticationPreemptive(true); DefaultHttpMethodRetryHandler retryhandler = new DefaultHttpMethodRetryHandler(retries, true); client.getParams().setParameter("http.method.retry-handler", retryhandler); return client; }
From source file:org.socraticgrid.displaycalendarlib.SogoCalendar.java
public HostConfiguration createHostConfiguration() { HostConfiguration hostConfig = new HostConfiguration(); hostConfig.setHost(host, port, protocol); return hostConfig; }
From source file:org.tuckey.web.filters.urlrewrite.RequestProxy.java
/** * This method performs the proxying of the request to the target address. * * @param target The target address. Has to be a fully qualified address. The request is send as-is to this address. * @param hsRequest The request data which should be send to the * @param hsResponse The response data which will contain the data returned by the proxied request to target. * @throws java.io.IOException Passed on from the connection logic. *///from w w w .j a va 2 s .com public static void execute(final String target, final HttpServletRequest hsRequest, final HttpServletResponse hsResponse) throws IOException { if (log.isInfoEnabled()) { log.info("execute, target is " + target); log.info("response commit state: " + hsResponse.isCommitted()); } if (StringUtils.isBlank(target)) { log.error("The target address is not given. Please provide a target address."); return; } log.info("checking url"); final URL url; try { url = new URL(target); } catch (MalformedURLException e) { log.error("The provided target url is not valid.", e); return; } log.info("seting up the host configuration"); final HostConfiguration config = new HostConfiguration(); ProxyHost proxyHost = getUseProxyServer((String) hsRequest.getAttribute("use-proxy")); if (proxyHost != null) config.setProxyHost(proxyHost); final int port = url.getPort() != -1 ? url.getPort() : url.getDefaultPort(); config.setHost(url.getHost(), port, url.getProtocol()); if (log.isInfoEnabled()) log.info("config is " + config.toString()); final HttpMethod targetRequest = setupProxyRequest(hsRequest, url); if (targetRequest == null) { log.error("Unsupported request method found: " + hsRequest.getMethod()); return; } //perform the reqeust to the target server final HttpClient client = new HttpClient(new SimpleHttpConnectionManager()); if (log.isInfoEnabled()) { log.info("client state" + client.getState()); log.info("client params" + client.getParams().toString()); log.info("executeMethod / fetching data ..."); } final int result; if (targetRequest instanceof EntityEnclosingMethod) { final RequestProxyCustomRequestEntity requestEntity = new RequestProxyCustomRequestEntity( hsRequest.getInputStream(), hsRequest.getContentLength(), hsRequest.getContentType()); final EntityEnclosingMethod entityEnclosingMethod = (EntityEnclosingMethod) targetRequest; entityEnclosingMethod.setRequestEntity(requestEntity); result = client.executeMethod(config, entityEnclosingMethod); } else { result = client.executeMethod(config, targetRequest); } //copy the target response headers to our response setupResponseHeaders(targetRequest, hsResponse); InputStream originalResponseStream = targetRequest.getResponseBodyAsStream(); //the body might be null, i.e. for responses with cache-headers which leave out the body if (originalResponseStream != null) { OutputStream responseStream = hsResponse.getOutputStream(); copyStream(originalResponseStream, responseStream); } log.info("set up response, result code was " + result); }