1

i have following https client but it has deprecated methods in it . When i am trying to remove them I am not getting the response back . can you help me get this client without deprecated methods.

Deprecated methods: SSLSocketFactory SchemeRegistry Scheme getConnectionManager()

My Client :

HttpComponent httpComponent = context.getComponent("https4", HttpComponent.class);

    KeyStore keystore = KeyStore.getInstance("JKS");
    keystore.load(new FileInputStream(new File("XXXXXX")), "XXXXXX".toCharArray());
    //keystore.load(new FileInputStream(new File("C:/certificate/ToPankaj/clientcert.jks")), "changeit".toCharArray());

    KeyManagerFactory keyFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
    keyFactory.init(keystore, "changeit".toCharArray());


    SSLContext sslcontext = SSLContext.getInstance("SSLv3");
    sslcontext.init(keyFactory.getKeyManagers(), null, null);


    @SuppressWarnings("deprecation")
    SSLSocketFactory factory = new SSLSocketFactory(sslcontext, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

    @SuppressWarnings("deprecation")
    SchemeRegistry registry = new SchemeRegistry();

    @SuppressWarnings("deprecation")
    final Scheme scheme = new Scheme("https4", 443, factory);

    //registry.register(scheme);

    httpComponent.setHttpClientConfigurer(new HttpClientConfigurer() 
    {

        @SuppressWarnings("deprcecation")
        @Override
        public void configureHttpClient(HttpClient client) {
            client.getConnectionManager().getSchemeRegistry().register(scheme);
        }
    });

    httpComponent.setClientConnectionManager(new ThreadSafeClientConnManager());
    //httpComponent.
    Endpoint endpoint =httpComponent.createEndpoint(Uri);

    return endpoint;

1 Answer 1

2

Use the example from the Camel doc:

import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.http.SSLContextParametersSecureProtocolSocketFactory;
import org.apache.camel.main.Main;
import org.apache.camel.util.jsse.KeyManagersParameters;
import org.apache.camel.util.jsse.KeyStoreParameters;
import org.apache.camel.util.jsse.SSLContextParameters;
import org.apache.commons.httpclient.protocol.Protocol;
import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;

public class SSLHttpClientRouteBuilder extends RouteBuilder {

    @Override
    public void configure() {
        final KeyStoreParameters ksp = new KeyStoreParameters();
        ksp.setResource("/users/home/server/keystore.jks");
        ksp.setPassword("keystorePassword");

        final KeyManagersParameters kmp = new KeyManagersParameters();
        kmp.setKeyStore(ksp);
        kmp.setKeyPassword("keyPassword");

        final SSLContextParameters scp = new SSLContextParameters();
        scp.setKeyManagers(kmp);

        final ProtocolSocketFactory factory = new SSLContextParametersSecureProtocolSocketFactory(scp);

        Protocol.registerProtocol("https", new Protocol("https", factory, 443));

        from("direct:start").to("https://mail.google.com/mail/").to("mock:results");
    }
}

Alternativelly, you can also directly use the Apache HTTP client as mentioned in the Camel doc

Sign up to request clarification or add additional context in comments.

2 Comments

to("https://mail.google.com/mail/") defines a client reading data from a server, doesn't it?
It does. Also, this is the simplest example I have seen so far as it doesn't require you to fiddle with the HTTP Client itself. Simply adding your keystore or truststore is enough for many use cases.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.