users@grizzly.java.net

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

From: Christopher Piggott <cpiggott_at_gmail.com>
Date: Fri, 3 May 2013 14:56:06 -0400

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