users@jersey.java.net

Re: [Jersey] HTTP DELETE method

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 13 Apr 2010 15:44:33 +0200

Hi Jonathan,

The stack trace appears to have nothing to do with the DELETE method
and seems to be a problem with the parsing of the JSON request entity
using the JSON JAXB support. I do not see how switching from @DELETE
to @PUT would change anything in this respect.

Note that there is a restriction in the HttpURLConnection
implementation that for some crazy reason does not support DELETE when
sending a request entity. And you rightly guess the Apache HTTP client
does not have such a restriction.

Can you enable client and server side logging.

On the client side do:

   Client c = ...
   c.add(new LoggingFilter());

and on the server side:

   https://jersey.dev.java.net/nonav/apidocs/latest/jersey/com/sun/jersey/api/container/filter/LoggingFilter.html

as that might give some clues.

Paul.

On Apr 13, 2010, at 3:19 PM, Jonathan Hodges wrote:

> 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