Dan Collins
Dan Collins

Reputation: 1018

Jetty works for HTTP but not HTTPS

I am trying to create a jetty consumer. I am able to get it successfully running using the endpoint uri:

jetty:http://0.0.0.0:8080

However, when I modify the endpoint uri for https:

jetty:https://0.0.0.0:8443

The page times out trying to load. This seems odd because the camel documentation states it should function right out of the box.

I have since loaded a signed SSL into java's default keystore, with my attempted implementation to load it below:http://camel.apache.org/jetty.html

I have a basic Jetty instance using the akka-camel library with akka and scala. ex:

class RestActor extends Actor with Consumer {

    val ksp: KeyStoreParameters = new KeyStoreParameters();
    ksp.setPassword("...");
    val kmp: KeyManagersParameters = new KeyManagersParameters();
    kmp.setKeyStore(ksp);
    val scp: SSLContextParameters = new SSLContextParameters();
    scp.setKeyManagers(kmp);
    val jettyComponent: JettyHttpComponent = CamelExtension(context.system).context.getComponent("jetty", classOf[JettyHttpComponent])
    jettyComponent.setSslContextParameters(scp);

    def endpointUri = "jetty:https://0.0.0.0:8443/"
    def receive = {
        case msg: CamelMessage => {
            ...
        }
        ...
    }
    ...
}

This resulted in some progress, because the page does not timeout anymore, but instead gives a "The connection was interrupted" error. I am not sure where to go from here because camel is not throwing any Exceptions, but rather failing silently somewhere (apparently).

Does anybody know what would cause this behavior?

Upvotes: 1

Views: 327

Answers (1)

Dan Collins
Dan Collins

Reputation: 1018

When using java's "keytool" I did not specify an output file. It didn't throw back an error, so it probably went somewhere. I created a new keystore and explicitly imported my crt into the keyfile. I then explicitly added the filepath to that keystore I created, and everything works now!

If I had to speculate, it is possible things failed silently because I was adding the certs to jetty's general bank of certs to use if eligible, instead of explicitly binding it as the SSL for the endpoint.

class RestActor extends Actor with Consumer {

    val ksp: KeyStoreParameters = new KeyStoreParameters();
    ksp.setResource("/path/to/keystore");
    ksp.setPassword("...");
    val kmp: KeyManagersParameters = new KeyManagersParameters();
    kmp.setKeyStore(ksp);
    val scp: SSLContextParameters = new SSLContextParameters();
    scp.setKeyManagers(kmp);
    val jettyComponent: JettyHttpComponent = CamelExtension(context.system).context.getComponent("jetty", classOf[JettyHttpComponent])
    jettyComponent.setSslContextParameters(scp);

    def endpointUri = "jetty:https://0.0.0.0:8443/"
    def receive = {
        case msg: CamelMessage => {
            ...
        }
        ...
    }
    ...
}

Hopefully somebody in the future can find use for this code as a template in implementing Jetty over SSL with akka-camel (surprisingly no examples seem to exist)

Upvotes: 1

Related Questions