Example usage for org.apache.commons.httpclient.protocol Protocol getDefaultPort

List of usage examples for org.apache.commons.httpclient.protocol Protocol getDefaultPort

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.protocol Protocol getDefaultPort.

Prototype

public int getDefaultPort() 

Source Link

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;
    }//from w  w  w .j a v  a  2  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;
    }/*  www .  j a v a 2s . 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:edu.utah.further.core.ws.HttpResponseTo.java

/**
 * Generates HTTP request line according to the specified attributes.
 * /*from  w w w . j  a v  a2  s . c  om*/
 * @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:flex.messaging.services.http.HTTPProxyAdapter.java

private void initHttpConnectionManagerParams(HTTPConnectionManagerSettings settings) {
    connectionParams = new HttpConnectionManagerParams();
    connectionParams.setMaxTotalConnections(settings.getMaxTotalConnections());
    connectionParams.setDefaultMaxConnectionsPerHost(settings.getDefaultMaxConnectionsPerHost());

    if (!settings.getCookiePolicy().equals(CookiePolicy.DEFAULT)) {
        HttpClientParams httpClientParams = (HttpClientParams) connectionParams.getDefaults();
        httpClientParams.setCookiePolicy(settings.getCookiePolicy());
    }//from w w w. ja  v  a 2 s.c o m

    if (settings.getConnectionTimeout() >= 0)
        connectionParams.setConnectionTimeout(settings.getConnectionTimeout());

    if (settings.getSocketTimeout() >= 0)
        connectionParams.setSoTimeout(settings.getSocketTimeout());

    connectionParams.setStaleCheckingEnabled(settings.isStaleCheckingEnabled());

    if (settings.getSendBufferSize() > 0)
        connectionParams.setSendBufferSize(settings.getSendBufferSize());

    if (settings.getReceiveBufferSize() > 0)
        connectionParams.setReceiveBufferSize(settings.getReceiveBufferSize());

    connectionParams.setTcpNoDelay(settings.isTcpNoDelay());
    connectionParams.setLinger(settings.getLinger());

    if (settings.getMaxConnectionsPerHost() != null) {
        Iterator it = settings.getMaxConnectionsPerHost().iterator();
        while (it.hasNext()) {
            HostConfigurationSettings hcs = (HostConfigurationSettings) it.next();
            HostConfiguration hostConfig = new HostConfiguration();

            if (hcs.getProtocol() != null) {
                Protocol protocol = Protocol.getProtocol(hcs.getProtocol());
                hostConfig.setHost(hcs.getHost(), hcs.getPort(), protocol);
            } else if (hcs.getProtocolFactory() != null) {
                Protocol protocol = hcs.getProtocolFactory().getProtocol();
                if (hcs.getPort() > 0)
                    hostConfig.setHost(hcs.getHost(), hcs.getPort(), protocol);
                else
                    hostConfig.setHost(hcs.getHost(), protocol.getDefaultPort(), protocol);
            } else {
                if (hcs.getPort() > 0)
                    hostConfig.setHost(hcs.getHost(), hcs.getPort());
                else
                    hostConfig.setHost(hcs.getHost());
            }

            if (hcs.getVirtualHost() != null) {
                HostParams params = hostConfig.getParams();
                if (params != null)
                    params.setVirtualHost(hcs.getVirtualHost());
            }

            if (hcs.getProxyHost() != null) {
                hostConfig.setProxy(hcs.getProxyHost(), hcs.getProxyPort());
            }

            try {
                InetAddress addr = InetAddress.getByName(hcs.getLocalAddress());
                hostConfig.setLocalAddress(addr);
            } catch (UnknownHostException ex) {
            }
            connectionParams.setMaxConnectionsPerHost(hostConfig, hcs.getMaximumConnections());
        }
    }
}

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./*ww w  .  j ava 2  s.  c o 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;
}

From source file:org.mule.transport.http.MuleHostConfiguration.java

@Override
public synchronized void setHost(URI uri) {
    try {/*from w  w w  . j a va2s.  c  o  m*/
        Protocol original = getProtocol();

        if (uri.getScheme().equals(original.getScheme())) {
            Protocol newProtocol = new Protocol(uri.getScheme(), original.getSocketFactory(),
                    original.getDefaultPort());

            super.setHost(uri.getHost(), uri.getPort(), newProtocol);
        } else {
            Protocol protoByName = Protocol.getProtocol(uri.getScheme());
            super.setHost(uri.getHost(), uri.getPort(), protoByName);
        }
    } catch (URIException uriException) {
        throw new IllegalArgumentException(uriException);
    }
}

From source file:org.mule.transport.http.MuleHostConfiguration.java

private Protocol cloneProtocolKeepingSocketFactory(Protocol protocol) {
    Protocol original = getProtocol();/*ww w. j  av  a 2  s . c  o  m*/
    if (protocol.getScheme().equals(original.getScheme())) {
        // the protocol is the same, create a copy of it but keep the original socket factory
        return new Protocol(protocol.getScheme(), original.getSocketFactory(), protocol.getDefaultPort());
    }
    return protocol;
}