差異處
這裏顯示兩個版本的差異處。
下次修改 | 前次修改 | ||
java:apache_camel:rest_with_netty_http_and_ssl [2017/11/21 18:06] tony 建立 |
java:apache_camel:rest_with_netty_http_and_ssl [2023/06/25 09:48] (目前版本) |
||
---|---|---|---|
行 1: | 行 1: | ||
+ | {{tag>camel}} | ||
====== Apply the REST with Netty-http and SSL ====== | ====== Apply the REST with Netty-http and SSL ====== | ||
- | ===== Code ===== | + | 網路找到的大都是透過xml設定SSL到RestConfiguration中,後來實驗出透過coding的方法。 |
+ | ===== Java ===== | ||
<code java> | <code java> | ||
行 49: | 行 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)"); | ||
+ | } | ||
+ | }; | ||
} | } | ||
行 56: | 行 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"); | ||
行 88: | 行 93: | ||
===== Reference ===== | ===== Reference ===== | ||
* [[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]] | ||
+ | * [[https://stackoverflow.com/questions/40803215/camel-jetty-rest-methods-on-2-ports-and-protocols|Camel jetty rest methods on 2 ports and protocols]] | ||
+ | |||
+ | ===== ===== | ||
+ | ---- | ||
+ | \\ | ||
+ | ~~DISQUS~~ |