使用Apache Camel Atmosphere Websocket组件(大气 - websocket)是否有任何示例?我正在尝试一个基本的东西;从客户端(Html5 Websocket)向严重(Camel氛围 - webscoket组件)发送消息并重新发送回客户端。我使用的严重是vFabric tc Runtime 2.9.5.SR1或Tomcat 7.0.50
我的路线看起来像这样
from("atmosphere-websocket://localhost:8181/test1").to("log:body ${body}").to("atmosphere-websocket://localhost:8181/test1");
Javascript代码
var ws = new WebSocket("ws://localhost:8181/test1");
ws.onopen = function (e) {
console.log("open");
}
ws.onclose = function (e) {
console.log("close");
}
ws.onerror = function (e) {
console.log("error");
}
ws.onmessage = function (e) {
console.log("message");
}
但我收到了错误
WebSocket connection to 'ws://localhost:8181/test1' failed: Error during WebSocket handshake: Unexpected response code: 403
从日志中我可以看到路由和Atmospher框架启动没有任何错误
2015-03-10 16:13:14,391 [ost-startStop-1] WARN IOUtils - META-INF/services/org.atmosphere.cpr.AtmosphereFramework not found in class loader
2015-03-10 16:13:14,435 [ost-startStop-1] INFO AtmosphereFramework - Atmosphere is using org.atmosphere.cpr.DefaultAnnotationProcessor for processing annotation
2015-03-10 16:13:14,436 [ost-startStop-1] INFO DefaultAnnotationProcessor - AnnotationProcessor class org.atmosphere.cpr.DefaultAnnotationProcessor$BytecodeBasedAnnotationProcessor being used
2015-03-10 16:13:14,482 [ost-startStop-1] INFO AtmosphereFramework - Auto detecting atmosphere handlers /WEB-INF/classes/
2015-03-10 16:13:14,484 [ost-startStop-1] INFO AtmosphereFramework - Auto detecting WebSocketHandler in /WEB-INF/classes/
2015-03-10 16:13:14,485 [ost-startStop-1] INFO AtmosphereFramework - Installed WebSocketProtocol org.apache.camel.component.atmosphere.websocket.WebsocketHandler
2015-03-10 16:13:14,516 [ost-startStop-1] INFO AtmosphereFramework - Installed AtmosphereHandler org.atmosphere.cpr.AtmosphereFramework$5 mapped to context-path: /*
2015-03-10 16:13:14,516 [ost-startStop-1] INFO AtmosphereFramework - Installed the following AtmosphereInterceptor mapped to AtmosphereHandler org.atmosphere.cpr.AtmosphereFramework$5
2015-03-10 16:13:14,516 [ost-startStop-1] INFO AtmosphereFramework - Installing Default AtmosphereInterceptor
2015-03-10 16:13:14,517 [ost-startStop-1] INFO AtmosphereFramework - org.atmosphere.interceptor.CorsInterceptor : CORS Interceptor Support
2015-03-10 16:13:14,517 [ost-startStop-1] INFO AtmosphereFramework - org.atmosphere.interceptor.CacheHeadersInterceptor : Default Response's Headers Interceptor
2015-03-10 16:13:14,520 [ost-startStop-1] INFO AtmosphereFramework - org.atmosphere.interceptor.PaddingAtmosphereInterceptor : Browser Padding Interceptor Support
2015-03-10 16:13:14,520 [ost-startStop-1] INFO AtmosphereFramework - org.atmosphere.interceptor.AndroidAtmosphereInterceptor : Android Interceptor Support
2015-03-10 16:13:14,521 [ost-startStop-1] INFO AtmosphereFramework - org.atmosphere.interceptor.HeartbeatInterceptor : Heartbeat Interceptor Support
2015-03-10 16:13:14,521 [ost-startStop-1] INFO AtmosphereFramework - org.atmosphere.interceptor.SSEAtmosphereInterceptor : SSE Interceptor Support
2015-03-10 16:13:14,521 [ost-startStop-1] INFO AtmosphereFramework - org.atmosphere.interceptor.JSONPAtmosphereInterceptor : JSONP Interceptor Support
2015-03-10 16:13:14,524 [ost-startStop-1] INFO AtmosphereFramework - org.atmosphere.interceptor.JavaScriptProtocol : Atmosphere JavaScript Protocol
2015-03-10 16:13:14,524 [ost-startStop-1] INFO AtmosphereFramework - org.atmosphere.interceptor.WebSocketMessageSuspendInterceptor : org.atmosphere.interceptor.WebSocketMessageSuspendInterceptor
2015-03-10 16:13:14,525 [ost-startStop-1] INFO AtmosphereFramework - org.atmosphere.interceptor.OnDisconnectInterceptor : Browser disconnection detection
2015-03-10 16:13:14,525 [ost-startStop-1] INFO AtmosphereFramework - org.atmosphere.interceptor.IdleResourceInterceptor : org.atmosphere.interceptor.IdleResourceInterceptor
2015-03-10 16:13:14,525 [ost-startStop-1] INFO AtmosphereFramework - Set org.atmosphere.cpr.AtmosphereInterceptor.disableDefaults to disable them.
2015-03-10 16:13:14,532 [ost-startStop-1] INFO AtmosphereFramework - Using EndpointMapper class org.atmosphere.util.DefaultEndpointMapper
2015-03-10 16:13:14,532 [ost-startStop-1] WARN AtmosphereFramework - No BroadcasterCache configured. Broadcasted message between client reconnection will be LOST. It is recommended to configure the org.atmosphere.cache.UUIDBroadcasterCache
2015-03-10 16:13:14,532 [ost-startStop-1] INFO AtmosphereFramework - Default Broadcaster Class: org.atmosphere.cpr.DefaultBroadcaster
2015-03-10 16:13:14,532 [ost-startStop-1] INFO AtmosphereFramework - Broadcaster Polling Wait Time 100
2015-03-10 16:13:14,532 [ost-startStop-1] INFO AtmosphereFramework - Shared ExecutorService supported: true
2015-03-10 16:13:14,532 [ost-startStop-1] INFO AtmosphereFramework - Messaging Thread Pool Size: Unlimited
2015-03-10 16:13:14,532 [ost-startStop-1] INFO AtmosphereFramework - Async I/O Thread Pool Size: 200
2015-03-10 16:13:14,533 [ost-startStop-1] INFO AtmosphereFramework - Using BroadcasterFactory: org.atmosphere.cpr.DefaultBroadcasterFactory
2015-03-10 16:13:14,533 [ost-startStop-1] INFO AtmosphereFramework - Using WebSocketProcessor: org.atmosphere.websocket.DefaultWebSocketProcessor
2015-03-10 16:13:14,533 [ost-startStop-1] INFO AtmosphereFramework - Invoke AtmosphereInterceptor on WebSocket message true
2015-03-10 16:13:14,533 [ost-startStop-1] INFO AtmosphereFramework - HttpSession supported: false
2015-03-10 16:13:14,533 [ost-startStop-1] INFO AtmosphereFramework - Atmosphere is using DefaultAtmosphereObjectFactory for dependency injection and object creation
2015-03-10 16:13:14,533 [ost-startStop-1] INFO AtmosphereFramework - Atmosphere is using async support: org.atmosphere.container.Tomcat7Servlet30SupportWithWebSocket running under container: Undefined using javax.servlet/3.0
2015-03-10 16:13:14,535 [ost-startStop-1] INFO AtmosphereFramework - Atmosphere Framework 2.2.0 started.
2015-03-10 16:13:14,576 [ost-startStop-1] INFO SpringCamelContext - Route: route4 started and consuming from: Endpoint[atmosphere-websocket://localhost:8181/test1]
答案 0 :(得分:0)
当您使用大气 - websocket端点时,您应该只指定路径。组件的单元测试文件夹中有一个jave DSL示例。
还有一个osgi示例代码及其指令 https://github.com/elakito/testzone/tree/master/samples/osgi_camel_websocket_sample_route_bp https://github.com/elakito/testzone/blob/master/samples/instruction_osgi_camel_websocket_sample_route.txt