Search in sources :

Example 1 with Protocol

use of org.apache.commons.httpclient.protocol.Protocol in project tdi-studio-se by Talend.

the class HttpMethodBase method generateRequestLine.

// ------------------------------------------------- Static Utility Methods
/**
     * Generates HTTP request line according to the specified attributes.
     *
     * @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(HttpConnection connection, String name, String requestPath, String query, String version) {
    LOG.trace("enter HttpMethodBase.generateRequestLine(HttpConnection, " + "String, String, String, String)");
    StringBuffer buf = new StringBuffer();
    // Append method name
    buf.append(name);
    buf.append(" ");
    // Absolute or relative URL?
    if (!connection.isTransparent()) {
        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(" ");
    buf.append(version);
    buf.append("\r\n");
    return buf.toString();
}
Also used : Protocol(org.apache.commons.httpclient.protocol.Protocol)

Example 2 with Protocol

use of org.apache.commons.httpclient.protocol.Protocol in project zm-mailbox by Zimbra.

the class SocketFactories method register.

private static synchronized void register(X509TrustManager tm) {
    if (registered)
        return;
    // Set default TrustManager
    TrustManagers.setDefaultTrustManager(tm);
    // Register Apache Commons HTTP/HTTPS protocol socket factories
    ProtocolSocketFactory psf = defaultProtocolSocketFactory();
    Protocol.registerProtocol(HTTP, new Protocol(HTTP, psf, 80));
    ProtocolSocketFactory spsf = defaultSecureProtocolSocketFactory();
    Protocol.registerProtocol(HTTPS, new Protocol(HTTPS, spsf, 443));
    // HttpURLConnection already uses system ProxySelector by default
    // Set HttpsURLConnection SSL socket factory and optional hostname verifier
    HttpsURLConnection.setDefaultSSLSocketFactory(defaultSSLSocketFactory(false));
    if (tm instanceof CustomTrustManager) {
        HttpsURLConnection.setDefaultHostnameVerifier(new CustomHostnameVerifier());
    }
    // Set the system-wide default ProxySelector
    ProxySelector.setDefault(ProxySelectors.defaultProxySelector());
    registered = true;
}
Also used : ProtocolSocketFactory(org.apache.commons.httpclient.protocol.ProtocolSocketFactory) SecureProtocolSocketFactory(org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory) Protocol(org.apache.commons.httpclient.protocol.Protocol)

Example 3 with Protocol

use of org.apache.commons.httpclient.protocol.Protocol in project translationstudio8 by heartsome.

the class ServiceUtilTest method getService.

public static IService getService() throws MalformedURLException {
    // Service srvcModel = new
    // ObjectServiceFactory().create(IService.class);
    // XFireProxyFactory factory = new XFireProxyFactory(XFireFactory
    // .newInstance().getXFire());
    //
    // IService srvc = (IService) factory.create(srvcModel,
    // Constants.CONNECT_URL);
    // return srvc;
    ProtocolSocketFactory easy = new EasySSLProtocolSocketFactory();
    Protocol protocol = new Protocol(HTTP_TYPE, easy, PORT);
    Protocol.registerProtocol(HTTP_TYPE, protocol);
    Service serviceModel = new ObjectServiceFactory().create(IService.class, SERVICE_NAME, SERVICE_NAMESPACE, null);
    IService service = (IService) new XFireProxyFactory().create(serviceModel, SERVICE_URL);
    Client client = ((XFireProxy) Proxy.getInvocationHandler(service)).getClient();
    client.addOutHandler(new DOMOutHandler());
    client.setProperty(CommonsHttpMessageSender.GZIP_ENABLED, Boolean.FALSE);
    client.setProperty(CommonsHttpMessageSender.DISABLE_EXPECT_CONTINUE, "1");
    client.setProperty(CommonsHttpMessageSender.HTTP_TIMEOUT, "0");
    return service;
}
Also used : ProtocolSocketFactory(org.apache.commons.httpclient.protocol.ProtocolSocketFactory) EasySSLProtocolSocketFactory(org.codehaus.xfire.transport.http.EasySSLProtocolSocketFactory) ObjectServiceFactory(org.codehaus.xfire.service.binding.ObjectServiceFactory) DOMOutHandler(org.codehaus.xfire.util.dom.DOMOutHandler) Service(org.codehaus.xfire.service.Service) Protocol(org.apache.commons.httpclient.protocol.Protocol) Client(org.codehaus.xfire.client.Client) XFireProxy(org.codehaus.xfire.client.XFireProxy) XFireProxyFactory(org.codehaus.xfire.client.XFireProxyFactory) EasySSLProtocolSocketFactory(org.codehaus.xfire.transport.http.EasySSLProtocolSocketFactory)

Example 4 with Protocol

use of org.apache.commons.httpclient.protocol.Protocol in project camel by apache.

the class HttpsSslContextParametersGetTest method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        public void configure() {
            SSLContextParameters params = new SSLContextParameters();
            ProtocolSocketFactory factory = new SSLContextParametersSecureProtocolSocketFactory(params, context);
            Protocol.registerProtocol("https", new Protocol("https", factory, 443));
            from("direct:start").to("https://mail.google.com/mail/").to("mock:results");
        }
    };
}
Also used : ProtocolSocketFactory(org.apache.commons.httpclient.protocol.ProtocolSocketFactory) RouteBuilder(org.apache.camel.builder.RouteBuilder) Protocol(org.apache.commons.httpclient.protocol.Protocol) SSLContextParameters(org.apache.camel.util.jsse.SSLContextParameters)

Example 5 with Protocol

use of org.apache.commons.httpclient.protocol.Protocol in project pinpoint by naver.

the class HttpMethodBaseExecuteMethodInterceptor method recordDestination.

private void recordDestination(final Trace trace, final HttpMethod httpMethod, final Object[] args) {
    final SpanEventRecorder recorder = trace.currentSpanEventRecorder();
    try {
        final URI uri = httpMethod.getURI();
        final HttpConnection httpConnection = getHttpConnection(args);
        // if uri have schema or not found HttpConnection argument.
        if (uri.isAbsoluteURI() || httpConnection == null) {
            recorder.recordAttribute(AnnotationKey.HTTP_URL, InterceptorUtils.getHttpUrl(uri.getURI(), param));
            recorder.recordDestinationId(getEndpoint(uri.getHost(), uri.getPort()));
            return;
        }
        if (isDebug) {
            logger.debug("URI is not absolute. {}", uri.getURI());
        }
        // use HttpConnection argument.
        final String host = httpConnection.getHost();
        int port = httpConnection.getPort();
        final StringBuilder httpUrl = new StringBuilder();
        final Protocol protocol = httpConnection.getProtocol();
        if (protocol != null) {
            httpUrl.append(protocol.getScheme()).append("://");
            httpUrl.append(httpConnection.getHost());
            // if port is default port number.
            if (httpConnection.getPort() == protocol.getDefaultPort()) {
                port = -1;
            } else {
                httpUrl.append(":").append(port);
            }
        }
        httpUrl.append(uri.getURI());
        recorder.recordAttribute(AnnotationKey.HTTP_URL, InterceptorUtils.getHttpUrl(httpUrl.toString(), param));
        recorder.recordDestinationId(getEndpoint(host, port));
    } catch (URIException e) {
        logger.error("Fail get URI", e);
        recorder.recordDestinationId("unknown");
    }
}
Also used : URIException(org.apache.commons.httpclient.URIException) HttpConnection(org.apache.commons.httpclient.HttpConnection) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) Protocol(org.apache.commons.httpclient.protocol.Protocol) URI(org.apache.commons.httpclient.URI)

Aggregations

Protocol (org.apache.commons.httpclient.protocol.Protocol)12 ProtocolSocketFactory (org.apache.commons.httpclient.protocol.ProtocolSocketFactory)6 IOException (java.io.IOException)2 RouteBuilder (org.apache.camel.builder.RouteBuilder)2 HttpClient (org.apache.commons.httpclient.HttpClient)2 URI (org.apache.commons.httpclient.URI)2 URIException (org.apache.commons.httpclient.URIException)2 SecureProtocolSocketFactory (org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory)2 Client (org.codehaus.xfire.client.Client)2 XFireProxy (org.codehaus.xfire.client.XFireProxy)2 XFireProxyFactory (org.codehaus.xfire.client.XFireProxyFactory)2 Service (org.codehaus.xfire.service.Service)2 ObjectServiceFactory (org.codehaus.xfire.service.binding.ObjectServiceFactory)2 EasySSLProtocolSocketFactory (org.codehaus.xfire.transport.http.EasySSLProtocolSocketFactory)2 DOMOutHandler (org.codehaus.xfire.util.dom.DOMOutHandler)2 SpanEventRecorder (com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)1 BufferedInputStream (java.io.BufferedInputStream)1 BufferedOutputStream (java.io.BufferedOutputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1