users@jersey.java.net

Re: [Jersey] Jersey Client WebResource delete with request entity?

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Fri, 11 Dec 2009 14:01:21 +0100

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.

On Dec 11, 2009, at 1:34 AM, Rick Wager wrote:

> 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
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>