users@jersey.java.net

Re: [Jersey] Error: HTTP method DELETE doesn't support output

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Fri, 05 Feb 2010 11:40:56 +0100

Hi Akki,

This is a rather bizarre and pointless limitation in the
implementation in HttpURLConnection, and i have no idea why such a
limitation was implemented. Namely HttpURLConnection does not support
the sending of a request entity for a DELETE method.

Two possible solutions:

1) Use the Apache HTTP client integration, see:

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

2) Use POST with the override header, X-HTTP-Method-Override, which
says you really mean DELETE. This requires the server understand such
a header (there is a server filter in Jersey for this [1]).

Paul.

[1] https://jersey.dev.java.net/nonav/apidocs/latest/jersey/com/sun/jersey/api/container/filter/PostReplaceFilter.html

On Feb 4, 2010, at 3:46 PM, Akki wrote:

>
> I am trying to call the restful web service - delete method using
> the jersey
> client (using following piece of code):
>
> ClientResponse response = Client.create().resource(url).entity(mvp,
> MediaType.APPLICATION_XML).delete(ClientResponse.class);
>
> But, I am getting the error message:
> com.sun.jersey.api.client.ClientHandlerException:
> java.net.ProtocolException: HTTP method DELETE doesn't support output
>
> Complete trace is given below.
>
> Could you please let me know if this error is fixed OR is there any
> other
> way in which I can make this call? I also tried calling it with
> ApacheHttpClient but, as per my understanding it is used to make
> simple GET
> and POST requests (not DELETE) to a Web resource.
>
> Error trace:
> com.sun.jersey.api.client.ClientHandlerException:
> java.net.ProtocolException: HTTP method DELETE doesn't support output
> at
> com
> .sun
> .jersey
> .impl
> .client
> .urlconnection
> .URLConnectionClientHandler.handle(URLConnectionClientHandler.java:
> 193)
> at com.sun.jersey.api.client.Client.handle(Client.java:404)
> at com.sun.jersey.api.client.WebResource.handle(WebResource.java:462)
> at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:
> 64)
> at
> com.sun.jersey.api.client.WebResource
> $Builder.delete(WebResource.java:420)
> at
> com
> .sonymusic
> .mediapublisher
> .test
> .resources
> .TestMediaResourceJersey
> .testDeleteMediaGroupsAndAssets(TestMediaResourceJersey.java:177)
> 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 junit.framework.TestCase.runTest(TestCase.java:164)
> at junit.framework.TestCase.runBare(TestCase.java:130)
> at junit.framework.TestResult$1.protect(TestResult.java:110)
> at junit.framework.TestResult.runProtected(TestResult.java:128)
> at junit.framework.TestResult.run(TestResult.java:113)
> at junit.framework.TestCase.run(TestCase.java:120)
> at junit.framework.TestSuite.runTest(TestSuite.java:228)
> at junit.framework.TestSuite.run(TestSuite.java:223)
> at
> org
> .junit
> .internal.runners.OldTestClassRunner.run(OldTestClassRunner.java:35)
> at
> org
> .eclipse
> .jdt
> .internal
> .junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
> at
> org
> .eclipse
> .jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
> at
> org
> .eclipse
> .jdt
> .internal
> .junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
> at
> org
> .eclipse
> .jdt
> .internal
> .junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
> at
> org
> .eclipse
> .jdt
> .internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
> at
> org
> .eclipse
> .jdt
> .internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:
> 196)
> Caused by: java.net.ProtocolException: HTTP method DELETE doesn't
> support
> output
> at
> sun
> .net
> .www
> .protocol
> .http.HttpURLConnection.getOutputStream(HttpURLConnection.java:886)
> at
> com
> .sun
> .jersey
> .impl
> .client
> .urlconnection
> .URLConnectionClientHandler
> .writeEntity(URLConnectionClientHandler.java:313)
> at
> com
> .sun
> .jersey
> .impl
> .client
> .urlconnection
> .URLConnectionClientHandler._invoke(URLConnectionClientHandler.java:
> 229)
> at
> com
> .sun
> .jersey
> .impl
> .client
> .urlconnection
> .URLConnectionClientHandler.handle(URLConnectionClientHandler.java:
> 191)
> ... 24 more
>
> --
> View this message in context: http://n2.nabble.com/Error-HTTP-method-DELETE-doesn-t-support-output-tp4513829p4513829.html
> Sent from the Jersey mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>