Jersey error at @DELETE: "Unsupported HTTP Method: DELETE"

I am using a RESTful app in Jersey (deployed on WildFly 8.1.0.Final) but I have a problem with @DELETE test methods. All others (GET, POST, PUT) work as expected. However, when calling @DELETE I get the following error

Cross-Origin Resource Sharing (CORS) Filter: Unsupported HTTP method: DELETE

      

I am testing a RESTful interface via a plugin in Google Chrome: Advanced REST Client. How can I fix this?

Resource class: I've removed other methods for clarity.

@Path(value = "destination")
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public class DestinationResource {

public DestinationResource() {}

@DELETE
@Path(value = "/{id}")
public Response deleteDestination(@PathParam("id") Long id) {
    //Doing something
    return Response.status(Response.Status.OK).build();
}

      

}

EDIT: I added CORS.filter but still didn't work. Here is my web.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- This web.xml file is not required when using Servlet 3.0 container,
 see implementation details http://jersey.java.net/nonav/documentation/latest/jax-rs.html#d4e194 -->
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  <servlet>
    <servlet-name>Jersey Web Application</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>

    <init-param>
        <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
        <param-value>true</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>Jersey Web Application</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>

<context-param>
    <param-name>resteasy.scan</param-name>
    <param-value>false</param-value>
</context-param>
<context-param>
    <param-name>resteasy.scan.providers</param-name>
    <param-value>false</param-value>
</context-param>
<context-param>
    <param-name>resteasy.scan.resources</param-name>
    <param-value>false</param-value>
</context-param>

<filter>
    <!-- The CORS filter with parameters -->
    <filter-name>CORS</filter-name>
    <filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>

    <!-- Note: All parameters are options, if omitted the CORS
         Filter will fall back to the respective default values.
      -->
    <init-param>
        <param-name>cors.allowGenericHttpRequests</param-name>
        <param-value>true</param-value>
    </init-param>

    <init-param>
        <param-name>cors.allowOrigin</param-name>
        <param-value>*</param-value>
    </init-param>

    <init-param>
        <param-name>cors.allowSubdomains</param-name>
        <param-value>false</param-value>
    </init-param>

    <init-param>
        <param-name>cors.supportedMethods</param-name>
        <param-value>GET, HEAD, POST, PUT, OPTIONS</param-value>
    </init-param>

    <init-param>
        <param-name>cors.supportedHeaders</param-name>
        <param-value>*</param-value>
    </init-param>

    <init-param>
        <param-name>cors.exposedHeaders</param-name>
        <param-value>X-Count-records</param-value>
    </init-param>

    <init-param>
        <param-name>cors.supportsCredentials</param-name>
        <param-value>true</param-value>
    </init-param>

    <init-param>
        <param-name>cors.maxAge</param-name>
        <param-value>3600</param-value>
    </init-param>

</filter>

<filter-mapping>
    <filter-name>CORS</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

      

+3


source to share


1 answer


<init-param>
    <param-name>cors.supportedMethods</param-name>
    <param-value>GET, HEAD, POST, PUT, OPTIONS</param-value>
</init-param>

      



Do you see that it says DELETE? I do not do this.

+4


source







All Articles