我正在为我的骆驼路线编写Junit测试用例。骆驼路线之一包括如下的REST DSL
restConfiguration()
.component("jetty")
.host("0.0.0.0")
.port(this.port)
.scheme("https")
.endpointProperty("sslContextParameters", "#sslContextParameters");
请在下面找到一个测试用例。
@Test
public void testSampleService() throws Exception {
context.start();
...
MockEndpoint mock = getMockEndpoint("mock:mockEndPoint");
mock.expectedMessageCount(1);
...
context.stop();
}
在context.start()上,我得到如下异常。但是,当我将方案https更改为http并注释掉sslContextParameters的endpointProperty时,它可以正常工作。
IllegalStateException: No protocol factory for default protocol 'ssl-http/1.1' in ServerConnector@52bba91a{ssl-http/1.1,[ssl, http/1.1]}{0.0.0.0:9091}
at org.eclipse.jetty.server.AbstractConnector.doStart(AbstractConnector.java:267)
at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:81)
at org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:238)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.server.Server.doStart(Server.java:397)
我已经在骆驼上下文中为Jetty配置了SSL
<bean id="sslContextParameters" class="org.apache.camel.util.jsse.SSLContextParameters">
<property name="keyManagers">
<bean class="org.apache.camel.util.jsse.KeyManagersParameters">
<property name="keyPassword" value="${app.fuse.keymanager.password}" />
<property name="keyStore">
<bean class="org.apache.camel.util.jsse.KeyStoreParameters">
<property name="resource" value="${app.fuse.keystore.path}" />
<property name="type" value="JKS" />
<property name="password" value="${app.fuse.keystore.password}" />
<property name="camelContext" ref="ctx" />
</bean>
</property>
<property name="camelContext" ref="ctx" />
</bean>
</property>
<property name="camelContext" ref="ctx" />
</bean>
并在pom.xml中使用以下码头依赖项
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jetty</artifactId>
<version>2.17.0.redhat-630224</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.4.8.v20171121</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-io</artifactId>
<version>9.4.8.v20171121</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-continuation</artifactId>
<version>9.4.8.v20171121</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-http</artifactId>
<version>9.4.8.v20171121</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-jaas</artifactId>
<version>9.4.8.v20171121</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-security</artifactId>
<version>9.4.8.v20171121</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>9.4.8.v20171121</version>
<scope>test</scope>
</dependency>