Search in sources :

Example 1 with AuthSSLProtocolSocketFactory

use of org.apache.commons.httpclient.contrib.ssl.AuthSSLProtocolSocketFactory in project ddf by codice.

the class HttpProxyServiceImpl method start.

public String start(final String endpointName, final String targetUri, final Integer timeout, final boolean matchOnPrefix, final Object bean) throws Exception {
    // Enable proxy settings for the external target
    enableProxySettings();
    // Fetch location of trust store and trust store password
    fetchTrustStoreLocation();
    // Create SSL connection Camel protocol for https
    Protocol authhttps = null;
    File certStore = new File(trustStore);
    try {
        authhttps = new Protocol("https", new AuthSSLProtocolSocketFactory(certStore.toURI().toURL(), trustStorePassword, certStore.toURI().toURL(), trustStorePassword), 443);
    } catch (MalformedURLException e) {
        LOGGER.debug(e.getMessage());
    }
    if (authhttps != null) {
        Protocol.registerProtocol("https", authhttps);
    }
    final String matchPrefix = (matchOnPrefix) ? "?matchOnUriPrefix=true" : "";
    final String protocolDelimiter = (routeEndpointType.equals(SERVLET)) ? ":///" : "://";
    // Create Camel route
    RouteBuilder routeBuilder;
    if (bean == null) {
        routeBuilder = new RouteBuilder() {

            @Override
            public void configure() throws Exception {
                from(routeEndpointType + protocolDelimiter + endpointName + matchPrefix).removeHeader("Authorization").removeHeader("Cookie").to(targetUri + "?bridgeEndpoint=true&throwExceptionOnFailure=false&httpClient.soTimeout=" + timeout + "&httpClient.connectionManagerTimeout=" + timeout).routeId(endpointName);
            }
        };
    } else {
        routeBuilder = new RouteBuilder() {

            @Override
            public void configure() throws Exception {
                from(routeEndpointType + protocolDelimiter + endpointName + matchPrefix).removeHeader("Authorization").removeHeader("Cookie").to(targetUri + "?bridgeEndpoint=true&throwExceptionOnFailure=false&httpClient.soTimeout=" + timeout + "&httpClient.connectionManagerTimeout=" + timeout).routeId(endpointName).bean(bean);
            }
        };
    }
    camelContext.addRoutes(routeBuilder);
    camelContext.start();
    LOGGER.debug("Started proxy route at servlet endpoint: {}, routing to: {}", endpointName, targetUri);
    endpointIds.add(endpointName);
    return endpointName;
}
Also used : MalformedURLException(java.net.MalformedURLException) RouteBuilder(org.apache.camel.builder.RouteBuilder) AuthSSLProtocolSocketFactory(org.apache.commons.httpclient.contrib.ssl.AuthSSLProtocolSocketFactory) Protocol(org.apache.commons.httpclient.protocol.Protocol) File(java.io.File) MalformedURLException(java.net.MalformedURLException)

Aggregations

File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 AuthSSLProtocolSocketFactory (org.apache.commons.httpclient.contrib.ssl.AuthSSLProtocolSocketFactory)1 Protocol (org.apache.commons.httpclient.protocol.Protocol)1