Search code examples
javaapache-httpclient-4.xjersey-client

java.net.ProtocolException: HTTP method DELETE doesn't support output


I am having this error while using jersey-client-1.19. All the googling I have done points to a bug or unnecessary limitation in HttpUrlConnection, especially in java 7.

I have been advised by some to move to java 8, I am not ready for that now.

I have already heard suggestions of transferring all my parameters to path but this can not work for me as the API requires me to pass certain authentication details as a json request body.

I have already looked at several answers related to this question including How do Jersey-client and Apache HTTP Client compare?. which suggests explicitely defining Apache's httpclient for jersey. So I thought there should be a standard integration of jersey-client-1.19 with Apache httpclient in the back which is indeed confirmed by Paul Sandoz answer. However all the links he has offered there are down.

Does anyone know of any such integration or alternatively how I can just resolve this issue?


Solution

  • For anyone who still faces this problem, I am adding the hot-fix that worked for me. Basically, we resolved to send HTTP DELETE requests as POST to enable us to add a request body, with an additional {"delete":true} field in the JSON body. This will only work if it is the same team that is working on the REST service or if you are in position to add the corresponding check in the backend.