访问akka-camel actor下的Camel / Jetty实例

时间:2013-12-04 23:09:59

标签: scala jetty apache-camel akka

我有一个基本的Jetty实例,使用带有akka和scala的akka​​-camel库。例如:

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

我想将SslSocketConnector绑定到底层的jetty实例,以便我可以加载我的SSL证书,但我遇到的问题是我无法弄清楚如何获取一个句柄底层的jetty实例来调用addConnector()功能。我有一个想法是将Camel特性添加到我的类中(例如:RestActor使用Consumer with Camel扩展Actor)来访问Camel的“context”变量,但编译器抱怨这样做会覆盖“context”变量,该变量也存在于阿卡的演员特质。

1 个答案:

答案 0 :(得分:0)

以下代码似乎提供对底层Camel对象的访问。

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

编辑:我正在使用akka的scala akka-camel库成功运行Jetty w / SSL的最终代码,以供将来寻找如何实现这一点的示例。

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