users@jersey.java.net

RE: [Jersey] Using ServletFilter with Grizzly

From: Markus Karg <markus.karg_at_gmx.net>
Date: Mon, 14 Dec 2009 15:23:50 +0100

Thank you for this URL, which I actually already new before. I wrote the
following code which in fact is working pretty well:

 

final GrizzlyWebServer ws = new GrizzlyWebServer(80);

final ServletAdapter sa = new ServletAdapter(new
ServletContainer(MyApplication.class));

sa.addFilter(new MyServletFilter(), "My Servlet Filter",
Collections.EMPTY_MAP);

ws.addGrizzlyAdapter(sa, null);

ws.start();

 

Since that is much more code that without using a filter (which can be done
in just two lines thanks to GrizzlyServerFactory) I wonder whether the is a
smarter (and shorter) way to achieve this?

 

Thanks

Markus

 

 

From: Steven Cummings [mailto:estebistec_at_gmail.com]
Sent: Sonntag, 13. Dezember 2009 21:05
To: users_at_jersey.dev.java.net
Subject: Re: [Jersey] Using ServletFilter with Grizzly

 

The only way I've found is to directly setup a ServletAdapter [1], which is
one of the implementations that GrizzlyWebContainer can use behind the
scenes to set up your test server.

 

[1]
https://grizzly.dev.java.net/nonav/apidocs/com/sun/grizzly/http/servlet/Serv
letAdapter.html#addFilter(javax.servlet.Filter, java.lang.String,
java.util.Map)
--
Steven
On Sun, Dec 13, 2009 at 7:00 PM, Markus Karg <markus.karg_at_gmx.net> wrote:
Dear Jersey Community,
 
to test drive a small JAX-RS sample I wrote, I am using Grizzly. Now I need
to add a ServletFilter that shall filter all requests going through Grizzly
to the JAX-RS application. I wonder how this can be set up. Any ideas? The
current code I am using is this one:
 
public class Main {
  public static void main(String[] args) throws IOException {
    Adapter adapter = RuntimeDelegate.getInstance().createEndpoint(new
MyApplication(), Adapter.class);
    GrizzlyServerFactory.create("http://localhost:80/", adapter);
  }
}
 
Thanks a lot!
Markus