首页 > 代码库 > Websocket Component
Websocket Component
As of Camel 2.10, the Websocket component supports SSL/TLS configuration through the Camel JSSE Configuration Utility. So to use wss:// protocol, the SSLContextParameters must be defined:
<to uri="websocket://0.0.0.0:8443/notification?sslContextParameters=#sslContextParameters&sendToAll=true"/>
<camel:sslContextParameters id="sslContextParameters">
<camel:keyManagers keyPassword="666666">
<camel:keyStore resource="{{keystore.url}}" password="{{keystore.pwd}}" type="{{keystore.type}}"/>
</camel:keyManagers>
<camel:trustManagers>
<camel:keyStore resource="{{keystore.url}}" password="{{keystore.pwd}}" type="{{keystore.type}}"/>
</camel:trustManagers>
</camel:sslContextParameters>
There is a built-in default keystore implementation type known as "jks" that is provided by Sun Microsystems. There are two other types of keystores that come with the Sun JDK implementation: jceks, pkcs12.
// properties
websocket.url=0.0.0.0:8443
keystore.url=file:c:/demo/key.jceks
keystore.pwd=666666
keystore.type=jceks
<property name="location" value=http://www.mamicode.com/"file:C:/demo/etc/settings.cfg"/>
</bean>
<camel:camelContext xmlns="http://camel.apache.org/schema/spring">
…
<to uri="websocket://{{websocket.url}}/notification?sslContextParameters=#sslContextParameters&sendToAll=true"/>
…
</camel:camelContext>
Note: Using the
<!-- OSGI blueprint property placeholder -->
<cm:property-placeholder id="my.placeholder" persistent-id="com.example.demo">
<!-- list some properties for this test -->
<cm:default-properties>
<cm:property name="result" value=http://www.mamicode.com/"mock:result"/>
</cm:default-properties>
</cm:property-placeholder>
<to uri="websocket://0.0.0.0:8443/notification?sslContextParameters=#sslContextParameters&sendToAll=true"/>
<camel:sslContextParameters id="sslContextParameters">
<camel:keyManagers keyPassword="666666">
<camel:keyStore resource="{{keystore.url}}" password="{{keystore.pwd}}" type="{{keystore.type}}"/>
</camel:keyManagers>
<camel:trustManagers>
<camel:keyStore resource="{{keystore.url}}" password="{{keystore.pwd}}" type="{{keystore.type}}"/>
</camel:trustManagers>
</camel:sslContextParameters>
There is a built-in default keystore implementation type known as "jks" that is provided by Sun Microsystems. There are two other types of keystores that come with the Sun JDK implementation: jceks, pkcs12.
// properties
websocket.url=0.0.0.0:8443
keystore.url=file:c:/demo/key.jceks
keystore.pwd=666666
keystore.type=jceks
Configuring in Spring XML
<bean id="bridgePropertyPlaceholder" class="org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer"><property name="location" value=http://www.mamicode.com/"file:C:/demo/etc/settings.cfg"/>
</bean>
<camel:camelContext xmlns="http://camel.apache.org/schema/spring">
…
<to uri="websocket://{{websocket.url}}/notification?sslContextParameters=#sslContextParameters&sendToAll=true"/>
…
</camel:camelContext>
Note: Using the
<propertyPlaceholder>
tag in camelContext makes the configuration a bit more fresh such as: <propertyPlaceholder id="properties" location="file:C:/demo/etc/settings.cfg"/> Configuring in Blueprint
When using Blueprint property placeholder in the Blueprint XML file, you can declare the properties in a .properties or .cfg file. If you use Apache ServieMix / Karaf then this container has a convention that it loads the properties from a file in the etc directory with the naming etc/pid.cfg, where pid is the persistence-id.<!-- OSGI blueprint property placeholder -->
<cm:property-placeholder id="my.placeholder" persistent-id="com.example.demo">
<!-- list some properties for this test -->
<cm:default-properties>
<cm:property name="result" value=http://www.mamicode.com/"mock:result"/>
</cm:default-properties>
</cm:property-placeholder>
Reference
http://camel.apache.org/websocket.html
http://docs.oracle.com/javase/6/docs/technotes/guides/security/StandardNames.html
http://camel.apache.org/using-propertyplaceholder.html
作者:Hans.Hu
出处:http://huyh.cnblogs.com
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
Websocket Component
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。