diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/api/rest/httputils/HTTPCall.java b/src/main/java/org/gcube/informationsystem/resourceregistry/api/rest/httputils/HTTPCall.java index dde78e8..6152e42 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/api/rest/httputils/HTTPCall.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/api/rest/httputils/HTTPCall.java @@ -1,6 +1,7 @@ package org.gcube.informationsystem.resourceregistry.api.rest.httputils; import java.io.BufferedReader; +import java.io.DataOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -41,7 +42,30 @@ public class HTTPCall { protected final String path; protected final HTTPMETHOD method; protected final String urlParameters; - + protected final String body; + + /** + * @param path + * @param method + * @param requestProperties + * @throws UnsupportedEncodingException + */ + public HTTPCall(String path, HTTPMETHOD method, + Map parameters, String body) + throws UnsupportedEncodingException { + super(); + this.path = path; + this.method = method; + this.urlParameters = getParametersDataString(parameters); + this.body = body; + } + + public HTTPCall(String path, HTTPMETHOD method, + Map parameters) + throws UnsupportedEncodingException { + this(path, method, parameters, null); + } + protected String getParametersDataString( Map parameters) throws UnsupportedEncodingException { @@ -68,20 +92,7 @@ public class HTTPCall { return result.toString(); } - /** - * @param path - * @param method - * @param requestProperties - * @throws UnsupportedEncodingException - */ - public HTTPCall(String path, HTTPMETHOD method, - Map parameters) - throws UnsupportedEncodingException { - super(); - this.path = path; - this.method = method; - this.urlParameters = getParametersDataString(parameters); - } + /** * @return the path @@ -131,6 +142,16 @@ public class HTTPCall { connection.setRequestProperty("User-Agent", userAgent); connection.setRequestMethod(method.toString()); + + + if (body != null + && (method == HTTPMETHOD.POST || method == HTTPMETHOD.PUT)) { + DataOutputStream wr = new DataOutputStream( + connection.getOutputStream()); + wr.writeBytes(body); + wr.flush(); + wr.close(); + } return connection; }