From 455a3d7d8a7fef683d8d2d3b26cf3c1f85bca5a6 Mon Sep 17 00:00:00 2001 From: tulioccalazans Date: Tue, 23 Jan 2018 16:15:01 -0200 Subject: [PATCH] New feature: Allows to send the body in HTTP PUT calls. --- .../net/rest/AbstractHTTPRestfulClient.java | 39 +++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/fly-rest/src/br/com/softctrl/net/rest/AbstractHTTPRestfulClient.java b/fly-rest/src/br/com/softctrl/net/rest/AbstractHTTPRestfulClient.java index 33c35ef..0b344a9 100644 --- a/fly-rest/src/br/com/softctrl/net/rest/AbstractHTTPRestfulClient.java +++ b/fly-rest/src/br/com/softctrl/net/rest/AbstractHTTPRestfulClient.java @@ -397,8 +397,8 @@ protected Response perform(final Request request) { final HttpURLConnection connection = newURLConnection(request.getHttpMethod(), request.getUrl()); try { connection.setDoInput(true); - final boolean isPOST = HttpMethod.POST.equals(request.getHttpMethod()); - connection.setDoOutput(isPOST); + final boolean isPostOrPut = HttpMethod.POST.equals(request.getHttpMethod()) || HttpMethod.PUT.equals(request.getHttpMethod(); + connection.setDoOutput(isPostOrPut); // Basic HTTP Authentication if (Objects.nonNull(this.mBasicHttpAuthentication)) { @@ -415,7 +415,7 @@ protected Response perform(final Request request) { } // If is a POST: - if (isPOST) { + if (isPostOrPut) { // If exists parameters: final String parameters = request.getStringParameters(); if (Objects.nonNull(parameters)) { @@ -601,6 +601,39 @@ public synchronized final void post(final String url, final R body, final Parame this.send(HttpMethod.POST, url, body, parameters, properties); } + /** + * + * @param url + */ + public synchronized final void put(final String url) { + this.put(url, mBody, + this.getValidParameters(), + this.getValidProperties()); + } + + /** + * @param url + * @param body + * @param parameters + */ + public synchronized final void put(final String url, final R body, final Parameter... parameters) { + + this.put(url, body, (Objects.isNullOrEmpty(parameters) ? this.getValidParameters() : parameters), + this.getValidProperties()); + + } + + /** + * + * @param url + * @param body + * @param parameters + * @param properties + */ + public synchronized final void put(final String url, final R body, final Parameter[] parameters, final Property[] properties) { + this.send(HttpMethod.PUT, url, body, parameters, properties); + } + /** * * @param url