users@jersey.java.net

Re: [Jersey] Trailing slash redirect

From: Chris Carrier <ctcarrier_at_gmail.com>
Date: Wed, 17 Feb 2010 09:03:51 -0800

Awesome Paul thanks for the help I'll give that a shot. I figured it
was something in the interaction between all the different systems.

Thanks!
Chris

On Wed, Feb 17, 2010 at 2:54 AM, Paul Sandoz <Paul.Sandoz_at_sun.com> wrote:
> Hi Chris,
>
> The issue is independent of Spring and is related to a possible bug with
> Jetty.
>
> In you Main class you have
>
>        root.addServlet(holder, "/");
>
> change it to:
>
>        root.addServlet(holder, "/*");
>
> and things should work as documented.
>
> The issue is that when "/" is declared in Jetty it returns, what i consider
> to be, incorrect information via the HttpServletRequest and Jersey gets
> confused because of that.
>
> Below is the Main.main method i used to configure Jersey and enable tracing
> and logging.
>
> Paul.
>
>    public static void main(String[] args) throws Exception {
>        // create the server
>        log.info("Starting redirect core on port " + PORT);
>        server = new Server(PORT);
>        Context root = new Context(server, "/", Context.NO_SESSIONS);
>
>        root.getInitParams().put("contextConfigLocation",
> "classpath:/META-INF/spring/applicationContext.xml");
>        root.addEventListener(new ContextLoaderListener());
>        root.addEventListener(new RequestContextListener());
>
>        Servlet servlet = new SpringServlet();
>        ServletHolder holder = new ServletHolder(servlet);
>        Map initParams = new HashMap();
>        initParams.put(ResourceConfig.FEATURE_REDIRECT, "true");
>        initParams.put(ResourceConfig.FEATURE_TRACE, "true");
>
>  initParams.put("com.sun.jersey.spi.container.ContainerRequestFilters",
> "com.sun.jersey.api.container.filter.LoggingFilter");
>
>  initParams.put("com.sun.jersey.spi.container.ContainerResponseFilters",
> "com.sun.jersey.api.container.filter.LoggingFilter");
>        holder.setInitParameters(initParams);
>        root.addServlet(holder, "/*");
>
>        // add shutdown hook
>        Thread monitor = new MonitorThread();
>        monitor.start();
>        server.start();
>    }
>
>
>
> On Feb 12, 2010, at 7:17 PM, Chris Carrier wrote:
>
>> Hi Paul,
>>
>> I'm not sure why the additional logging didn't work.  We're
>> configuring our Jetty programatically (no web.xml) so I find it kind
>> of tricky to get it configured just so.  What I did do is create a
>> really simple Maven app with tests that show the problem I'm having.
>> Like you say we have a lot of different components so I can't say this
>> is a Jersey problem but I would love your input.  Assuming attachments
>> work i'll attach the project as a zip and you should be able to either
>> run the tests with normal 'mvn test' or run the Main class.
>>
>> It's pretty obvious but what I have is two GET endpoints one with a
>> @Path with a '/' at the end and the other without.  In both cases i
>> can only reach it with a trailing slash in my URL.
>>
>> Let me know what you think.
>>
>> Thanks!
>> Chris
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>