Example usage for org.apache.commons.httpclient HttpConnection HttpConnection

List of usage examples for org.apache.commons.httpclient HttpConnection HttpConnection

Introduction

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

Prototype

public HttpConnection(HostConfiguration hostConfiguration) 

Source Link

Document

Creates a new HTTP connection for the given host configuration.

Usage

From source file:com.carrotsearch.util.httpclient.SingleHttpConnectionManager.java

/** */
@Override// ww  w.  ja v a2 s . c  om
public HttpConnection getConnectionWithTimeout(HostConfiguration hostConfiguration, long timeout) {
    final HttpConnection conn = new HttpConnection(hostConfiguration);
    conn.setHttpConnectionManager(this);
    conn.getParams().setDefaults(this.getParams());
    conn.getParams().setSoTimeout((int) timeout);
    return conn;
}

From source file:com.cyberway.issue.httpclient.SingleHttpConnectionManager.java

public HttpConnection getConnectionWithTimeout(HostConfiguration hostConfiguration, long timeout) {

    HttpConnection conn = new HttpConnection(hostConfiguration);
    conn.setHttpConnectionManager(this);
    conn.getParams().setDefaults(this.getParams());
    return conn;//w w w  .  j  a v a  2s .  c  om
}

From source file:com.exalead.io.failover.HostState.java

MonitoredConnection connect(int timeout) throws IOException {
    MonitoredConnection newConn = new MonitoredConnection();
    newConn.host = this;
    newConn.conn = new HttpConnection(configuration);
    newConn.conn.getParams().setConnectionTimeout(timeout);
    newConn.conn.open();/*from   www  .java  2 s  .c o  m*/
    newConn.lastMonitoringTime = System.currentTimeMillis();
    return newConn;
}

From source file:com.cyberway.issue.httpclient.ThreadLocalHttpConnectionManager.java

/**
 * @see HttpConnectionManager#getConnectionWithTimeout(HostConfiguration, long)
 * //w w w.  j ava  2  s  . c o  m
 * @since 3.0
 */
public HttpConnection getConnectionWithTimeout(final HostConfiguration hostConfiguration, final long timeout) {

    final ConnectionInfo ci = getConnectionInfo();
    HttpConnection httpConnection = ci.conn;

    // make sure the host and proxy are correct for this connection
    // close it and set the values if they are not
    if (httpConnection == null || !finishLastResponse(httpConnection)
            || !hostConfiguration.hostEquals(httpConnection)
            || !hostConfiguration.proxyEquals(httpConnection)) {

        if (httpConnection != null && httpConnection.isOpen()) {
            closer.closeConnection(httpConnection);
        }

        httpConnection = new HttpConnection(hostConfiguration);
        httpConnection.setHttpConnectionManager(this);
        httpConnection.getParams().setDefaults(this.params);
        ci.conn = httpConnection;

        httpConnection.setHost(hostConfiguration.getHost());
        httpConnection.setPort(hostConfiguration.getPort());
        httpConnection.setProtocol(hostConfiguration.getProtocol());
        httpConnection.setLocalAddress(hostConfiguration.getLocalAddress());

        httpConnection.setProxyHost(hostConfiguration.getProxyHost());
        httpConnection.setProxyPort(hostConfiguration.getProxyPort());
    }

    // remove the connection from the timeout handler
    ci.idleStartTime = Long.MAX_VALUE;

    return httpConnection;
}

From source file:org.apache.cocoon.generation.HttpProxyGenerator.java

/**
 * Parse the remote <code>InputStream</code> accessed over HTTP.
 *
 * @throws ResourceNotFoundException If the remote HTTP resource could not be found.
 * @throws ProcessingException If an error occurred processing generation.
 * @throws SAXException If an error occurred parsing or processing XML in the pipeline.
 * @throws IOException If an I/O error occurred accessing the HTTP server.
 *//*from w  ww.j a  va 2 s.  com*/
public void generate() throws ResourceNotFoundException, ProcessingException, SAXException, IOException {
    /* Do the boring stuff in case we have to do a debug output (blablabla) */
    if (this.debug) {
        this.generateDebugOutput();
        return;
    }

    /* Call up the remote HTTP server */
    HttpConnection connection = new HttpConnection(this.method.getHostConfiguration());
    HttpState state = new HttpState();
    this.method.setFollowRedirects(true);
    int status = this.method.execute(state, connection);
    if (status == 404) {
        throw new ResourceNotFoundException(
                "Unable to access \"" + this.method.getURI() + "\" (HTTP 404 Error)");
    } else if ((status < 200) || (status > 299)) {
        throw new IOException("Unable to access HTTP resource at \"" + this.method.getURI().toString()
                + "\" (status=" + status + ")");
    }
    InputStream response = this.method.getResponseBodyAsStream();

    /* Let's try to set up our InputSource from the response output stream and to parse it */
    SAXParser parser = null;
    try {
        InputSource inputSource = new InputSource(response);
        parser = (SAXParser) this.manager.lookup(SAXParser.ROLE);
        parser.parse(inputSource, super.xmlConsumer);
    } catch (ServiceException ex) {
        throw new ProcessingException("Unable to get parser", ex);
    } finally {
        this.manager.release(parser);
        this.method.releaseConnection();
        connection.close();
    }
}

From source file:org.woodwardbernsteinprotocol.protocol.DirectTransfer.java

@Override
public void transmit(Tip tip) throws IOException {
    ByteArrayOutputStream data = new ByteArrayOutputStream();
    Base64OutputStream stream = new Base64OutputStream(data);
    tip.transmit(stream);//from www  .j  a  v a2 s .c om
    InputStream writer = new ByteArrayInputStream(data.toByteArray());
    HttpConnection client = new HttpConnection(config);
    client.open();
    byte[] buffer = new byte[10240];
    int read = 0;
    byte[] start = new byte[] { 't', 'i', 'p', '=' };
    client.write(start);
    while ((read = writer.read(buffer, 0, 10240)) > 0) {
        client.write(buffer, 0, read);
    }
    client.close();
}