1

I am using resteasy. Here is a code to delete a resource.

@DELETE
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Path("/{id:\\d+}")
public Response removeResource(@PathParam("id") int id){
    .........................
    .. code to delete resource and return Response object ..
    .........................
}

This code is working fine. But when I try to pass some parameter to delete request. I am getting UnsupportedMediaException

@DELETE
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Path("/{id:\\d+}")
public Response removeResource(@PathParam("id") int id, Map<String, Object> source){
    .........................
    .. code to delete resource and return Response object ..
    .........................
}

I need to send some parameter for some reason. Moreover when I just replace delete request with put request i.e. replacing @DELETE with @PUT, the code works fine.

Is there any way to pass parameter to delete request.

And at front end I was using angularjs's $resource to send DELETE request

var r = $Resource(/rest/resources/1);    // for debugging purpose I made id 1
r.remove({"key1":"data1", "key2", "data2"});

Edit :
Stack trace from server

11:43:25,767 ERROR [org.jboss.resteasy.resteasy_jaxrs.i18n] (default task-7) RESTEASY002010: Failed to execute: javax.ws.rs.NotSupportedException: RESTEASY003065: Cannot consume content type
at org.jboss.resteasy.core.registry.SegmentNode.match(SegmentNode.java:382)
at org.jboss.resteasy.core.registry.SegmentNode.match(SegmentNode.java:116)
at org.jboss.resteasy.core.registry.RootNode.match(RootNode.java:43)
at org.jboss.resteasy.core.registry.RootClassNode.match(RootClassNode.java:48)
at org.jboss.resteasy.core.ResourceMethodRegistry.getResourceInvoker(ResourceMethodRegistry.java:445)
at org.jboss.resteasy.core.SynchronousDispatcher.getInvoker(SynchronousDispatcher.java:257)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:194)
at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:221)
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)

Response at front-end

Status Code: 415 Unsupported Media Type
Connection: keep-alive
Content-Length: 0
Date: Wed, 01 Jun 2016 06:13:25 GMT
Server: WildFly/10
x-powered-by: Undertow/1
afzalex
  • 8,598
  • 2
  • 34
  • 61
  • Can you show the complete stacktrace – Paul Samsotha Jun 01 '16 at 05:59
  • Also some servers don't support a body with DELETE. Though the `UnsupportedMediaException` sounds like a RESTEasy exception, so the error is happening at the application level. I am not quite sure RESTEasy's rules regarding this. Worst case, just send the data in query parameters – Paul Samsotha Jun 01 '16 at 06:01
  • @peeskillet I added stacktrace of web server and response at front end – afzalex Jun 01 '16 at 06:20
  • Maybe this is a [client side problem](http://stackoverflow.com/q/22186671/2587435). What details does the browser developer tools show about the request? Have you checked it out? – Paul Samsotha Jun 01 '16 at 06:28

1 Answers1

1

You have requested that the Content-Type be "application/json" AngularJS defaults to text/plain.

If you have a new enough version of AngularJS(1.1.3) you can customise the resource object to include the Content-Type you requested. You should be able to modify your resource definition to include the Content-Type for a delete request

var r = $Resource(/rest/resources/1, {},
   remove:{
      method:"DELETE",
      isArray:false,
      headers:{'Content-Type':'application/json; charset=UTF-8'} 
   }
);

For more info see Answer One and Angular issue

Community
  • 1
  • 1
Tim
  • 50
  • 1
  • 2
  • 18