Package ej.restserver
Class RestServer
- java.lang.Object
-
- HTTPServer
-
- ej.restserver.RestServer
-
public class RestServer extends HTTPServerA simple implementation of HTTP server capable of easily exposing endpoints.REST servers can always handle requests that target endpoints. Other kind of request are handles by custom request handlers.
- See Also:
EndpointHandler,RequestHandler
-
-
Constructor Summary
Constructors Constructor Description RestServer(int port, int maxSimultaneousConnection, int jobCountBySession)Creates a new server bounded to given port.RestServer(int port, int maxSimultaneousConnection, int jobCountBySession, ServerSocketFactory serverSocketFactory)Creates a REST server on top of the given HTTP server.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddEndpoint(RestEndpoint endpoint)Adds an endpoint to this server.voidaddRequestResolver(RequestHandler handler)Adds a request handler to this server.List<RestEndpoint>getEndpoints()Gets the list of active endpoints.List<RequestHandler>getRequestResolvers()Gets the list of active request handlers.
-
-
-
Constructor Detail
-
RestServer
public RestServer(int port, int maxSimultaneousConnection, int jobCountBySession) throws IOExceptionCreates a new server bounded to given port.This constructor looks for server socket service implementation using a Service Loader. The returned server socket will be used. If no service is declared, default implementation is used (Java standard server socket).
- Parameters:
port- the port.maxSimultaneousConnection- the maximal number of simultaneously opened connections.jobCountBySession- the number of parallel jobs to process by opened sessions.- Throws:
IOException- if server cannot be bind to given port.
-
RestServer
public RestServer(int port, int maxSimultaneousConnection, int jobCountBySession, ServerSocketFactory serverSocketFactory) throws IOExceptionCreates a REST server on top of the given HTTP server.- Parameters:
port- the port.maxSimultaneousConnection- the maximal number of simultaneously opened connections.jobCountBySession- the number of parallel jobs to process by opened sessions.serverSocketFactory- the serverSocketFactory to use.- Throws:
IOException- if server cannot be bind to given port.
-
-
Method Detail
-
addEndpoint
public void addEndpoint(RestEndpoint endpoint)
Adds an endpoint to this server.- Parameters:
endpoint- the endpoint to add.
-
addRequestResolver
public void addRequestResolver(RequestHandler handler)
Adds a request handler to this server. Given resolver becomes immediately active.- Parameters:
handler- the handler to add.
-
getEndpoints
public List<RestEndpoint> getEndpoints()
Gets the list of active endpoints.- Returns:
- an unmodifiable list of server active endpoints.
-
getRequestResolvers
public List<RequestHandler> getRequestResolvers()
Gets the list of active request handlers. It contains at least an endpoint handler.- Returns:
- an non-empty and unmodifiable list of server active request handlers.
- See Also:
EndpointHandler
-
-