Ecthelion
Ecthelion

Reputation: 119

Jersey with embedded Jetty + PostReplaceFilter

I am using Jersey with an embedded Jetty according to the documentation http://wiki.eclipse.org/Jetty/Tutorial/Embedding_Jetty. This works fine so far. What I'd like to add now is usage of the PostReplaceFilter in this configuration.

Normally this is done in the web.xml like this

    <init-param>
        <param-name>com.sun.jersey.spi.container.ContainerRequestFilters</param-name>
        <param-value>com.sun.jersey.api.container.filter.PostReplaceFilter</param-value>
    </init-param>

But using the embedded Jetty I have no web.xml. I tried setting the filter programmatically like this

    ServletContextHandler sch = new ServletContextHandler(server, "myapp");

    sch.setInitParameter("com.sun.jersey.spi.container.ContainerRequestFilters", "com.sun.jersey.api.container.filter.PostReplaceFilter");

But this does not show any effect. Can anyone shed light on how to install a PostReplaceFilter using Java code?

Thanks in advance


I looks like I missed to mention one important fact, which is that I am using Google Guice. Therefore there is no ServletHolder where I could set initialization parameters. Instead I could finally find the answer in the Guice documentation at http://code.google.com/p/google-guice/wiki/ServletRegexKeyMapping in the section on "Initialization Parameters". So for the PostReplaceFilter this would look like this:

 Map<String, String> params = new HashMap<String, String>();                
 params.put("com.sun.jersey.spi.container.ContainerRequestFilters", "com.sun.jersey.api.container.filter.PostReplaceFilter");
 serve("/*").with(GuiceContainer.class, params);

Upvotes: 2

Views: 2099

Answers (1)

Martin Matula
Martin Matula

Reputation: 7989

You should set it using the setInitParameter() on the ServletHolder instance that you use to register the Jersey servlet.

Upvotes: 1

Related Questions