在具有jetty的同一服务器中使用camel创建http和https端点



我正试图在我的一个web服务中创建HTTP和HTTPS端点。我想要使用HTTPS的安全少数端点和使用纯HTTP的其他端点。

我使用下面的代码来做同样的事情。

public void configure() {
configureJetty();
configureHttp4();
//This works with configuring Jetty
from("jetty:https://0.0.0.0:8085/sample1/?matchOnUriPrefix=true")
.to("file://./?fileName=out.csv");
//This url does not working with the configuring the jetty with configure jetty this works.
from("jetty:http://0.0.0.0:8084/sample2/?matchOnUriPrefix=true")
.to("file://./?fileName=out2.csv");
}
private void configureJetty() {
KeyStoreParameters ksp = new KeyStoreParameters();
ksp.setResource("./trustStore.jks");
ksp.setPassword("someSecretPassword");
KeyManagersParameters kmp = new KeyManagersParameters();
kmp.setKeyStore(ksp); kmp.setKeyPassword("someSecretPassword");
SSLContextParameters scp = new SSLContextParameters();
scp.setKeyManagers(kmp);
JettyHttpComponent jettyComponent = getContext().getComponent("jetty", JettyHttpComponent.class);
jettyComponent.setSslContextParameters(scp);
}

https可以很好地使用此设置,但http端点不起作用。如果我删除了配置Jetty的方法调用,HTTP端点就会工作。如何在同一台服务器中配置两者?我不能使用弹簧靴,只能使用普通的驼色组件。

我已经用示例代码创建了一个github存储库。你可以在这里找到它。样本代码

您可以

  • 创建两个不同的jetty组件实例,一个用于纯http,另一个用于https
  • 用特定别名("jetty"one_answers"jettys"(注册它们中的每一个
  • 在端点uri中使用适当的别名";来自("jettys:…"(

CDI示例:

@Produces
@ApplicationScoped 
@Named("jetty")
public final JettyHttpComponent createJettyComponent1() {       
return this.configureJetty(false);
}
@Produces
@ApplicationScoped 
@Named("jettys")
public final JettyHttpComponent createJettyComponent2() {       
return this.configureJetty(true);
}  
private void configureJetty(boolean ssl) {
...
JettyHttpComponent jettyComponent = new JettyHttpComponent();
if (ssl) {
jettyComponent.setSslContextParameters(scp);
}   
}

最新更新