I'm doing a REST application. I have made the GET method without issues, however, when I implement the POST method, it says that I don't have the OPTIONS method implemented for it. I am doing the OPTIONS method for URI:
http://192.168.1.26:8080/sellAppWeb/api/object/
I have the POST and OPTIONS methods:
@OPTIONS
@Produces("application/json; charset=UTF-8")
public Response options() {
return Response.ok().build();
}
@Override
@POST
public Response save(CervejaDTO cervejaDTO) {
cervejaController.register(cervejaDTO);
return Response.ok(cervejaDTO).build();
}
Then I am made the DELETE method and again it says that I don't have a OPTIONS method. Then I need to make another OPTIONS method, which has an ID in the URI end. For example to delete a object with id = 3:
http://192.168.1.26:8080/sellAppWeb/api/object/3
I need to have another OPTIONS with same structure of DELETE URI:
@OPTIONS
@Path("/{id}")
@Produces("application/json; charset=UTF-8")
public Response optionsDelete(@PathParam("id") Integer id) {
return Response.ok().build();
}
@Override
@POST
public Response save(CervejaDTO cervejaDTO) {
cervejaController.register(cervejaDTO);
return Response.ok(cervejaDTO).build();
}
Does anyone have a way to do a generic OPTIONS for all REST requests?
the web.xml:
<display-name>Testes de serviços REST</display-name>
<description>Testes de serviços REST</description>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<context-param>
<param-name>resteasy.scan</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>resteasy.servlet.mapping.prefix</param-name>
<param-value>/api</param-value>
</context-param>
<context-param>
<param-name>resteasy.providers</param-name>
<param-value>br.com.sell.app.exception.handler.DefaultExceptionHandler</param-value>
</context-param>
<listener>
<listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
</listener>
<servlet>
<servlet-name>resteasy-servlet</servlet-name>
<servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>resteasy-servlet</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>