Package org.hcjf.io.net.http
Class HttpServer
- java.lang.Object
-
- org.hcjf.io.net.NetServiceConsumer<S,D>
-
- org.hcjf.io.net.NetServer<HttpSession,HttpPackage>
-
- org.hcjf.io.net.http.HttpServer
-
- All Implemented Interfaces:
ServiceConsumer
- Direct Known Subclasses:
HttpProxy,HttpsServer
public class HttpServer extends NetServer<HttpSession,HttpPackage>
Implementation of the net service that provides the http protocol server.- Author:
- javaito
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classHttpServer.AccessControlstatic classHttpServer.ContextMatcher-
Nested classes/interfaces inherited from class org.hcjf.io.net.NetServiceConsumer
NetServiceConsumer.DecoupledAction
-
-
Constructor Summary
Constructors Modifier Constructor Description HttpServer()HttpServer(java.lang.Integer port)protectedHttpServer(java.lang.Integer port, boolean sslProtocol)
-
Method Summary
Modifier and Type Method Description voidaddAccessControl(HttpServer.AccessControl accessControl)Adda new access control into the server.voidaddContext(Context context)Add context to the server.HttpSessioncheckSession(HttpSession session, HttpPackage payLoad, NetPackage netPackage)This method must update the http session with all the information of the request.static voidcreate(java.lang.Integer port, Context... contexts)HttpSessioncreateSession(NetPackage netPackage)This method must implements the session creation based on the net package that incoming.protected HttpPackagedecode(NetPackage netPackage)This method decode the net package to obtain the implementation datavoiddestroySession(NetSession session)Destroy the session.protected byte[]encode(HttpPackage payLoad)This method decode the implementation data.protected HttpServer.ContextMatcherfindContext(java.lang.String contextName)Find the context instance that response to the request's context name.HttpSessionManagergetSessionManager()Return the instance of the session factory.booleanisCreationTimeoutAvailable()For http implementation the connection timeout is not available.protected voidonCheckSessionError(HttpSession session, HttpPackage requestPayLoad, NetPackage netPackage, java.lang.Throwable exception)Manages an exception thrown while trying to check session (authenticate) by calling to the specific context for get an error response depending on exception information.protected HttpResponseonContextNotFound(HttpRequest request)This method must create the response package when the context not found.protected voidonDisconnect(HttpSession session, NetPackage netPackage)This method is called when the session is closed.protected HttpResponseonNotCheckedSession(HttpRequest request)This method must create the response package when the session check fail.protected voidonRead(HttpSession session, HttpPackage payLoad, NetPackage netPackage)First check if the package is complete, then try to found the context using the http request information a create the response package.protected voidonStart()Only put in the log the moment to server start.protected voidonStop()Only put in the log the moment to server stop.protected HttpResponseonUnresponsiveContext(HttpRequest request)This method must create the response package when the context result is null.protected voidonWrite(HttpSession session, NetPackage netPackage)When the net service write data then call this method to process the package.voidsetSessionManager(HttpSessionManager sessionManager)Set the instance of the session factory.-
Methods inherited from class org.hcjf.io.net.NetServer
isDisconnectAndRemove, isMultiSession, start, stop
-
Methods inherited from class org.hcjf.io.net.NetServiceConsumer
addDecoupledAction, decoupleIoAction, disconnect, getName, getPort, getProtocol, getService, getShutdownFrame, getShutdownPackage, getSocketOptions, getSSLEngine, getWriteWaitForTimeout, isDecoupledIoAction, onConnect, onConnect, onDisconnect, onRead, onWrite, setService, setWriteWaitForTimeout, write, write
-
-
-
-
Method Detail
-
create
public static void create(java.lang.Integer port, Context... contexts)
-
addAccessControl
public final void addAccessControl(HttpServer.AccessControl accessControl)
Adda new access control into the server.- Parameters:
accessControl- Access control instance.
-
getSessionManager
public final HttpSessionManager getSessionManager()
Return the instance of the session factory.- Returns:
- Session factory.
-
setSessionManager
public final void setSessionManager(HttpSessionManager sessionManager)
Set the instance of the session factory.- Parameters:
sessionManager- Session factory.
-
createSession
public final HttpSession createSession(NetPackage netPackage)
This method must implements the session creation based on the net package that incoming.- Specified by:
createSessionin classNetServer<HttpSession,HttpPackage>- Parameters:
netPackage- Net package.- Returns:
- Return the session based on the package.
-
checkSession
public HttpSession checkSession(HttpSession session, HttpPackage payLoad, NetPackage netPackage)
This method must update the http session with all the information of the request.- Specified by:
checkSessionin classNetServiceConsumer<HttpSession,HttpPackage>- Parameters:
session- Current session.payLoad- Decoded package.netPackage- Net package.- Returns:
- Updated http session.
-
encode
protected final byte[] encode(HttpPackage payLoad)
This method decode the implementation data.- Specified by:
encodein classNetServiceConsumer<HttpSession,HttpPackage>- Parameters:
payLoad- Implementation data.- Returns:
- Implementation data encoded.
-
decode
protected final HttpPackage decode(NetPackage netPackage)
This method decode the net package to obtain the implementation data- Specified by:
decodein classNetServiceConsumer<HttpSession,HttpPackage>- Parameters:
netPackage- Net package.- Returns:
- Return the implementation data.
-
addContext
public void addContext(Context context)
Add context to the server.- Parameters:
context- Context instance.
-
findContext
protected HttpServer.ContextMatcher findContext(java.lang.String contextName)
Find the context instance that response to the request's context name.- Parameters:
contextName- Request's context name.- Returns:
- Founded context.
-
destroySession
public void destroySession(NetSession session)
Destroy the session.- Specified by:
destroySessionin classNetServiceConsumer<HttpSession,HttpPackage>- Parameters:
session- Net session to be destroyed
-
onRead
protected final void onRead(HttpSession session, HttpPackage payLoad, NetPackage netPackage)
First check if the package is complete, then try to found the context using the http request information a create the response package.- Overrides:
onReadin classNetServiceConsumer<HttpSession,HttpPackage>- Parameters:
session- Net session.payLoad- Net package decodednetPackage- Net package.
-
onCheckSessionError
protected void onCheckSessionError(HttpSession session, HttpPackage requestPayLoad, NetPackage netPackage, java.lang.Throwable exception)
Manages an exception thrown while trying to check session (authenticate) by calling to the specific context for get an error response depending on exception information. Thus, the response is written to the consumer.- Overrides:
onCheckSessionErrorin classNetServiceConsumer<HttpSession,HttpPackage>- Parameters:
session- Net session.requestPayLoad- Net package decoded asHttpRequestnetPackage- Net package.exception- exception
-
onContextNotFound
protected HttpResponse onContextNotFound(HttpRequest request)
This method must create the response package when the context not found.- Parameters:
request- Http request.- Returns:
- Context not found response.
-
onUnresponsiveContext
protected HttpResponse onUnresponsiveContext(HttpRequest request)
This method must create the response package when the context result is null.- Parameters:
request- Http request.- Returns:
- Unresponsive context response.
-
onNotCheckedSession
protected HttpResponse onNotCheckedSession(HttpRequest request)
This method must create the response package when the session check fail.- Parameters:
request- Http request.- Returns:
- Session check fail response.
-
onDisconnect
protected final void onDisconnect(HttpSession session, NetPackage netPackage)
This method is called when the session is closed.- Overrides:
onDisconnectin classNetServiceConsumer<HttpSession,HttpPackage>- Parameters:
session- Closed session.netPackage- Close package.
-
onWrite
protected final void onWrite(HttpSession session, NetPackage netPackage)
When the net service write data then call this method to process the package.- Overrides:
onWritein classNetServiceConsumer<HttpSession,HttpPackage>- Parameters:
session- Net session.netPackage- Net package.
-
onStart
protected void onStart()
Only put in the log the moment to server start.- Overrides:
onStartin classNetServer<HttpSession,HttpPackage>
-
isCreationTimeoutAvailable
public boolean isCreationTimeoutAvailable()
For http implementation the connection timeout is not available.- Overrides:
isCreationTimeoutAvailablein classNetServer<HttpSession,HttpPackage>- Returns:
- Connection timeout available.
-
onStop
protected void onStop()
Only put in the log the moment to server stop.- Overrides:
onStopin classNetServer<HttpSession,HttpPackage>
-
-