Discussion:
Jersey Client WebResource delete with request entity?
Rick Wager
2009-12-11 00:34:01 UTC
Permalink
Hello,

I'm attempting to use the Jersey client (1.1.4.1) and invoke the delete
(java.lang.Class<T> c, java.lang.Object requestEntity) method because
I'd like to specify the resource to be deleted via its representation.

The API for WebResouce seems to allow this - but I am unable to get this
working, I get a null ptr in the client code before it communicates to
the server. I've downloaded the source and attempted to understand why
this is happening, but to no luck. So, I'd appreciate some guidance on this.

- Is this just a stupid thing to do? A misguided way to use REST?
- I'm not using the API correctly in some way?
- ??

Thanks in advance -
Rick


(this stack captured using the source for 1.1.4.1)
com.sun.jersey.api.client.ClientHandlerException:
java.lang.NullPointerException:

at
com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:128)
at com.sun.jersey.api.client.Client.handle(Client.java:457)
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:557)
at com.sun.jersey.api.client.WebResource.delete(WebResource.java:251)
at
test.wsi.rest.ShotQueueRestTest.testDeleteShotFromQueue(ShotQueueRestTest.java:61)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at
org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.NullPointerException
at
com.sun.jersey.api.client.CommittingOutputStream.close(CommittingOutputStream.java:104)
at
com.sun.jersey.api.client.TerminatingClientHandler.writeRequestEntity(TerminatingClientHandler.java:294)
at
com.sun.jersey.client.urlconnection.URLConnectionClientHandler._invoke(URLConnectionClientHandler.java:179)
at
com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:126)
... 28 more
--
Rick Wager
Wireless Seismic
361 Centennial Parkway, Suite 230
720-242-9916, ext. 19
Louisville, CO 80027
Paul Sandoz
2009-12-11 13:01:21 UTC
Permalink
Hi Rick,

The problem is HttpURLConnection does not support the sending of
request entities for a DELETE request, and Jersey is masking that
error as a consequence of attempting to recover. So i need to fix that
error reporting. Could you log an issue?

I really do not know why HttpURLConnection has such a restriction.

You should be able to switch to using the Apache HTTP client, which
IIUC does not have such a restriction:

https://jersey.dev.java.net/nonav/apidocs/latest/contribs/jersey-apache-client/com/sun/jersey/client/apache/package-summary.html

Thanks,
Paul.
Post by Rick Wager
Hello,
I'm attempting to use the Jersey client (1.1.4.1) and invoke the
delete (java.lang.Class<T> c, java.lang.Object requestEntity) method
because I'd like to specify the resource to be deleted via its
representation.
The API for WebResouce seems to allow this - but I am unable to get
this working, I get a null ptr in the client code before it
communicates to the server. I've downloaded the source and
attempted to understand why this is happening, but to no luck. So,
I'd appreciate some guidance on this.
- Is this just a stupid thing to do? A misguided way to use REST?
- I'm not using the API correctly in some way?
- ??
Thanks in advance -
Rick
(this stack captured using the source for 1.1.4.1)
at
com
.sun
.jersey
.client
.urlconnection
128)
at com.sun.jersey.api.client.Client.handle(Client.java:457)
557)
251)
at
test
.wsi
.rest
.ShotQueueRestTest.testDeleteShotFromQueue(ShotQueueRestTest.java:61)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun
.reflect
.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun
.reflect
.DelegatingMethodAccessorImpl
.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod
$1.runReflectiveCall(FrameworkMethod.java:44)
at
org
.junit
.internal
.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at
org
.junit
.runners
.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at
org
.junit
20)
at
org
.junit
76)
at
org
.junit
50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at
org
.junit
.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at
org
31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at
org
.eclipse
.jdt
.internal
.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
at
org
.eclipse
.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org
.eclipse
.jdt
.internal
.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at
org
.eclipse
.jdt
.internal
.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at
org
.eclipse
.jdt
.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at
org
.eclipse
.jdt
197)
Caused by: java.lang.NullPointerException
at
com
.sun
.jersey
104)
at
com
.sun
.jersey
.api
.client
.TerminatingClientHandler
.writeRequestEntity(TerminatingClientHandler.java:294)
at
com
.sun
.jersey
.client
.urlconnection
179)
at
com
.sun
.jersey
.client
.urlconnection
126)
... 28 more
--
Rick Wager
Wireless Seismic
361 Centennial Parkway, Suite 230
720-242-9916, ext. 19
Louisville, CO 80027
---------------------------------------------------------------------
Paul Sandoz
2009-12-11 15:01:31 UTC
Permalink
Post by Paul Sandoz
Hi Rick,
The problem is HttpURLConnection does not support the sending of
request entities for a DELETE request, and Jersey is masking that
error as a consequence of attempting to recover. So i need to fix
that error reporting. Could you log an issue?
No need to log an issue. I have fixed things in the trunk so that the
original exception is thrown and you should see a stack trace like the
following:

