0
votes

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

class RestActor extends Actor with Consumer {
    def endpointUri = "jetty:https://0.0.0.0:443/"
    def receive = {
        case msg: CamelMessage => {
            ...
        }
        ...
    }
    ...
}

I want to bind a SslSocketConnector to the underlying jetty instance so that I can load my SSL cert, but the problem I have is I can't figure out how to get a handle the underlying jetty instance to call the addConnector() function. One thought I had was to add the Camel trait to my class (ex: RestActor extends Actor with Consumer with Camel) to access Camel's "context" variable, but the compiler complains that doing this will override the "context" variable which also exists from Akka's actor trait.

1

1 Answers

0
votes

The following code appears to provide access to the underlying Camel object.

class RestActor extends Actor with Consumer {
    val camel = CamelExtension(context.system).context
    def endpointUri = "jetty:https://0.0.0.0:443/"
    def receive = {
        case msg: CamelMessage => {
            ...
        }
        ...
    }
    ...
}

EDIT: I am including the final code that successfully runs Jetty w/SSL using akka's scala akka-camel library for anybody looking for an example on how to impliment this in the future.

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 => {
            ...
        }
        ...
    }
    ...
}