1
1
package com .sendgrid ;
2
2
3
3
import org .apache .http .Header ;
4
+ import org .apache .http .annotation .NotThreadSafe ;
4
5
import org .apache .http .client .ResponseHandler ;
5
6
import org .apache .http .client .methods .CloseableHttpResponse ;
7
+ import org .apache .http .client .methods .HttpEntityEnclosingRequestBase ;
6
8
import org .apache .http .client .methods .HttpDelete ;
7
9
import org .apache .http .client .methods .HttpGet ;
8
10
import org .apache .http .client .methods .HttpPatch ;
33
35
import java .util .Map ;
34
36
import java .util .Scanner ;
35
37
38
+ // Hack to get DELETE to accept a request body
39
+ @ NotThreadSafe
40
+ class HttpDeleteWithBody extends HttpEntityEnclosingRequestBase {
41
+ public static final String METHOD_NAME = "DELETE" ;
42
+
43
+ public String getMethod () {
44
+ return METHOD_NAME ;
45
+ }
46
+
47
+ public HttpDeleteWithBody (final String uri ) {
48
+ super ();
49
+ setURI (URI .create (uri ));
50
+ }
51
+ }
52
+
36
53
/**
37
54
* Class Client allows for quick and easy access any REST or REST-like API.
38
55
*/
@@ -286,11 +303,11 @@ public Response delete(Request request) throws URISyntaxException, IOException {
286
303
CloseableHttpResponse serverResponse = null ;
287
304
Response response = new Response ();
288
305
URI uri = null ;
289
- HttpDelete httpDelete = null ;
306
+ HttpDeleteWithBody httpDelete = null ;
290
307
291
308
try {
292
309
uri = buildUri (request .baseUri , request .endpoint , request .queryParams );
293
- httpDelete = new HttpDelete (uri .toString ());
310
+ httpDelete = new HttpDeleteWithBody (uri .toString ());
294
311
} catch (URISyntaxException ex ) {
295
312
throw ex ;
296
313
}
@@ -301,6 +318,12 @@ public Response delete(Request request) throws URISyntaxException, IOException {
301
318
}
302
319
}
303
320
321
+ try {
322
+ httpDelete .setEntity (new StringEntity (request .body ));
323
+ } catch (IOException ex ) {
324
+ throw ex ;
325
+ }
326
+
304
327
try {
305
328
serverResponse = httpClient .execute (httpDelete );
306
329
response = getResponse (serverResponse );
0 commit comments