Hi folks,
I've seen this topic mentioned in the archive but I am having trouble
getting it to work. It's a pretty annoying problem. I just want all
my calls to work whether they have a trailing slash or not. In this
project we're using embedded Jetty that is being programatically
configured. So in that code I added:
Servlet servlet = new SpringServlet();
ServletHolder holder = new ServletHolder(servlet);
Map initParams = new HashMap();
initParams.put(ResourceConfig.FEATURE_REDIRECT, "true");
holder.setInitParameters(initParams);
But this seems to cause pretty unpredictable behavior. For instance
after I added that I tried making a POST to my endpoint which has a
method annotated as @POST but I get a 400 response. And the weird
thing is the debug log shows:
2010-02-10 11:40:03,382 DEBUG org.springframework.web.context.request.RequestContextListener:69 Bound
request context to thread: POST /some/path HTTP/1.1
...
2010-02-10 11:40:03,383 DEBUG org.springframework.web.context.request.RequestContextListener:89 Cleared
thread-bound request context: POST /some/path HTTP/1.1
...
2010-02-10 11:40:03,384 DEBUG org.springframework.web.context.request.RequestContextListener:69 Bound
request context to thread: GET /some/path/ HTTP/1.1
...
2010-02-10 11:40:03,385 DEBUG org.springframework.web.context.request.RequestContextListener:89 Cleared
thread-bound request context: GET /some/path/ HTTP/1.1
...
There isn't a GET call being made. It's like the POST is getting
turned into a GET for some reason. This doesn't happen when i don't
have the redirect on. Does the trailing slash thing only apply to
GETs? If that's the case shouldn't it just ignore my POST? If i have
a trailing slash in the original call it works fine.
Aside from that the redirect doesn't even work for my GETs. When i
try a GET without a trailing slash I get:
2010-02-10 11:47:15,344 DEBUG org.springframework.web.context.request.RequestContextListener:69 Bound
request context to thread: GET /some/path/c4e713e HTTP/1.1
2010-02-10 11:47:15,346 DEBUG org.springframework.web.context.request.RequestContextListener:89 Cleared
thread-bound request context: GET /some/path/c4e713e HTTP/1.1
2010-02-10 11:47:15,359 DEBUG org.springframework.web.context.request.RequestContextListener:69 Bound
request context to thread: GET /some/path/c4e713e/ HTTP/1.1
2010-02-10 11:47:15,440 DEBUG org.springframework.web.context.request.RequestContextListener:89 Cleared
thread-bound request context: GET /some/path/c4e713e/ HTTP/1.1
Which looks like it's redirecting properly but then it returns a 404.
In this case it doesn't matter whether i have a trailing slash on the
original call or not it always returns a 404. Even though I have a
GET annotated class and I've tried various combinations for the path:
@GET
@Path("/{id}/")
@GET
@Path("/{id}")
Is there something I'm missing here? For my main Path i've tried:
@Path("/some/path/")
@Path("/some/path")
@Path("/some/path*")
And probably some others.
Any ideas?
Thanks!
Chris