java.net.ProtocolException: HTTP method DELETE doesn't support output
com.sun.jersey.api.client.ClientHandlerException:
java.net.ProtocolException: HTTP method DELETE doesn't support output
at
com
.sun
.jersey
.client
.urlconnection
.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:128)
at com.sun.jersey.api.client.Client.handle(Client.java:457)
at
com.sun.jersey.api.client.WebResource.handle(WebResource.java:557)
at
com.sun.jersey.api.client.WebResource.delete(WebResource.java:251)
at com.sun.jersey.impl.container.grizzly.web.HttpMethodTest.testDelete
(HttpMethodTest.java:113)
Caused by: java.net.ProtocolException: HTTP method DELETE doesn't
support output
at
sun
.net
.www
.protocol
.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:873)
at
com.sun.jersey.client.urlconnection.URLConnectionClientHandler
$1$1.getOutputStream(URLConnectionClientHandler.java:200)
at
com
.sun
.jersey
.api
.client.CommittingOutputStream.commitWrite(CommittingOutputStream.java:
114)
at
com
.sun
.jersey
.api.client.CommittingOutputStream.write(CommittingOutputStream.java:86)

Paul.
moshebeeri
2011-12-24 23:48:06 UTC
Permalink
The problem is that the default client produces synchronous WebResource to
grab the response back.
When using @DELETE there is no need to synchronize request for idempotent
requirement.
I just changes the call to the following format and it works like charm

ClientConfig clientConfig = new DefaultClientConfig();
clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING,
Boolean.TRUE);
Client c = Client.create(clientConfig);
AsyncWebResource ar =
c.*asyncResource*("http://127.0.0.1:8888/r/at/delete");
r.delete(Status.class, reqStatus);

Code Well,
Moshe Beeri.


--
View this message in context: http://jersey.576304.n2.nabble.com/Jersey-Client-WebResource-delete-with-request-entity-tp4150141p7125102.html
Sent from the Jersey mailing list archive at Nabble.com.

arul
2011-09-17 11:47:29 UTC
Permalink
hi-
I am getting the below error when I call Delete method from jersey client
com.sun.jersey.api.client.ClientHandlerException:
java.net.ProtocolException: HTTP method DELETE doesn't support output

My WebService code
@DELETE @Path("delete")
@Consumes(MediaType.APPLICATION_XML)
public Response unSubscriberAssetRequest(SubscriberDetail subscr) {
logger.info("Inside method unSubscribeAssetRequest
------------------------------->");
System.out.println("Id --->"+subscr.getAssetIdentifier());
System.out.println("Type--->"+subscr.getAssetIdentifierType());
return Response.status(Response.Status.ACCEPTED).build();
}



My Client code
ClientResponse response =
webResource.path("subscriberResource").path("subscriber").path("delete").accept(MediaType.APPLICATION_XML).entity(subscriberDetailXML).delete(ClientResponse.class);

Would you please reply someone how to resolve the issue?
Thanks
Arul

--
View this message in context: http://jersey.576304.n2.nabble.com/Jersey-Client-WebResource-delete-with-request-entity-tp4150141p6803742.html
Sent from the Jersey mailing list archive at Nabble.com.
Loading...