Class HTTPCallsUtils
- java.lang.Object
-
- org.gcube.datatransfer.resolver.util.HTTPCallsUtils
-
public class HTTPCallsUtils extends Object
The Class HTTPCallsUtils. copied by Geosolution- Author:
- Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Apr 5, 2016
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classHTTPCallsUtils.HttpResponseThe Class HttpResponse.
-
Constructor Summary
Constructors Constructor Description HTTPCallsUtils()Instantiates a new HTTP utils.HTTPCallsUtils(String userName, String password)Instantiates a new HTTP utils.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleandelete(String url)Delete.booleanexists(String url)Used to query for REST resources.HTTPCallsUtils.HttpResponseget(String url)Performs an HTTP GET on the given URL.org.apache.commons.httpclient.HttpClientgetClient()Gets the client.protected static StringgetGeoNetworkErrorMessage(InputStream msg)Gets the geo network error message.protected static StringgetGeoNetworkErrorMessage(String msg)Gets the geo network error message.StringgetLastContentType()Gets the last content type.intgetLastHttpStatus()Gets the last http status.booleanhttpPing(String url)Http ping.booleanisIgnoreResponseContentOnSuccess()Checks if is ignore response content on success.InputStreampost(String url, File file, String contentType)POSTs a File to the given URL.InputStreampost(String url, InputStream content, String contentType)POSTs a Stream content to the given URL.InputStreampost(String url, InputStream content, String contentType, Map<String,String[]> parameterMap)POSTs a Stream content to the given URL.InputStreampost(String url, String content, String contentType)POSTs a String to the given URL.InputStreampost(String url, org.apache.commons.httpclient.methods.RequestEntity requestEntity, Map<String,String[]> parameterMap)Performs a POST to the given URL.InputStreampostXml(String url, InputStream content)POSTs a Stream content representing an XML document to the given URL.InputStreampostXml(String url, String content)POSTs a String representing an XML document to the given URL.InputStreamput(String url, File file, String contentType)PUTs a File to the given URL.InputStreamput(String url, String content, String contentType)PUTs a String to the given URL.InputStreamput(String url, org.apache.commons.httpclient.methods.RequestEntity requestEntity)Performs a PUT to the given URL.InputStreamputXml(String url, String content)PUTs a String representing an XML document to the given URL.protected InputStreamsend(org.apache.commons.httpclient.methods.EntityEnclosingMethod httpMethod, String url, org.apache.commons.httpclient.methods.RequestEntity requestEntity)Send an HTTP request (PUT or POST) to a server.protected InputStreamsendPost(org.apache.commons.httpclient.methods.EntityEnclosingMethod httpMethod, String url, org.apache.commons.httpclient.methods.RequestEntity requestEntity)Send an HTTP request (PUT or POST) to a server.voidsetIgnoreResponseContentOnSuccess(boolean ignoreResponseContentOnSuccess)Sets the ignore response content on success.voidsetXmlContentType(String xmlContentType)Sets the xml content type.
-
-
-
Method Detail
-
setXmlContentType
public void setXmlContentType(String xmlContentType)
Sets the xml content type.- Parameters:
xmlContentType- the new xml content type
-
getLastHttpStatus
public int getLastHttpStatus()
Gets the last http status.- Returns:
- the last http status
-
isIgnoreResponseContentOnSuccess
public boolean isIgnoreResponseContentOnSuccess()
Checks if is ignore response content on success.- Returns:
- true, if is ignore response content on success
-
setIgnoreResponseContentOnSuccess
public void setIgnoreResponseContentOnSuccess(boolean ignoreResponseContentOnSuccess)
Sets the ignore response content on success.- Parameters:
ignoreResponseContentOnSuccess- the new ignore response content on success
-
get
public HTTPCallsUtils.HttpResponse get(String url) throws MalformedURLException
Performs an HTTP GET on the given URL.- Parameters:
url- The URL where to connect to.- Returns:
- The HTTP response as a String if the HTTP response code was 200 (OK).
- Throws:
MalformedURLException- the malformed url exception
-
getLastContentType
public String getLastContentType()
Gets the last content type.- Returns:
- the lastContentType
-
getClient
public org.apache.commons.httpclient.HttpClient getClient()
Gets the client.- Returns:
- the client
-
putXml
public InputStream putXml(String url, String content)
PUTs a String representing an XML document to the given URL.- Parameters:
url- The URL where to connect to.content- The XML content to be sent as a String.- Returns:
- The HTTP response as a String if the HTTP response code was 200 (OK). the HTTP response or null on errors.
-
put
public InputStream put(String url, File file, String contentType)
PUTs a File to the given URL.- Parameters:
url- The URL where to connect to.file- The File to be sent.contentType- The content-type to advert in the PUT.- Returns:
- The HTTP response as a String if the HTTP response code was 200 (OK). the HTTP response or null on errors.
-
put
public InputStream put(String url, String content, String contentType)
PUTs a String to the given URL.- Parameters:
url- The URL where to connect to.content- The content to be sent as a String.contentType- The content-type to advert in the PUT.- Returns:
- The HTTP response as a String if the HTTP response code was 200 (OK). the HTTP response or null on errors.
-
put
public InputStream put(String url, org.apache.commons.httpclient.methods.RequestEntity requestEntity)
Performs a PUT to the given URL.- Parameters:
url- The URL where to connect to.requestEntity- The request to be sent.- Returns:
- The HTTP response as a String if the HTTP response code was 200 (OK). the HTTP response or null on errors.
-
postXml
public InputStream postXml(String url, String content)
POSTs a String representing an XML document to the given URL.- Parameters:
url- The URL where to connect to.content- The XML content to be sent as a String.- Returns:
- The HTTP response as a String if the HTTP response code was 200 (OK). the HTTP response or null on errors.
-
postXml
public InputStream postXml(String url, InputStream content)
POSTs a Stream content representing an XML document to the given URL.- Parameters:
url- The URL where to connect to.content- The content to be sent as an InputStream.- Returns:
- The HTTP response as a String if the HTTP response code was 200 (OK). the HTTP response or null on errors.
-
post
public InputStream post(String url, File file, String contentType)
POSTs a File to the given URL.- Parameters:
url- The URL where to connect to.file- The File to be sent.contentType- The content-type to advert in the POST.- Returns:
- The HTTP response as a String if the HTTP response code was 200 (OK). the HTTP response or null on errors.
-
post
public InputStream post(String url, String content, String contentType)
POSTs a String to the given URL.- Parameters:
url- The URL where to connect to.content- The content to be sent as a String.contentType- The content-type to advert in the POST.- Returns:
- The HTTP response as a String if the HTTP response code was 200 (OK). the HTTP response or null on errors.
-
post
public InputStream post(String url, InputStream content, String contentType)
POSTs a Stream content to the given URL.- Parameters:
url- The URL where to connect to.content- The content to be sent as an InputStream.contentType- The content-type to advert in the POST.- Returns:
- The HTTP response as a String if the HTTP response code was 200 (OK). the HTTP response or null on errors.
-
post
public InputStream post(String url, InputStream content, String contentType, Map<String,String[]> parameterMap)
POSTs a Stream content to the given URL.- Parameters:
url- the urlcontent- The content to be sent as an InputStream.contentType- The content-type to advert in the POST.parameterMap- the parameter map- Returns:
- The HTTP response as a String if the HTTP response code was 200 (OK). the HTTP response or null on errors.
-
post
public InputStream post(String url, org.apache.commons.httpclient.methods.RequestEntity requestEntity, Map<String,String[]> parameterMap)
Performs a POST to the given URL.
Basic auth is used if both username and pw are not null.- Parameters:
url- The URL where to connect to.requestEntity- The request to be sent.parameterMap- the parameter map- Returns:
- The HTTP response as a String if the HTTP response code was 200 (OK). the HTTP response or null on errors.
-
send
protected InputStream send(org.apache.commons.httpclient.methods.EntityEnclosingMethod httpMethod, String url, org.apache.commons.httpclient.methods.RequestEntity requestEntity)
Send an HTTP request (PUT or POST) to a server.
Basic auth is used if both username and pw are not null.Only
- 200: OK
- 201: ACCEPTED
- 202: CREATED
- Parameters:
httpMethod- the http methodurl- the urlrequestEntity- the request entity- Returns:
- the InputStream body response or null on errors.
-
sendPost
protected InputStream sendPost(org.apache.commons.httpclient.methods.EntityEnclosingMethod httpMethod, String url, org.apache.commons.httpclient.methods.RequestEntity requestEntity)
Send an HTTP request (PUT or POST) to a server.
Basic auth is used if both username and pw are not null.Only
- 200: OK
- 201: ACCEPTED
- 202: CREATED
- Parameters:
httpMethod- the http methodurl- the urlrequestEntity- the request entity- Returns:
- the HTTP response or null on errors.
-
delete
public boolean delete(String url)
Delete.- Parameters:
url- the url- Returns:
- true, if successful
-
httpPing
public boolean httpPing(String url)
Http ping.- Parameters:
url- the url- Returns:
- true if the server response was an HTTP_OK
-
exists
public boolean exists(String url)
Used to query for REST resources.- Parameters:
url- The URL of the REST resource to query about.- Returns:
- true on 200, false on 404.
-
getGeoNetworkErrorMessage
protected static String getGeoNetworkErrorMessage(String msg)
Gets the geo network error message.- Parameters:
msg- the msg- Returns:
- the geo network error message
-
getGeoNetworkErrorMessage
protected static String getGeoNetworkErrorMessage(InputStream msg)
Gets the geo network error message.- Parameters:
msg- the msg- Returns:
- the geo network error message
-
-