List of usage examples for org.apache.commons.httpclient HostConfiguration HostConfiguration
public HostConfiguration()
From source file:xtremweb.communications.HTTPClient.java
/** * This does nothing; everything is done in write() * * @throws IOException// w w w. ja v a2 s.co m * @see #write(XMLRPCCommand) */ @Override protected void open(URI uri) throws UnknownHostException, NoRouteToHostException, SSLHandshakeException, SocketTimeoutException, IOException { try { String serverName = XWTools.getHostName(uri.getHost()); int serverPort = uri.getPort(); httpClient = new HttpClient(new MultiThreadedHttpConnectionManager()); Protocol xwssl = null; final XWConfigurator config = getConfig(); final KeyStore keyStore = config.getKeyStore(); if (keyStore != null) { if (serverPort == -1) { serverPort = config.getPort(Connection.HTTPSPORT); } xwssl = new Protocol(uri.getScheme(), new AuthSSLProtocolSocketFactory(uri.getScheme(), keyStore, config.getProperty(XWPropertyDefs.SSLKEYPASSWORD)), serverPort); Protocol.registerProtocol(uri.getScheme(), xwssl); } else { getLogger().warn("unsecured communications : not using SSL"); if (serverPort == -1) { serverPort = config.getPort(Connection.HTTPPORT); } } final String proxyName = config.getProperty(XWPropertyDefs.PROXYSERVER); if ((proxyName != null) && (proxyName.trim().length() > 0)) { serverName = XWTools.getHostName(proxyName); } final String porttxt = config.getProperty(XWPropertyDefs.PROXYPORT); if ((porttxt != null) && (porttxt.trim().length() > 0)) { final int proxyPort = config.getPort(Connection.PROXYPORT); if (proxyPort > 0) { serverPort = proxyPort; } } URI uri2 = null; try { final StringBuilder struri2 = new StringBuilder( uri.getScheme() + Connection.getSchemeSeparator() + serverName); if (serverPort > 0) { struri2.append(":" + serverPort); } if (uri.getPath() != null) { struri2.append("/" + uri.getPath()); } uri2 = new URI(struri2.toString()); } catch (final Exception e) { uri2 = uri; } uri = uri2; uri2 = null; mileStone("<open uri=\"" + uri + "\">"); httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(30000); final HostConfiguration hConfig = new HostConfiguration(); if (xwssl == null) { hConfig.setHost(serverName, serverPort); } else { hConfig.setHost(serverName, serverPort, xwssl); } httpClient.setHostConfiguration(hConfig); nio = false; if (config.getBoolean(XWPropertyDefs.OPTIMIZENETWORK) && (OSEnum.getOs().isMacosx() == false)) { final HttpConnectionManagerParams params = httpClient.getHttpConnectionManager().getParams(); params.setLinger(0); // don't wait on close params.setTcpNoDelay(true); // don't wait to send } final HttpConnection connection = httpClient.getHttpConnectionManager() .getConnection(httpClient.getHostConfiguration()); connection.open(); } catch (final Exception e) { getLogger().exception(e); mileStone("<error method='open' msg='" + e.getMessage() + "' />"); throw new IOException("HTTPClient : open failed " + e.toString()); } finally { mileStone("</open>"); } }