Discussion:
Error: HTTP method DELETE doesn't support output
Akki
2010-02-04 14:46:27 UTC
Permalink
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.
Paul Sandoz
2010-02-05 10:40:56 UTC
Permalink
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
Post by Akki
I am trying to call the restful web service - delete method using the jersey
ClientResponse response = Client.create().resource(url).entity(mvp,
MediaType.APPLICATION_XML).delete(ClientResponse.class);
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.
java.net.ProtocolException: HTTP method DELETE doesn't support output
at
com
.sun
.jersey
.impl
.client
.urlconnection
193)
at com.sun.jersey.api.client.Client.handle(Client.java:404)
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:462)
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
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
229)
at
com
.sun
.jersey
.impl
.client
.urlconnection
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.
---------------------------------------------------------------------
moshebeeri
2011-12-24 23:49:17 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/Error-HTTP-method-DELETE-doesn-t-support-output-tp4513829p7125103.html
Sent from the Jersey mailing list archive at Nabble.com.

Loading...