I'm writing a RESTful Web service. Technologies that I use:
- Eclipse EE Kepler IDE
- GlassFish 3 (based on Java 6)
- Jersey
- JDK v7
When I annotate a Java method with, for example, the @DELETE
annotation
I get the following HTTP error (invoked via URI):
HTTP Status 405 - Method Not Allowed
I would like to know how to enable/disable (so that to enable/disable the above HTTP error) those methods (PUT, HEAD, etc.) and at which level it can be done (Glassfish, Web.xml, etc). As well, can you invoke all of those resource methods (annotated with HTTP method type) from either Web browser's URI, within the <form>
, or stand-alone client application (non-browser)?
For example, whether or not the following config line on deployment descriptor is present, it makes no difference:
<security-constraint>
<web-resource-collection>
<web-resource-name>RESTfulServiceDrill</web-resource-name>
<url-pattern>/drill/rest/resource/*</url-pattern>
<http-method>DELETE</http-method>
</web-resource-collection>
Of course, one's can disable a specific resource method by throwing an exception from it (and map it to an HTTP error) as the indication of it. That would indicate that the implementation is not available, for example.
So far, only @GET and @POST (on the <form>
) resource methods work out, the other annotated methods, such as @POST (via URI), @PUT, @DELETE, @OPTIONS returns the above HTTP error. And this is where my question needs solutions. Why does the mentioned resource methods cause HTTP error when the former two don't?
An example of a resource method:
@DELETE
@Consumes(MediaType.TEXT_PLAIN)
@Produces(MediaType.TEXT_PLAIN)
@Path("/getDelete/{value}/{cat}")
public String getDelete(@PathParam("value") String value, @PathParam("cat") String cat){
return value+" : "+cat;
}
Invoking URL:
<a href= "/RESTfulServiceDrill/rest/v6/exception/getDelete/Animal/cat">getDelete</a>
The deployment descriptor is empty, except for the above lines of XML code. So far, I made the app to work by using annotations, no Web.xml (only contains some default values, such as index.jsp files).
Any ideas out there?