2015-03-10 4 views
1

Есть ли какой-нибудь пример для использования компонента Apache Camel Atmosphere Websocket (атмосфера-websocket)? Я пробую основную вещь; отправляя сообщение от клиента (Html5 Websocket) на серьезный (компонент Camel atmosphere-webscoket) и повторно отправляемый клиенту. Суровым я пользуюсь vFabric tc Runtime 2.9.5.SR1 или Tomcat 7.0.50Пример для использования компонента Apache Camel Atmosphere Websocket

My Маршрут выглядит следующим образом

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

При использовании атмосферно-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