Adding a Websocket engine to a context that already has a filter

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Adding a Websocket engine to a context that already has a filter

Christopher Piggott-2
I have a jersy/guice/grizzly application that has jersey instantiated as a GuiceFilter.  It goes something like:

WebappContext ctx = new WebappContext( "xt", "" );
ctx.addListener( MyServletContextListener.class );
FilterRegistration filter = ctx.addFilter( "myServletFilter", GuiceFilter.class );

filter.addMappingForUrlPatterns( EnumSet.of( DispatcherType.REQUEST ), "/myJersey/*" );


ws = new HttpServer();


NetworkListener nl = new NetworkListener( "xt-listener", NetworkListener.DEFAULT_NETWORK_HOST, port );

WebSocketAddOn webSocketAddon = new WebSocketAddOn();
nl.registerAddOn( webSocketAddon );

MyWebSocketApp app = new AhmWebSocketApp();
WebSocketEngine.getEngine().register( "", "/ws/*", app );


ServletRegistration sreg = ctx.addServlet( "defaultServlet", MyDefaultServlet.class );
sreg.addMapping( "*" );
ctx.deploy( ws );
ws.addListener( nl );

The problem is that the filter picks up everything it's mapped to, then my default servlet picks up everything else.  Because of that, the /ws/* piece that should be directed to the WSE never gets there.

If there any way to influence the order that these paths are processed, to make it look for /ws/* FIRST ? 

--C

Reply | Threaded
Open this post in threaded view
|

Re: Adding a Websocket engine to a context that already has a filter

oleksiys
Administrator
Hi Christopher,

can you pls. share the entire app, so it would be easier to test?

Thank you.

WBR,
Alexey.

On 03.05.13 11:56, Christopher Piggott wrote:
I have a jersy/guice/grizzly application that has jersey instantiated as a GuiceFilter.  It goes something like:

WebappContext ctx = new WebappContext( "xt", "" );
ctx.addListener( MyServletContextListener.class );
FilterRegistration filter = ctx.addFilter( "myServletFilter", GuiceFilter.class );

filter.addMappingForUrlPatterns( EnumSet.of( DispatcherType.REQUEST ), "/myJersey/*" );


ws = new HttpServer();


NetworkListener nl = new NetworkListener( "xt-listener", NetworkListener.DEFAULT_NETWORK_HOST, port );

WebSocketAddOn webSocketAddon = new WebSocketAddOn();
nl.registerAddOn( webSocketAddon );

MyWebSocketApp app = new AhmWebSocketApp();
WebSocketEngine.getEngine().register( "", "/ws/*", app );


ServletRegistration sreg = ctx.addServlet( "defaultServlet", MyDefaultServlet.class );
sreg.addMapping( "*" );
ctx.deploy( ws );
ws.addListener( nl );

The problem is that the filter picks up everything it's mapped to, then my default servlet picks up everything else.  Because of that, the /ws/* piece that should be directed to the WSE never gets there.

If there any way to influence the order that these paths are processed, to make it look for /ws/* FIRST ? 

--C