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

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

Introduction

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

Prototype

public int getPort() 

Source Link

Document

Returns the port of the host.

Usage

From source file:com.navercorp.pinpoint.plugin.httpclient3.HttpClient3RequestWrapper.java

public static int getPort(final HttpConnection httpConnection) {
    if (httpConnection == null) {
        return SKIP_DEFAULT_PORT;
    }/*  w  w  w .  j a v a2 s .  c  o m*/
    final int port = httpConnection.getPort();
    final Protocol protocol = httpConnection.getProtocol();
    // if port is default port number.
    if (protocol != null && port == protocol.getDefaultPort()) {
        // skip
        return SKIP_DEFAULT_PORT;
    }
    return port;
}

From source file:com.navercorp.pinpoint.plugin.httpclient3.HttpClient3RequestTrace.java

private static int getPort(final HttpConnection httpConnection) {
    if (httpConnection == null) {
        return SKIP_DEFAULT_PORT;
    }/*from   w  w  w. j  av a 2 s  .  co m*/
    final int port = httpConnection.getPort();
    final Protocol protocol = httpConnection.getProtocol();
    // if port is default port number.
    if (protocol != null && port == protocol.getDefaultPort()) {
        // skip
        return SKIP_DEFAULT_PORT;
    }
    return port;
}

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

/**
 * Gets the host configuration for a connection.
 * @param conn the connection to get the configuration of
 * @return a new HostConfiguration//from w  w w .  j  a v a 2 s.  c o  m
 */
static HostConfiguration rebuildConfigurationFromConnection(HttpConnection conn) {
    HostConfiguration connectionConfiguration = new HostConfiguration();
    connectionConfiguration.setHost(conn.getHost(), conn.getPort(), conn.getProtocol());
    if (conn.getLocalAddress() != null) {
        connectionConfiguration.setLocalAddress(conn.getLocalAddress());
    }
    if (conn.getProxyHost() != null) {
        connectionConfiguration.setProxy(conn.getProxyHost(), conn.getProxyPort());
    }
    return connectionConfiguration;
}

From source file:edu.utah.further.core.ws.HttpResponseTo.java

/**
 * Generates HTTP request line according to the specified attributes.
 * /*from   w  w w . j a va 2  s.  c  o  m*/
 * @param connection
 *            the {@link HttpConnection connection} used to execute this HTTP method
 * @param name
 *            the method name generate a request for
 * @param requestPath
 *            the path string for the request
 * @param query
 *            the query string for the request
 * @param version
 *            the protocol version to use (e.g. HTTP/1.0)
 * 
 * @return HTTP request line
 */
protected static String generateRequestLine(final HttpConnection connection, final String name,
        final String requestPath, final String query, final String version) {
    final StringBuffer buf = new StringBuffer();
    // Append method name
    buf.append(name).append(Strings.SPACE_STRING);
    // Absolute or relative URL?
    if (!connection.isTransparent()) {
        final Protocol protocol = connection.getProtocol();
        buf.append(protocol.getScheme().toLowerCase());
        buf.append("://");
        buf.append(connection.getHost());
        if ((connection.getPort() != -1) && (connection.getPort() != protocol.getDefaultPort())) {
            buf.append(":");
            buf.append(connection.getPort());
        }
    }
    // Append path, if any
    if (requestPath == null) {
        buf.append("/");
    } else {
        if (!connection.isTransparent() && !requestPath.startsWith("/")) {
            buf.append("/");
        }
        buf.append(requestPath);
    }
    // Append query, if any
    if (query != null) {
        if (query.indexOf("?") != 0) {
            buf.append("?");
        }
        buf.append(query);
    }
    // Append protocol
    buf.append(Strings.SPACE_STRING).append(version).append(Strings.UNIX_NEW_LINE_STRING);
    return buf.toString();
}

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

/**
 * Creates a new HttpConnectionAdapter.//from w w w  . ja  v  a 2 s .co  m
 * @param connection the connection to be wrapped
 */
public HttpConnectionAdapter(HttpConnection connection) {
    super(connection.getHost(), connection.getPort(), connection.getProtocol());
    this.wrappedConnection = connection;
}

From source file:org.apache.webdav.lib.methods.MoveMethod.java

/**
 * A client of the {@link MoveMethod} can specify a destination as either an
 * absolute URL (possibly to a different server), or as a absolute path on
 * the same server, but this function makes sure that the path sent to the
 * server is always an absolute URL.//  www.j  av  a  2s . co m
 *
 * <p>Note that this function will add server and port to the request -
 * however, port is not added if it is the default port for the scheme
 * in question. </p>
 *
 * <p>This function is static so that it can be reused by the {@link CopyMethod}.
 * </p>
 *
 * @param conn  The connection for the current request, in case the caller
 *  specifies an absolute path.
 *
 * @param absolutePathOrURL If an absolute URL, nothing done, but if an absolute
 *  path, it is converted into an absolute URL.
 *
 * @return An absolute URL
 */
static String getAbsoluteDestination(HttpConnection conn, String absolutePathOrURL) {

    String absoluteDestination = absolutePathOrURL;

    // is this an absolute path?
    if (absolutePathOrURL.startsWith("/")) {

        // yes - get the protocol to start the URL with the appropriate scheme.
        Protocol protocol = conn.getProtocol();
        StringBuffer bufDest = new StringBuffer(protocol.getScheme());
        bufDest.append("://").append(conn.getHost());

        // only add in the port if it is not the default port.
        if (conn.getPort() != protocol.getDefaultPort()) {
            bufDest.append(':').append(conn.getPort());
        }

        // append the path.
        bufDest.append(absolutePathOrURL);
        absoluteDestination = bufDest.toString();
    }
    return absoluteDestination;
}