Example usage for org.apache.commons.httpclient HostConfiguration setHost

List of usage examples for org.apache.commons.httpclient HostConfiguration setHost

Introduction

In this page you can find the example usage for org.apache.commons.httpclient HostConfiguration setHost.

Prototype

public void setHost(String paramString, int paramInt)

Source Link

Usage

From source file:org.nuxeo.ecm.webdav.JackrabbitWebdavClientTest.java

@BeforeClass
public static void setUp() {
    // Setup code
    HostConfiguration hostConfig = new HostConfiguration();
    hostConfig.setHost("localhost", PORT);

    HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    int maxHostConnections = 20;
    params.setMaxConnectionsPerHost(hostConfig, maxHostConnections);
    connectionManager.setParams(params);

    client = new HttpClient(connectionManager);
    client.setHostConfiguration(hostConfig);

    Credentials creds = new UsernamePasswordCredentials("userId", "pw");
    client.getState().setCredentials(AuthScope.ANY, creds);
}

From source file:org.nuxeo.ecm.webdav.ParallelBench.java

private HttpClient createClient() {
    HostConfiguration hostConfig = new HostConfiguration();
    hostConfig.setHost("localhost", PORT);

    // HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    HttpConnectionManager connectionManager = new SimpleHttpConnectionManager(true);
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setMaxConnectionsPerHost(hostConfig, 10);
    connectionManager.setParams(params);

    HttpClient client = new HttpClient(connectionManager);
    client.setHostConfiguration(hostConfig);

    Credentials creds = new UsernamePasswordCredentials(LOGIN, PASSWD);
    client.getState().setCredentials(AuthScope.ANY, creds);

    return client;
}

From source file:org.nuxeo.ecm.webdav.WebDavClientTest.java

protected static HttpClient createClient(String username, String password) {
    HostConfiguration hostConfig = new HostConfiguration();
    hostConfig.setHost("localhost", WebDavServerFeature.PORT);

    HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    int maxHostConnections = 20;
    params.setMaxConnectionsPerHost(hostConfig, maxHostConnections);
    connectionManager.setParams(params);

    HttpClient httpClient = new HttpClient(connectionManager);
    httpClient.setHostConfiguration(hostConfig);

    Credentials creds = new UsernamePasswordCredentials(username, password);
    httpClient.getState().setCredentials(AuthScope.ANY, creds);
    httpClient.getParams().setAuthenticationPreemptive(true);
    return httpClient;
}

From source file:org.seasr.meandre.components.tools.tapor.restservice.Concordance.java

@Override
public void executeCallBack(ComponentContext cc) throws Exception {
    String htmlTag = cc.getProperty(PROP_HTML_TAG);
    String pattern = cc.getProperty(PROP_PATTERN);
    String context = cc.getProperty(PROP_CONTEXT);
    String contextLen = cc.getProperty(PROP_CONTEXT_LENGTH);
    String outFormat = cc.getProperty(PROP_OUT_FORMAT);

    String htmlInput = DataTypeParser.parseAsString(cc.getDataComponentFromInput(IN_TEXT))[0];

    try {//from   w w w.j av a 2s  .c om
        URL url = new URL(serviceLoc);

        HostConfiguration hostConfig = new HostConfiguration();
        hostConfig.setHost(url.getHost(), url.getPort());
        HttpClient httpClient = new HttpClient(new SimpleHttpConnectionManager());
        httpClient.setHostConfiguration(hostConfig);
        PostMethod postMethod = new PostMethod(serviceLoc);

        postMethod.addParameter("htmlInput", htmlInput);
        postMethod.addParameter("htmlTag", htmlTag);
        ;
        postMethod.addParameter("pattern", pattern);
        postMethod.addParameter("context", context);
        postMethod.addParameter("contextlength", contextLen);
        postMethod.addParameter("outFormat", outFormat);

        httpClient.executeMethod(postMethod);

        BufferedReader in = new BufferedReader(new InputStreamReader(postMethod.getResponseBodyAsStream()));
        String line = null;
        StringBuffer buf = new StringBuffer();
        while ((line = in.readLine()) != null)
            buf.append(line).append("\n");

        in.close();

        cc.pushDataComponentToOutput(OUT_TEXT, BasicDataTypesTools.stringToStrings(buf.toString()));

    } catch (Exception e) {
        throw new ComponentExecutionException(e);
    }
}

From source file:org.seasr.meandre.components.tools.tapor.restservice.ListWords.java

@Override
public void executeCallBack(ComponentContext cc) throws Exception {
    String htmlInput = DataTypeParser.parseAsString(cc.getDataComponentFromInput(IN_TEXT))[0];

    URL url = new URL(serviceLoc);

    HostConfiguration hostConfig = new HostConfiguration();
    hostConfig.setHost(url.getHost(), url.getPort());
    HttpClient httpClient = new HttpClient(new SimpleHttpConnectionManager());
    httpClient.setHostConfiguration(hostConfig);
    PostMethod postMethod = new PostMethod(serviceLoc);

    postMethod.addParameter("htmlInput", htmlInput);
    postMethod.addParameter("htmlTag", htmlTag);
    postMethod.addParameter("listOption", listOption);
    postMethod.addParameter("optionSelection", optionSelection);
    postMethod.addParameter("sorting", sorting);
    postMethod.addParameter("outFormat", outFormat);

    httpClient.executeMethod(postMethod);

    BufferedReader in = new BufferedReader(new InputStreamReader(postMethod.getResponseBodyAsStream()));
    String line = null;/*  www  .  j  a  va  2s .c o  m*/
    boolean firstLine = true;
    StringBuilder buf = new StringBuilder();

    while ((line = in.readLine()) != null) {
        if (firstLine && line.startsWith("<pre>")) {
            line = line.substring(5);
            firstLine = false;
        } else if (line.trim().equals("</pre>"))
            continue;

        buf.append(line).append("\n");
    }

    in.close();

    cc.pushDataComponentToOutput(OUT_TEXT, BasicDataTypesTools.stringToStrings(buf.toString()));
}

From source file:xtremweb.communications.HTTPClient.java

/**
 * This does nothing; everything is done in write()
 *
 * @throws IOException//from   w ww  .j  a v  a 2  s.  c om
 * @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>");
    }
}