Added constructor with body content
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry-api@144249 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
bf25323574
commit
ab6ef39199
|
@ -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<C> {
|
|||
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<String, String> 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<String, String> parameters)
|
||||
throws UnsupportedEncodingException {
|
||||
this(path, method, parameters, null);
|
||||
}
|
||||
|
||||
protected String getParametersDataString(
|
||||
Map<String, String> parameters)
|
||||
throws UnsupportedEncodingException {
|
||||
|
@ -68,20 +92,7 @@ public class HTTPCall<C> {
|
|||
return result.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param path
|
||||
* @param method
|
||||
* @param requestProperties
|
||||
* @throws UnsupportedEncodingException
|
||||
*/
|
||||
public HTTPCall(String path, HTTPMETHOD method,
|
||||
Map<String, String> parameters)
|
||||
throws UnsupportedEncodingException {
|
||||
super();
|
||||
this.path = path;
|
||||
this.method = method;
|
||||
this.urlParameters = getParametersDataString(parameters);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the path
|
||||
|
@ -131,6 +142,16 @@ public class HTTPCall<C> {
|
|||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue