users@jersey.java.net

HTTP DELETE method

From: Jonathan Hodges <hodgesz_at_gmail.com>
Date: Tue, 13 Apr 2010 07:19:36 -0600

Hi,

I am currently having trouble with getting the DELETE method to work
correctly. This may be due to my misunderstanding of the semantics for
DELETE so let me describe my scenario.

I currently have a resource with the following code snipped deployed on
Tomcat.


@DELETE
@Path("/removeUserSocialIdentity")
@Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public String removeUserSocialIdentity(UserSocialIdentityList
userSocialIdentityList) {
logger.debug("removeUserSocialIdentity");

return "OK";
}


I am trying to access this resource via the client API as follows.


             UserSocialIdentityList userSocialIdentityList = new
UserSocialIdentityList();
Set<UserSocialIdentity> userSocialIdentitySet = new
HashSet<UserSocialIdentity>();
UserSocialIdentity userSocialIdentity = new UserSocialIdentity();
userSocialIdentity.setUserUID("b5c587fe030377730010d4482d6148ea");
 Set<SocialIdentity> socialIdentitySet = new HashSet<SocialIdentity>();
SocialIdentityList socialIdentityList = new SocialIdentityList();
SocialIdentity socialIdentity = new SocialIdentity();
socialIdentity.setTypeCode("FACEBOOK");
socialIdentity.setUid("f1c5c6f8030377730010d4482c0f5d03");
socialIdentitySet.add(socialIdentity);
 socialIdentity = new SocialIdentity();
socialIdentity.setTypeCode("TWITTER");
socialIdentity.setUid("c1c5c6f8030377730010d4482c0f5d03");
socialIdentitySet.add(socialIdentity);
 socialIdentity = new SocialIdentity();
socialIdentity.setTypeCode("MYSPACE");
socialIdentity.setUid("a1c5c6f8030377730010d4482c0f5d03");
socialIdentitySet.add(socialIdentity);
 socialIdentityList.setSocialIdentitySet(socialIdentitySet);
userSocialIdentity.setSocialIdentityList(socialIdentityList);
 userSocialIdentitySet.add(userSocialIdentity);
 userSocialIdentity = new UserSocialIdentity();
userSocialIdentity.setUserUID("b5c587fe030377730010d4482d6148ea");
 socialIdentitySet = new HashSet<SocialIdentity>();
socialIdentityList = new SocialIdentityList();
socialIdentity = new SocialIdentity();
socialIdentity.setTypeCode("FACEBOOK");
socialIdentity.setUid("f1c5c6f8030377730010d4482c0f5d03");
socialIdentitySet.add(socialIdentity);
 socialIdentity = new SocialIdentity();
socialIdentity.setTypeCode("TWITTER");
socialIdentity.setUid("c1c5c6f8030377730010d4482c0f5d03");
socialIdentitySet.add(socialIdentity);
 socialIdentity = new SocialIdentity();
socialIdentity.setTypeCode("MYSPACE");
socialIdentity.setUid("a1c5c6f8030377730010d4482c0f5d03");
socialIdentitySet.add(socialIdentity);
 socialIdentityList.setSocialIdentitySet(socialIdentitySet);
userSocialIdentity.setSocialIdentityList(socialIdentityList);
 userSocialIdentitySet.add(userSocialIdentity);
 userSocialIdentityList.setUserSocialIdentity(userSocialIdentitySet);
 String response =
wr.path("removeUserSocialIdentity")
.type(MediaType.APPLICATION_JSON_TYPE)
.accept(MediaType.TEXT_PLAIN)
.header("Version", "1.0")
.put(String.class, userSocialIdentityList);
 assertTrue("Method: removeUserSocialIdentity \nMessage: Something wrong,
the returned " +
                "response is not 'OK'", response.equals("OK"));


This yields the following exception.


java.lang.IllegalStateException: reader must be on a START_ELEMENT event,
not a 8 event
at
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:352)
at
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:339)
at
com.sun.jersey.json.impl.BaseJSONUnmarshaller.unmarshalJAXBElementFromJSON(BaseJSONUnmarshaller.java:103)
at
com.sun.jersey.json.impl.BaseJSONUnmarshaller.unmarshalFromJSON(BaseJSONUnmarshaller.java:92)
at
com.sun.jersey.json.impl.provider.entity.JSONRootElementProvider.readFrom(JSONRootElementProvider.java:100)
at
com.sun.jersey.core.provider.jaxb.AbstractRootElementProvider.readFrom(AbstractRootElementProvider.java:105)
at
com.sun.jersey.spi.container.ContainerRequest.getEntity(ContainerRequest.java:444)
at
com.sun.jersey.server.impl.model.method.dispatch.EntityParamDispatchProvider$EntityInjectable.getValue(EntityParamDispatchProvider.java:137)
at
com.sun.jersey.server.impl.inject.InjectableValuesProvider.getInjectableValues(InjectableValuesProvider.java:43)
at
com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$EntityParamInInvoker.getParams(AbstractResourceMethodDispatchProvider.java:119)
at
com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$VoidOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:131)
at
com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:67)
at
com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:259)
at
com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:133)
at
com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:83)
at
com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:133)
at
com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:71)
at
com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:990)
at
com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:941)
at
com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:932)
at
com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:384)
at
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:451)
at
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:632)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)



If I change the resource to accept PUT and change the client to make a PUT
request instead of the DELETE it works perfectly. I already changed the
client to use the Apache HTTP client so I can have a response with DELETE
but I still can't seem to get past this issue. Any help would be greatly
appreciated.


Sincerely,

Jonathan