users@jersey.java.net

Re: [Jersey] Using ServletFilter with Grizzly

From: Steven Cummings <estebistec_at_gmail.com>
Date: Mon, 14 Dec 2009 14:27:21 +0000

I have to think that the reason this isn't addressed in the API is that unit
testing is unit testing. If you put too much of your system back together,
you've moved into "integration testing", at which point you can test a WAR
that integrates your jersey application with configured servlet filters.
Then you use something (like [1]) to startup and stop your WAR as a webapp
either before/after all tests run or between tests.

[1] http://cargo.codehaus.org/Maven2+plugin
--
Steven
On Mon, Dec 14, 2009 at 2:23 PM, Markus Karg <markus.karg_at_gmx.net> wrote:
>  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/ServletAdapter.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
>
>
>