List of usage examples for org.apache.commons.httpclient HostConfiguration setHost
public void setHost(URI paramURI)
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;/* ww w .ja v a 2 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.eviware.soapui.impl.wsdl.monitor.jettyproxy.ProxyServlet.java
public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException { monitor.fireOnRequest(request, response); if (response.isCommitted()) return;// www. java 2 s. co m ExtendedHttpMethod method; HttpServletRequest httpRequest = (HttpServletRequest) request; if (httpRequest.getMethod().equals("GET")) method = new ExtendedGetMethod(); else method = new ExtendedPostMethod(); method.setDecompress(false); // for this create ui server and port, properties. JProxyServletWsdlMonitorMessageExchange capturedData = new JProxyServletWsdlMonitorMessageExchange(project); capturedData.setRequestHost(httpRequest.getServerName()); capturedData.setRequestMethod(httpRequest.getMethod()); capturedData.setRequestHeader(httpRequest); capturedData.setHttpRequestParameters(httpRequest); capturedData.setTargetURL(httpRequest.getRequestURL().toString()); CaptureInputStream capture = new CaptureInputStream(httpRequest.getInputStream()); // check connection header String connectionHeader = httpRequest.getHeader("Connection"); if (connectionHeader != null) { connectionHeader = connectionHeader.toLowerCase(); if (connectionHeader.indexOf("keep-alive") < 0 && connectionHeader.indexOf("close") < 0) connectionHeader = null; } // copy headers boolean xForwardedFor = false; @SuppressWarnings("unused") long contentLength = -1; Enumeration<?> headerNames = httpRequest.getHeaderNames(); while (headerNames.hasMoreElements()) { String hdr = (String) headerNames.nextElement(); String lhdr = hdr.toLowerCase(); if (dontProxyHeaders.contains(lhdr)) continue; if (connectionHeader != null && connectionHeader.indexOf(lhdr) >= 0) continue; if ("content-length".equals(lhdr)) contentLength = request.getContentLength(); Enumeration<?> vals = httpRequest.getHeaders(hdr); while (vals.hasMoreElements()) { String val = (String) vals.nextElement(); if (val != null) { method.setRequestHeader(lhdr, val); xForwardedFor |= "X-Forwarded-For".equalsIgnoreCase(hdr); } } } // Proxy headers method.setRequestHeader("Via", "SoapUI Monitor"); if (!xForwardedFor) method.addRequestHeader("X-Forwarded-For", request.getRemoteAddr()); if (method instanceof ExtendedPostMethod) ((ExtendedPostMethod) method) .setRequestEntity(new InputStreamRequestEntity(capture, request.getContentType())); HostConfiguration hostConfiguration = new HostConfiguration(); StringBuffer url = new StringBuffer("http://"); url.append(httpRequest.getServerName()); if (httpRequest.getServerPort() != 80) url.append(":" + httpRequest.getServerPort()); if (httpRequest.getServletPath() != null) { url.append(httpRequest.getServletPath()); method.setPath(httpRequest.getServletPath()); if (httpRequest.getQueryString() != null) { url.append("?" + httpRequest.getQueryString()); method.setPath(httpRequest.getServletPath() + "?" + httpRequest.getQueryString()); } } hostConfiguration.setHost(new URI(url.toString(), true)); // SoapUI.log("PROXY to:" + url); monitor.fireBeforeProxy(request, response, method, hostConfiguration); if (settings.getBoolean(LaunchForm.SSLTUNNEL_REUSESTATE)) { if (httpState == null) httpState = new HttpState(); HttpClientSupport.getHttpClient().executeMethod(hostConfiguration, method, httpState); } else { HttpClientSupport.getHttpClient().executeMethod(hostConfiguration, method); } // wait for transaction to end and store it. capturedData.stopCapture(); capturedData.setRequest(capture.getCapturedData()); capturedData.setRawResponseBody(method.getResponseBody()); capturedData.setResponseHeader(method); capturedData.setRawRequestData(getRequestToBytes(request.toString(), method, capture)); capturedData.setRawResponseData( getResponseToBytes(response.toString(), method, capturedData.getRawResponseBody())); capturedData.setResponseContent(new String(method.getDecompressedResponseBody())); monitor.fireAfterProxy(request, response, method, capturedData); if (!response.isCommitted()) { StringToStringsMap responseHeaders = capturedData.getResponseHeaders(); // capturedData = null; // 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()); } synchronized (this) { if (checkContentType(method)) { monitor.addMessageExchange(capturedData); } } }
From source file:edu.internet2.middleware.shibboleth.idp.profile.saml2.SLOProfileHandler.java
/** * Creates Http connection./*from www .j a v a 2s . co m*/ * * @param serviceLogoutInfo * @param endpoint * @return * @throws URIException * @throws GeneralSecurityException * @throws IOException */ private HttpConnection createHttpConnection(LogoutInformation serviceLogoutInfo, Endpoint endpoint) throws URIException, GeneralSecurityException, IOException { HttpClientBuilder httpClientBuilder = new HttpClientBuilder(); httpClientBuilder.setContentCharSet("UTF-8"); SecureProtocolSocketFactory sf = new EasySSLProtocolSocketFactory(); httpClientBuilder.setHttpsProtocolSocketFactory(sf); //build http connection HttpClient httpClient = httpClientBuilder.buildClient(); HostConfiguration hostConfig = new HostConfiguration(); URI location = new URI(endpoint.getLocation()); hostConfig.setHost(location); LogoutRequestConfiguration config = (LogoutRequestConfiguration) getProfileConfiguration( serviceLogoutInfo.getEntityID(), getProfileId()); if (log.isDebugEnabled()) { log.debug("Creating new HTTP connection with the following timeouts:"); log.debug("Maximum waiting time for the connection pool is {}", config.getBackChannelConnectionPoolTimeout()); log.debug("Timeout for connection establishment is {}", config.getBackChannelConnectionTimeout()); log.debug("Timeout for soap response is {}", config.getBackChannelResponseTimeout()); } HttpConnection httpConn = null; try { httpConn = httpClient.getHttpConnectionManager().getConnectionWithTimeout(hostConfig, config.getBackChannelConnectionPoolTimeout()); } catch (ConnectionPoolTimeoutException e) { return null; } HttpConnectionParams params = new HttpConnectionParams(); params.setConnectionTimeout(config.getBackChannelConnectionTimeout()); params.setSoTimeout(config.getBackChannelResponseTimeout()); httpConn.setParams(params); return httpConn; }
From source file:com.liferay.portal.util.HttpImpl.java
public HostConfiguration getHostConfiguration(String location) throws IOException { if (_log.isDebugEnabled()) { _log.debug("Location is " + location); }//from www .j ava 2 s . co m 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:com.idega.slide.business.IWSlideServiceBean.java
@SuppressWarnings("deprecation") private HttpClient getHttpClient(HttpURL url, UsernamePasswordCredentials credentials) throws Exception { HttpSession currentSession = getCurrentSession(); HttpState state = new WebdavState(); AuthScope authScope = new AuthScope(url.getHost(), url.getPort()); state.setCredentials(authScope, credentials); if (currentSession != null) { IWTimestamp iwExpires = new IWTimestamp(System.currentTimeMillis()); iwExpires.setMinute(iwExpires.getMinute() + 30); Date expires = new Date(iwExpires.getTimestamp().getTime()); boolean secure = url instanceof HttpsURL; Cookie cookie = new Cookie(url.getHost(), CoreConstants.PARAMETER_SESSION_ID, currentSession.getId(), CoreConstants.SLASH, expires, secure); state.addCookie(cookie);// ww w . j av a 2 s . c o m } HttpClient client = new HttpClient(new MultiThreadedHttpConnectionManager()); client.setState(state); HostConfiguration hostConfig = client.getHostConfiguration(); hostConfig.setHost(url); Credentials hostCredentials = null; if (credentials == null) { String userName = url.getUser(); if (userName != null && userName.length() > 0) { hostCredentials = new UsernamePasswordCredentials(userName, url.getPassword()); } } if (hostCredentials != null) { HttpState clientState = client.getState(); clientState.setCredentials(null, url.getHost(), hostCredentials); clientState.setAuthenticationPreemptive(true); } return client; }
From source file:ome.formats.importer.util.HtmlMessenger.java
/** * Instantiate html messenger//from w w w .ja va2s . co m * * @param url * @param postList - variables list in post * @throws HtmlMessengerException */ public HtmlMessenger(String url, List<Part> postList) throws HtmlMessengerException { try { HostConfiguration cfg = new HostConfiguration(); cfg.setHost(url); String proxyHost = System.getProperty(PROXY_HOST); String proxyPort = System.getProperty(PROXY_PORT); if (proxyHost != null && proxyPort != null) { int port = Integer.parseInt(proxyPort); cfg.setProxy(proxyHost, port); } client = new HttpClient(); client.setHostConfiguration(cfg); HttpClientParams params = new HttpClientParams(); params.setConnectionManagerTimeout(CONN_TIMEOUT); params.setSoTimeout(CONN_TIMEOUT); client.setParams(params); method = new PostMethod(url); Part[] parts = new Part[postList.size()]; int i = 0; for (Part part : postList) { parts[i] = part; i++; } MultipartRequestEntity mpre = new MultipartRequestEntity(parts, method.getParams()); ProgressListener listener = new ProgressListener() { /* (non-Javadoc) * @see ome.formats.importer.util.FileUploadCounter.ProgressListener#update(long) */ public void update(long bytesRead) { } }; FileUploadCounter hfre = new FileUploadCounter(mpre, listener); method.setRequestEntity(hfre); } catch (Exception e) { e.printStackTrace(); throw new HtmlMessengerException("Error creating post parameters", e); } }
From source file:org.apache.cocoon.generation.HttpProxyGenerator.java
/** * Setup this <code>Generator</code> with its runtime configurations and parameters * specified in the sitemap, and prepare it for generation. * * @param sourceResolver The <code>SourceResolver</code> instance resolving sources by * system identifiers. * @param objectModel The Cocoon "object model" <code>Map</code> * @param parameters The runtime <code>Parameters</code> instance. * @throws ProcessingException If this instance could not be setup. * @throws SAXException If a SAX error occurred during setup. * @throws IOException If an I/O error occurred during setup. * @see #recycle()//from w ww. j a v a 2s. c o m */ public void setup(SourceResolver sourceResolver, Map objectModel, String source, Parameters parameters) throws ProcessingException, SAXException, IOException { /* Do the usual stuff */ super.setup(sourceResolver, objectModel, source, parameters); /* * Parameter handling: In case the method is a POST method, query * parameters and request parameters will be two different arrays * (one for the body, one for the query string, otherwise it's going * to be the same one, as all parameters are passed on the query string */ ArrayList req = new ArrayList(); ArrayList qry = req; if (this.method instanceof PostMethod) qry = new ArrayList(); req.addAll(this.reqParams); qry.addAll(this.qryParams); /* * Parameter handling: complete or override the configured parameters with * those specified in the pipeline. */ String names[] = parameters.getNames(); for (int x = 0; x < names.length; x++) { String name = names[x]; String value = parameters.getParameter(name, null); if (value == null) continue; if (name.startsWith("query:")) { name = name.substring("query:".length()); qry.add(new NameValuePair(name, value)); } else if (name.startsWith("param:")) { name = name.substring("param:".length()); req.add(new NameValuePair(name, value)); } else if (name.startsWith("query-override:")) { name = name.substring("query-override:".length()); qry = overrideParams(qry, name, value); } else if (name.startsWith("param-override:")) { name = name.substring("param-override:".length()); req = overrideParams(req, name, value); } } /* Process the current source URL in relation to the configured one */ HttpURL src = (super.source == null ? null : new HttpURL(super.source)); if (this.url != null) src = (src == null ? this.url : new HttpURL(this.url, src)); if (src == null) throw new ProcessingException("No URL specified"); if (src.isRelativeURI()) { throw new ProcessingException("Invalid URL \"" + src.toString() + "\""); } /* Configure the method with the resolved URL */ HostConfiguration hc = new HostConfiguration(); hc.setHost(src); this.method.setHostConfiguration(hc); this.method.setPath(src.getPath()); this.method.setQueryString(src.getQuery()); /* And now process the query string (from the parameters above) */ if (qry.size() > 0) { String qs = this.method.getQueryString(); NameValuePair nvpa[] = new NameValuePair[qry.size()]; this.method.setQueryString((NameValuePair[]) qry.toArray(nvpa)); if (qs != null) { this.method.setQueryString(qs + "&" + this.method.getQueryString()); } } /* Finally process the body parameters */ if ((this.method instanceof PostMethod) && (req.size() > 0)) { PostMethod post = (PostMethod) this.method; NameValuePair nvpa[] = new NameValuePair[req.size()]; post.setRequestBody((NameValuePair[]) req.toArray(nvpa)); } /* Check the debugging flag */ this.debug = parameters.getParameterAsBoolean("debug", false); }
From source file:org.apache.cocoon.generation.WebServiceProxyGenerator.java
/** * Create one per client session. //from w w w .ja v a2 s .c o m */ protected HttpClient getHttpClient() throws ProcessingException { URI uri = null; String host = null; Request request = ObjectModelHelper.getRequest(objectModel); Session session = request.getSession(true); HttpClient httpClient = null; if (session != null) { httpClient = (HttpClient) session.getAttribute(HTTP_CLIENT); } if (httpClient == null) { httpClient = new HttpClient(); HostConfiguration config = httpClient.getHostConfiguration(); if (config == null) { config = new HostConfiguration(); } /* TODO: fixme! * When the specified source sent to the wsproxy is not "http" * (e.g. "cocoon:/"), the HttpClient throws an exception. Does the source * here need to be resolved before being set in the HostConfiguration? */ try { uri = new URI(this.source); host = uri.getHost(); config.setHost(uri); } catch (URIException ex) { throw new ProcessingException("URI format error: " + ex, ex); } // Check the http.nonProxyHosts to see whether or not the current // host needs to be served through the proxy server. boolean proxiableHost = true; String nonProxyHosts = System.getProperty("http.nonProxyHosts"); if (nonProxyHosts != null) { StringTokenizer tok = new StringTokenizer(nonProxyHosts, "|"); while (tok.hasMoreTokens()) { String nonProxiableHost = tok.nextToken().trim(); // XXX is there any other characters that need to be // escaped? nonProxiableHost = StringUtils.replace(nonProxiableHost, ".", "\\."); nonProxiableHost = StringUtils.replace(nonProxiableHost, "*", ".*"); // XXX do we want .example.com to match // computer.example.com? it seems to be a very common // idiom for the nonProxyHosts, in that case then we want // to change "^" to "^.*" RE re = null; try { re = new RE("^" + nonProxiableHost + "$"); } catch (Exception ex) { throw new ProcessingException("Regex syntax error: " + ex, ex); } if (re.match(host)) { proxiableHost = false; break; } } } if (proxiableHost && System.getProperty("http.proxyHost") != null) { String proxyHost = System.getProperty("http.proxyHost"); int proxyPort = Integer.parseInt(System.getProperty("http.proxyPort")); config.setProxy(proxyHost, proxyPort); } httpClient.setHostConfiguration(config); session.setAttribute(HTTP_CLIENT, httpClient); } return httpClient; }
From source file:org.apache.maven.wagon.providers.webdav.AbstractHttpClientWagon.java
public void openConnectionInternal() { repository.setUrl(getURL(repository)); client = new HttpClient(connectionManager); // WAGON-273: default the cookie-policy to browser compatible client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY); String username = null;//from w w w . ja va 2s . c o m String password = null; String domain = null; if (authenticationInfo != null) { username = authenticationInfo.getUserName(); if (StringUtils.contains(username, "\\")) { String[] domainAndUsername = username.split("\\\\"); domain = domainAndUsername[0]; username = domainAndUsername[1]; } password = authenticationInfo.getPassword(); } String host = getRepository().getHost(); if (StringUtils.isNotEmpty(username) && StringUtils.isNotEmpty(password)) { Credentials creds; if (domain != null) { creds = new NTCredentials(username, password, host, domain); } else { creds = new UsernamePasswordCredentials(username, password); } int port = getRepository().getPort() > -1 ? getRepository().getPort() : AuthScope.ANY_PORT; AuthScope scope = new AuthScope(host, port); client.getState().setCredentials(scope, creds); } HostConfiguration hc = new HostConfiguration(); ProxyInfo proxyInfo = getProxyInfo(getRepository().getProtocol(), getRepository().getHost()); if (proxyInfo != null) { String proxyUsername = proxyInfo.getUserName(); String proxyPassword = proxyInfo.getPassword(); String proxyHost = proxyInfo.getHost(); int proxyPort = proxyInfo.getPort(); String proxyNtlmHost = proxyInfo.getNtlmHost(); String proxyNtlmDomain = proxyInfo.getNtlmDomain(); if (proxyHost != null) { hc.setProxy(proxyHost, proxyPort); if (proxyUsername != null && proxyPassword != null) { Credentials creds; if (proxyNtlmHost != null || proxyNtlmDomain != null) { creds = new NTCredentials(proxyUsername, proxyPassword, proxyNtlmHost, proxyNtlmDomain); } else { creds = new UsernamePasswordCredentials(proxyUsername, proxyPassword); } int port = proxyInfo.getPort() > -1 ? proxyInfo.getPort() : AuthScope.ANY_PORT; AuthScope scope = new AuthScope(proxyHost, port); client.getState().setProxyCredentials(scope, creds); } } } hc.setHost(host); //start a session with the webserver client.setHostConfiguration(hc); }
From source file:org.apache.maven.wagon.shared.http.AbstractHttpClientWagon.java
public void openConnectionInternal() { repository.setUrl(getURL(repository)); client = new HttpClient(connectionManager); String username = null;/*from w w w .j a va 2 s .c o m*/ String password = null; if (authenticationInfo != null) { username = authenticationInfo.getUserName(); password = authenticationInfo.getPassword(); } String host = getRepository().getHost(); if (StringUtils.isNotEmpty(username) && StringUtils.isNotEmpty(password)) { Credentials creds = new UsernamePasswordCredentials(username, password); int port = getRepository().getPort() > -1 ? getRepository().getPort() : AuthScope.ANY_PORT; AuthScope scope = new AuthScope(host, port); client.getState().setCredentials(scope, creds); } HostConfiguration hc = new HostConfiguration(); ProxyInfo proxyInfo = getProxyInfo(getRepository().getProtocol(), getRepository().getHost()); if (proxyInfo != null) { String proxyUsername = proxyInfo.getUserName(); String proxyPassword = proxyInfo.getPassword(); String proxyHost = proxyInfo.getHost(); int proxyPort = proxyInfo.getPort(); String proxyNtlmHost = proxyInfo.getNtlmHost(); String proxyNtlmDomain = proxyInfo.getNtlmDomain(); if (proxyHost != null) { hc.setProxy(proxyHost, proxyPort); if (proxyUsername != null && proxyPassword != null) { Credentials creds; if (proxyNtlmHost != null || proxyNtlmDomain != null) { creds = new NTCredentials(proxyUsername, proxyPassword, proxyNtlmHost, proxyNtlmDomain); } else { creds = new UsernamePasswordCredentials(proxyUsername, proxyPassword); } int port = proxyInfo.getPort() > -1 ? proxyInfo.getPort() : AuthScope.ANY_PORT; AuthScope scope = new AuthScope(proxyHost, port); client.getState().setProxyCredentials(scope, creds); } } } hc.setHost(host); //start a session with the webserver client.setHostConfiguration(hc); }