差異處

這裏顯示兩個版本的差異處。

連向這個比對檢視

Both sides previous revision 前次修改
下次修改
前次修改
java:apache_camel:rest_with_netty_http_and_ssl [2017/11/22 20:45]
tony [Apply the REST with Netty-http and SSL]
java:apache_camel:rest_with_netty_http_and_ssl [2023/06/25 09:48] (目前版本)
行 1: 行 1:
 {{tag>​camel}} {{tag>​camel}}
 ====== Apply the REST with Netty-http and SSL ====== ====== Apply the REST with Netty-http and SSL ======
-網路找到的大部分都是透過xml設定方法,後來實驗出一個可行方法分享給大家。 +網路找到的大都是透過xml設定SSL到RestConfiguration中,後來實驗出透過coding的方法。 
-===== Code =====+===== Java =====
 <code java> <code java>
  
行 51: 行 51:
  scp.setKeyManagers(kmp);​  scp.setKeyManagers(kmp);​
  return scp;  return scp;
 + }
 + private RouteBuilder createRouteBuilder(CamelContext context){
 + return new RouteBuilder() {
 + @Override
 + public void configure() throws Exception {
 + NettyHttpComponent nettyComponent = context.getComponent("​netty4-http",​ NettyHttpComponent.class);​
 + nettyComponent.getConfiguration().setSslContextParameters(createSSLContextParameters());​
 +
 + restConfiguration().component("​netty4-http"​).port(8444).bindingMode(RestBindingMode.auto).endpointProperty("​ssl", ​ "​true"​);​
 + rest("/​services/​{id}"​).get().route().bean(eventHandler,​ "​receiveServiceEvent(header.id)"​);​
 + }
 + };
  }  }
   
行 58: 行 70:
  CamelContext context = new DefaultCamelContext();​  CamelContext context = new DefaultCamelContext();​
  try {  try {
 + context.addRoutes(createRouteBuilder(context));​
  context.start();​  context.start();​
- context.addRoutes(new RouteBuilder() { 
- @Override 
- public void configure() throws Exception { 
- NettyHttpComponent nettyComponent = context.getComponent("​netty4-http",​ NettyHttpComponent.class);​ 
- nettyComponent.getConfiguration().setSslContextParameters(createSSLContextParameters());​ 
-  
- restConfiguration().port(8080).bindingMode(RestBindingMode.auto).endpointProperty("​ssl", ​ "​true"​);​ 
- rest("/​services/​{id}"​).get().route().bean(eventHandler,​ "​receiveServiceEvent(header.id)"​);​ 
- } 
- }); 
   
  System.out.println("​Enter"​);​  System.out.println("​Enter"​);​
行 91: 行 94:
   * [[http://​camel.apache.org/​netty4-http.html|netty4-http]]   * [[http://​camel.apache.org/​netty4-http.html|netty4-http]]
   * [[http://​camel.apache.org/​camel-configuration-utilities.html|camel-configuration-utilities]]   * [[http://​camel.apache.org/​camel-configuration-utilities.html|camel-configuration-utilities]]
 +  * [[https://​stackoverflow.com/​questions/​40803215/​camel-jetty-rest-methods-on-2-ports-and-protocols|Camel jetty rest methods on 2 ports and protocols]]
  
 =====    ===== =====    =====