Class HTTPCallsUtils


  • public class HTTPCallsUtils
    extends Object
    The Class HTTPCallsUtils. copied by Geosolution
    Author:
    Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Apr 5, 2016
    • Constructor Detail

      • HTTPCallsUtils

        public HTTPCallsUtils()
        Instantiates a new HTTP utils.
      • HTTPCallsUtils

        public HTTPCallsUtils​(String userName,
                              String password)
        Instantiates a new HTTP utils.
        Parameters:
        userName - the user name
        password - the password
    • 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
      • 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 url
        content - 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
        are accepted as successful codes; in these cases the response string will be returned.
        Parameters:
        httpMethod - the http method
        url - the url
        requestEntity - 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
        are accepted as successful codes; in these cases the response string will be returned.
        Parameters:
        httpMethod - the http method
        url - the url
        requestEntity - 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