Alex Rivera | Logout

Jersey returns HTTP Status 405 - Method Not Allowed

Asked 2012-07-18T22:03:07.580
21

I have a very simple endpoint using Jersey. My URL is static, it doesn't require any request parameters. It looks like this:

@GET
@Path("/mydata")
@Produces(javax.ws.rs.core.MediaType.APPLICATION_JSON)  
public String getData()  {
  return "{'name': 'value'}";
}

However, whenever I request this URL, I always receive a HTTP Status code of 405 - Method Not Allowed.

The weird thing is, that if I change the @Path annotation and define a path variable e.g. @Path("/chart/{blah}") it works fine.

Does anyone have an idea why I have to define a path variable to get this to work? I don't need a path variable and it seems silly to add one just to get a 200 response.

Edit
Report

1 Answer

6

Annotate the class instead of the method:

@Path("/mydata")
public class MyClass(){

@GET
@Produces(javax.ws.rs.core.MediaType.APPLICATION_JSON)  
public String getData()  {
  return "{'name': 'value'}";
}

}

I don't know why but it also gives me problems the other way

answered 2012-07-19T09:04:51.550

Your Answer