2016-11-25 109 views
0

骆驼可以做到这一点: 2个站在码头上的休息服务,首先由http(例如在端口1234上)和第二个https(例如在端口4321上),我怎么配置它?那可能吗?2个端口和协议上的骆驼码头休息方法

影响,我需要获得(例如网址):

http://localhost:1234/firstHttpMethod 
http://localhost:1234/secondHttpMethod 
https://localhost:4321/firstHttpsMethod 
https://localhost:4321/secondHttpsMethod 

这一刻,当我尝试添加2路,仅次于正在工作。如何解决这个问题(我有一个思考做2休息服务 - 首先在码头,其次是别的东西,但它不是好的概念)。

代码如下所示:

camelContext.addRoutes(firstJettyBuilder()); 
camelContext.addRoutes(secondJettyBuilder()); 

protected RouteBuilder firstJettyBuilder() 
{ 
    return new RouteBuilder() 
    { 
     @Override 
     public void configure() 
      throws Exception 
     { 

      restConfiguration() 
       .component("jetty") 
       .host("localhost") 
       .port(42300) 
       .scheme("https") 
       .bindingMode(RestBindingMode.json) 
       .dataFormatProperty("json.in.disableFeatures", "FAIL_ON_UNKNOWN_PROPERTIES") 
       .dataFormatProperty("json.in.enableFeatures", "FAIL_ON_NULL_FOR_PRIMITIVES"); 

      configureSSL(); 
     } 

     private void configureSSL() 
     { 
      final JettyHttpComponent jettyComponent = camelContext.getComponent("jetty", JettyHttpComponent.class); 

      final Map<String, Object> sslSocketConnectorProperties = new HashMap<>(); 

      sslSocketConnectorProperties.put("keyStorePath", KEYSTORE); 
      sslSocketConnectorProperties.put("trustStorePath", KEYSTORE); 

      sslSocketConnectorProperties.put("keyStorePassword", KEYSTORE_PASSWORD); 
      sslSocketConnectorProperties.put("trustStorePassword", KEYSTORE_PASSWORD); 

      jettyComponent.setSslSocketConnectorProperties(sslSocketConnectorProperties); 
     } 
    }; 
} 
protected RouteBuilder createPosJettyBuilder() 
{ 
    return new RouteBuilder() 
    { 
     @Override 
     public void configure() 
      throws Exception 
     { 

      restConfiguration() 
       .component("jetty") 
       .host("localhost") 
       .port(42302) 
       .scheme("http") 
       .bindingMode(RestBindingMode.json) 
       .dataFormatProperty("json.in.disableFeatures", "FAIL_ON_UNKNOWN_PROPERTIES") 
       .dataFormatProperty("json.in.enableFeatures", "FAIL_ON_NULL_FOR_PRIMITIVES"); 

     } 

    }; 
} 
+1

请提供您的路由配置。 – SubOptimal

+0

你的第二个工作是什么?当你启动camelcontext时,两条路线都会出现吗?只有一条路线? –

+0

取决于调用第一或第二个jettyBuilder的顺序,我只能连接到其中一个服务 – pustypawel

回答

0

简短的回答:我不thnik这是可能在同一个骆驼背景下,因为我可以调用错误的原因。这可能有不同的背景。


这是调试后的一些观察结果。

第一次尝试:在问题中。

骆驼对两种配置都使用相同的Jetty端点。第二个RouteBuilder覆盖第一个端点配置。因此,预期的第一台服务器根本没有运行。

第二次尝试:多个Jetty端点。

一个可以尝试(创建码头端点(S),并将它们添加到上下文后)是这样的:

this.restConfiguration("jetty").... 
this.rest("/path").... // good 
... 
this.restConfiguration("jetty-tls").... 
this.rest("/path").... // produces exception! 

它看起来像其余的定义添加到骆驼背景。在为第二个RouteBuilder创建路由时,第一个定义已经存在。骆驼想创建2个路由具有相同路径,并抛出异常:

Failed to start route ... because of Multiple consumers for the same endpoint is not allowed: jetty:... 

不幸的是,它不是跳过休息定义的建设者之一的选项。

奖励尝试:多个码头端点和不同的路径。

人们期望至少这个工作:

this.restConfiguration("jetty").... 
this.rest("/path1").... // good 
... 
this.restConfiguration("jetty-tls").... 
this.rest("/path2").... // good 

没有例外这里,但骆驼开始3条路线!