Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Cannot set a request body for a DELETE method." #44

Open
olivermt opened this issue Apr 24, 2015 · 7 comments
Open

"Cannot set a request body for a DELETE method." #44

olivermt opened this issue Apr 24, 2015 · 7 comments

Comments

@olivermt
Copy link

http://stackoverflow.com/questions/299628/is-an-entity-body-allowed-for-an-http-delete-request

There is nothing in the spec that says this is disallowed.

Is there any particular reason that this is not implemented?

@jonpeterson
Copy link

I ran into this same issue.

As a workaround for this:

public class CustomRESTClient extends RESTClient {

    private static class HttpDeleteWithEntity extends HttpEntityEnclosingRequestBase {
        public final static String METHOD_NAME = "DELETE";

        @Override
        public String getMethod() {
            return METHOD_NAME;
        }
    }


    public CustomRESTClient(Object defaultURI) throws URISyntaxException {
        super(defaultURI);
    }

    @Override
    public Object delete(Map<String,?> args) throws URISyntaxException, ClientProtocolException, IOException {
        return doRequest(new RequestConfigDelegate(args, new HttpDeleteWithEntity(), null));
    }
}

@tankchintan
Copy link

@jonpeterson I did as you have mentioned here, but for whatever reason the overridden delete method is not getting called & I still keep getting the error.

import groovyx.net.http.Method;
import groovyx.net.http.RESTClient;
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Map;

public class RichRESTClient extends RESTClient {

  private static class HttpDeleteWithEntity extends HttpEntityEnclosingRequestBase {

    @Override
    public String getMethod() {
      return Method.DELETE.name();
    }
  }

  public RichRESTClient(Object defaultURI) throws URISyntaxException {
    super(defaultURI);
  }

  @Override
  public Object delete(Map<String, ?> args) throws URISyntaxException, IOException {
    return this.doRequest(new RequestConfigDelegate(args, new HttpDeleteWithEntity(), null));  
  }
}

@Hubbitus
Copy link

@tankchintan, do you use then RichRESTClient instead of RESTClient? That solution help me.

@rtretyak
Copy link

In case if somebody's still having this issue, the more compact solution is:

RESTClient.metaClass.delete = { Map<String,?> args ->  
	def deleteRequestWithEntity = [getMethod: { "DELETE" }] as HttpEntityEnclosingRequestBase
	delegate.doRequest(new RequestConfigDelegate(delegate, args, deleteRequestWithEntity, null));
}

@nkumarclm
Copy link

@rtretyak Thanks for your compact solution. very helpful.

@arpithavaddu
Copy link

Groovyc: unable to resolve class RequestConfigDelegate
I am getting this error when I try to use this. RequestConfigDelegate is protected inner class
Any suggestions on how to get it working.

@rtretyak
Copy link

@arpithavaddu
Are you missing the import statement? import groovyx.net.http.HTTPBuilder.RequestConfigDelegate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants