Package org.hcjf.io.net.http
Class HttpPackage
- java.lang.Object
-
- org.hcjf.io.net.http.HttpPackage
-
- Direct Known Subclasses:
HttpRequest,HttpResponse
public abstract class HttpPackage extends java.lang.ObjectThis class represents all the king of packages between server and client side in a http communication.- Author:
- javaito
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classHttpPackage.ChunkedDecoderLayerThis decoder implementation resolve the chunked encoding method for http.static classHttpPackage.HttpProtocolEnum with the http protocolsstatic interfaceHttpPackage.TransferDecodingLayerInterfaceSpecify the interface for all the implementations of http body decode method.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringHTTP_CONTEXT_SEPARATORstatic java.lang.StringHTTP_FIELD_ASSIGNATIONstatic java.lang.StringHTTP_FIELD_SEPARATORstatic java.lang.StringHTTP_FIELD_STARTstatic java.lang.StringLINE_FIELD_SEPARATORstatic java.lang.StringSTRING_LINE_SEPARATOR
-
Constructor Summary
Constructors Modifier Constructor Description HttpPackage()protectedHttpPackage(HttpPackage httpPackage)
-
Method Summary
Modifier and Type Method Description voidaddCookie(Cookie cookie)Add a cookie to the http package.voidaddData(byte[] data)Add a portion of data into the package.voidaddHeader(HttpHeader header)Add a new header into a package.protected booleanbodyDone()Verify if the body of the package is complete.booleancontainsCookie(java.lang.String name)Verify if the package contains the cookie indexed by the parameter name.booleancontainsHeader(java.lang.String headerName)Verify if the package contains any header with the specific name.byte[]getBody()Return the body of the package.CookiegetCookie(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.HttpHeadergetHeader(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.StringgetHttpVersion()Return the version of the http protocolHttpPackage.HttpProtocolgetProtocol()Return the http protocol.abstract byte[]getProtocolHeader()Return the bytes that represent the string of the protocol name.booleanisComplete()Return true if the http package is complete.protected abstract voidprocessBody()This method must be implemented to process the body information.protected abstract voidprocessFirstLine(java.lang.String firstLine)This method must be implemented to process the first line of the package.voidsetBody(byte[] body)Set the body of the package.voidsetHttpVersion(java.lang.String httpVersion)Set the version of the http protocolvoidsetProtocol(HttpPackage.HttpProtocol protocol)Set the http protocol.protected byte[]trimBody(byte[] body)Return the body trimmed.
-
-
-
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
-
getProtocol
public HttpPackage.HttpProtocol getProtocol()
Return the http protocol.- Returns:
- Http protocol
-
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.
-
-