psdi.iface.util

Class HttpPostClient

  • java.lang.Object
    • psdi.iface.util.HttpPostClient


  • public class HttpPostClient
    extends java.lang.Object
    Test Client for HTTP Post
    • Constructor Summary

      Constructors 
      Constructor and Description
      HttpPostClient() 
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method and Description
      static java.lang.String getResponseString(java.io.InputStream is)
      Get the Response String from the InputStream
      static java.lang.String getURLEncodedString(java.util.Map requestProps)
      Returns a URL-encoded string of the given request properties
      static void main(java.lang.String[] args)
      Main method
      static java.io.InputStream postBinaryData(java.lang.String uri, byte[] data, java.util.Map headers, java.lang.String contentType)
      Post the data given as bytes
      static java.io.InputStream postTextData(java.lang.String uri, java.lang.String data, java.util.Map headers, java.lang.String contentType)
      Post the given text data
      static java.io.InputStream postURLEncodedData(java.lang.String uri, java.util.Map requestProps, java.util.Map headers)
      Post the given data as URL-encoded of the type application/x-www-form-urlencoded
      static byte[] readBinaryData(java.lang.String fileName)
      Utility method to read binary data from a file
      static java.lang.String readTextData(java.lang.String fileName, java.lang.String charEncoding)
      Utility method to read text data from a file.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • HttpPostClient

        public HttpPostClient()
    • Method Detail

      • postBinaryData

        public static java.io.InputStream postBinaryData(java.lang.String uri,
                                                         byte[] data,
                                                         java.util.Map headers,
                                                         java.lang.String contentType)
                                                  throws java.io.IOException
        Post the data given as bytes
        Parameters:
        uri - the URL
        data - the data
        headers - Map of headers which will be converted to HTTP headers
        contentType - the HTTP Content-Type header. If null, then a Content-Type of application/binary will be used
        Throws:
        java.io.IOException
      • postTextData

        public static java.io.InputStream postTextData(java.lang.String uri,
                                                       java.lang.String data,
                                                       java.util.Map headers,
                                                       java.lang.String contentType)
                                                throws java.io.IOException
        Post the given text data
        Parameters:
        uri - the URL
        data - the text data
        headers - Map of headers which will be converted to HTTP headers
        contentType - the HTTP Content-Type header. If null, then a Content-Type of text/xml; charset=UTF-8 will be used
        Throws:
        java.io.IOException
      • postURLEncodedData

        public static java.io.InputStream postURLEncodedData(java.lang.String uri,
                                                             java.util.Map requestProps,
                                                             java.util.Map headers)
                                                      throws java.lang.Exception
        Post the given data as URL-encoded of the type application/x-www-form-urlencoded
        Parameters:
        uri - the URI to post data
        requestProps - the Map containing the request properties
        headers - the HTTP headers
        Throws:
        java.lang.Exception
      • getURLEncodedString

        public static java.lang.String getURLEncodedString(java.util.Map requestProps)
                                                    throws java.lang.Exception
        Returns a URL-encoded string of the given request properties
        Parameters:
        requestProps - the Map containing the request properties
        Returns:
        URL-encoded string of the given request properties
        Throws:
        java.lang.Exception
      • getResponseString

        public static java.lang.String getResponseString(java.io.InputStream is)
                                                  throws java.io.IOException
        Get the Response String from the InputStream
        Parameters:
        is - the Input Stream
        Returns:
        the response string
        Throws:
        java.io.IOException - if any IO error occurs while reading the stream
      • readBinaryData

        public static byte[] readBinaryData(java.lang.String fileName)
                                     throws java.io.IOException
        Utility method to read binary data from a file
        Parameters:
        fileName - the absolute path to the file
        Throws:
        java.io.IOException - if any IO error occurs while reading the file
      • readTextData

        public static java.lang.String readTextData(java.lang.String fileName,
                                                    java.lang.String charEncoding)
                                             throws java.io.IOException
        Utility method to read text data from a file. If no character encoding is provided in the parameter, it assumes default system character encoding
        Parameters:
        fileName - the absolute path to the file
        charEncoding - the character encoding of the file
        Throws:
        java.io.IOException - if any IO error occurs while reading the file
      • main

        public static void main(java.lang.String[] args)
                         throws java.lang.Exception
        Main method
        Throws:
        java.lang.Exception - if any error occurs