Class BaseHTTPSender

  • Direct Known Subclasses:
    DefaultHTTPMsgSender

    public abstract class BaseHTTPSender
    extends java.lang.Object
    Abstract Base implementation of a MsgSender using HTTP. Created by Philip Vendil on 23/06/16.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.net.URL baseURL  
      protected java.lang.String outputContentType  
      protected java.lang.String requestType  
    • Constructor Summary

      Constructors 
      Constructor Description
      BaseHTTPSender​(java.lang.String url, java.lang.String requestType, java.lang.String outputContentType)
      Main constructor where it is possible to specify request type.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected byte[] sendMsg​(byte[] request)
      Synchronous call for sending HTTP request sending data in the HTTP request body (usually using POST)
      protected void sendMsg​(byte[] request, MsgSender.MsgCallback callback)
      Asynchronous call for sending HTTP request sending data in the HTTP request body (usually using POST)
      protected byte[] sendMsg​(java.lang.String parameters)
      Synchronous call for sending HTTP request with parameters in URL string (usually using GET)
      protected void sendMsg​(java.lang.String parameters, MsgSender.MsgCallback callback)
      Asynchronous call for sending HTTP request with parameters in URL string (usually using GET)
      boolean testConnection()
      Synchronous call to test connection to the given url.
      static byte[] toByteArray​(java.io.InputStream inputStream)  
      • Methods inherited from class java.lang.Object

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

      • baseURL

        protected java.net.URL baseURL
      • requestType

        protected java.lang.String requestType
      • outputContentType

        protected java.lang.String outputContentType
    • Constructor Detail

      • BaseHTTPSender

        public BaseHTTPSender​(java.lang.String url,
                              java.lang.String requestType,
                              java.lang.String outputContentType)
                       throws java.net.MalformedURLException
        Main constructor where it is possible to specify request type.
        Parameters:
        url - the URL to connect to.
        requestType - the HTTP request type in upper case (For example POST, GET)
        outputContentType - the content type on the output data.
        Throws:
        java.net.MalformedURLException - if URL was malformed.
    • Method Detail

      • testConnection

        public boolean testConnection()
        Synchronous call to test connection to the given url.
        Returns:
        true if connection is working, otherwise false.
      • toByteArray

        public static byte[] toByteArray​(java.io.InputStream inputStream)
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • sendMsg

        protected void sendMsg​(byte[] request,
                               MsgSender.MsgCallback callback)
        Asynchronous call for sending HTTP request sending data in the HTTP request body (usually using POST)
        Parameters:
        request - the data to send.
        callback - the callback to signal the result to.
      • sendMsg

        protected void sendMsg​(java.lang.String parameters,
                               MsgSender.MsgCallback callback)
                        throws MessageContentException
        Asynchronous call for sending HTTP request with parameters in URL string (usually using GET)
        Parameters:
        parameters - the parameter string to send (without ?)
        callback - the callback to signal the result to.
        Throws:
        MessageContentException