Class HttpPackage

  • Direct Known Subclasses:
    HttpRequest, HttpResponse

    public abstract class HttpPackage
    extends java.lang.Object
    This class represents all the king of packages between server and client side in a http communication.
    Author:
    javaito
    • Method Summary

      Modifier and Type Method Description
      void addCookie​(Cookie cookie)
      Add a cookie to the http package.
      void addData​(byte[] data)
      Add a portion of data into the package.
      void addHeader​(HttpHeader header)
      Add a new header into a package.
      protected boolean bodyDone()
      Verify if the body of the package is complete.
      boolean containsCookie​(java.lang.String name)
      Verify if the package contains the cookie indexed by the parameter name.
      boolean containsHeader​(java.lang.String headerName)
      Verify if the package contains any header with the specific name.
      byte[] getBody()
      Return the body of the package.
      Cookie getCookie​(java.lang.String name)
      Returns the cookie instance indexed by the parameter name.
      java.util.Collection<Cookie> getCookies()
      Returns a unmodifiable collection with all the cookies of the package.
      HttpHeader getHeader​(java.lang.String headerName)
      Return the header instance with the specific name.
      java.util.Collection<HttpHeader> getHeaders()
      Return in a unmodificable list, all the headers contained into the package.
      java.lang.String getHttpVersion()
      Return the version of the http protocol
      HttpPackage.HttpProtocol getProtocol()
      Return the http protocol.
      abstract byte[] getProtocolHeader()
      Return the bytes that represent the string of the protocol name.
      boolean isComplete()
      Return true if the http package is complete.
      protected abstract void processBody()
      This method must be implemented to process the body information.
      protected abstract void processFirstLine​(java.lang.String firstLine)
      This method must be implemented to process the first line of the package.
      void setBody​(byte[] body)
      Set the body of the package.
      void setHttpVersion​(java.lang.String httpVersion)
      Set the version of the http protocol
      void setProtocol​(HttpPackage.HttpProtocol protocol)
      Set the http protocol.
      protected byte[] trimBody​(byte[] body)
      Return the body trimmed.
      • Methods inherited from class java.lang.Object

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

      • STRING_LINE_SEPARATOR

        public static final java.lang.String STRING_LINE_SEPARATOR
        See Also:
        Constant Field Values
      • LINE_FIELD_SEPARATOR

        public static final java.lang.String LINE_FIELD_SEPARATOR
        See Also:
        Constant Field Values
      • HTTP_FIELD_START

        public static final java.lang.String HTTP_FIELD_START
        See Also:
        Constant Field Values
      • HTTP_FIELD_SEPARATOR

        public static final java.lang.String HTTP_FIELD_SEPARATOR
        See Also:
        Constant Field Values
      • HTTP_FIELD_ASSIGNATION

        public static final java.lang.String HTTP_FIELD_ASSIGNATION
        See Also:
        Constant Field Values
      • HTTP_CONTEXT_SEPARATOR

        public static final java.lang.String HTTP_CONTEXT_SEPARATOR
        See Also:
        Constant Field Values
    • Constructor Detail

      • HttpPackage

        public HttpPackage()
      • HttpPackage

        protected HttpPackage​(HttpPackage httpPackage)
    • Method Detail

      • setProtocol

        public void setProtocol​(HttpPackage.HttpProtocol protocol)
        Set the http protocol.
        Parameters:
        protocol - Http protocol
      • getBody

        public final byte[] getBody()
        Return the body of the package.
        Returns:
        Body.
      • setBody

        public final void setBody​(byte[] body)
        Set the body of the package.
        Parameters:
        body - Body.
      • getHttpVersion

        public final java.lang.String getHttpVersion()
        Return the version of the http protocol
        Returns:
        Http protocol version.
      • setHttpVersion

        public final void setHttpVersion​(java.lang.String httpVersion)
        Set the version of the http protocol
        Parameters:
        httpVersion - Version of the http protocol
      • isComplete

        public final boolean isComplete()
        Return true if the http package is complete.
        Returns:
        Trus if the package is complete and false in the otherwise.
      • addHeader

        public final void addHeader​(HttpHeader header)
        Add a new header into a package.
        Parameters:
        header - New header.
      • getHeaders

        public final java.util.Collection<HttpHeader> getHeaders()
        Return in a unmodificable list, all the headers contained into the package.
        Returns:
        List of the headers.
      • getHeader

        public final HttpHeader getHeader​(java.lang.String headerName)
        Return the header instance with the specific name.
        Parameters:
        headerName - Name of the founded header.
        Returns:
        Founded header or null if there are'nt any header with this name.
      • containsHeader

        public final boolean containsHeader​(java.lang.String headerName)
        Verify if the package contains any header with the specific name.
        Parameters:
        headerName - Finding header name.
        Returns:
        Return true if there are any header with the specific name and false in the otherwise.
      • addCookie

        public final void addCookie​(Cookie cookie)
        Add a cookie to the http package.
        Parameters:
        cookie - Cookie instance.
      • getCookies

        public final java.util.Collection<Cookie> getCookies()
        Returns a unmodifiable collection with all the cookies of the package.
        Returns:
        Collection with all the cookies.
      • getCookie

        public final Cookie getCookie​(java.lang.String name)
        Returns the cookie instance indexed by the parameter name.
        Parameters:
        name - Parameter name.
        Returns:
        Cookie instance.
      • containsCookie

        public final boolean containsCookie​(java.lang.String name)
        Verify if the package contains the cookie indexed by the parameter name.
        Parameters:
        name - Parameter name.
        Returns:
        True if the cookie is contained and false in the otherwise.
      • addData

        public final void addData​(byte[] data)
        Add a portion of data into the package.
        Parameters:
        data - Portion of data.
      • bodyDone

        protected boolean bodyDone()
        Verify if the body of the package is complete.
        Returns:
        Return true if the body is complete or false in the otherwise
      • trimBody

        protected byte[] trimBody​(byte[] body)
        Return the body trimmed.
        Parameters:
        body - Raw body.
        Returns:
        Trimmed body
      • processBody

        protected abstract void processBody()
        This method must be implemented to process the body information.
      • processFirstLine

        protected abstract void processFirstLine​(java.lang.String firstLine)
        This method must be implemented to process the first line of the package.
        Parameters:
        firstLine - First line of the package.
      • getProtocolHeader

        public abstract byte[] getProtocolHeader()
        Return the bytes that represent the string of the protocol name.
        Returns:
        Protocol name bytes.