0

I'm making a call from jQGrid to a Guice servlet that has the following binding:

@Produces({MediaType.APPLICATION_JSON})
@Path("/{param}")
public String getJson(@PathParam("param") String param) {
    ...
    return return json.toString();
}

Requesting the url directly, I can see the JSON. When jqgrid executes the request, I get 405 method not allowed response. I've seen this happen before when the returning page doesn't have the Content-type set to "text/json" (jqgrid is not very flexible here).

HERE IS THE REQUEST: Key Value Request POST /myapp/json/jqgrid/json ... HTTP/1.1 x-requested-with XMLHttpRequest Accept-Language en-us Referer http://localhost:8080/myapp/myPage... Accept application/json, text/javascript, / Content-Type application/x-www-form-urlencoded Accept-Encoding gzip, deflate User-Agent Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0) Host localhost:8080 Content-Length 63 Connection Keep-Alive Cache-Control no-cache

HERE IS THE RESPONSE: Key Value Response HTTP/1.1 405 Method Not Allowed Server Apache-Coyote/1.1 Allow GET,OPTIONS,HEAD Content-Type text/html;charset=utf-8 Content-Length 1034

Any thoughts on how to get the guice servlet to set the Content-type to "text/json" and allow the response?

JStark
  • 2,788
  • 2
  • 29
  • 37
  • "text/json" is wrong `Content-type` for the JSON response. Correct `Content-type` is "application/json". See [here](http://stackoverflow.com/questions/477816/the-right-json-content-type/477819#477819) – Oleg Aug 12 '11 at 15:20
  • The request was actually "Accept application/json" (see my REQUEST output above). The problem is the response from the Guice servlet is coming back as Content-Type text/html;charset=utf-8. In Guice I've tried several @Produces combinations to get the application/json with no luck although MediaType.APPLICATION_JSON should generate the correct response. – JStark Aug 12 '11 at 16:54

1 Answers1

0

This one is solved. I was using a @GET annotation and jQGrid was issuing a post. I changed the @POST and it started working. This may solve the problem for others with related 405 errors.

JStark
  • 2,788
  • 2
  • 29
  • 37