Package org.apache.hc.core5.http.impl.io
Class HttpService
java.lang.Object
org.apache.hc.core5.http.impl.io.HttpService
HttpService
is a server side HTTP protocol handler based on
the classic (blocking) I/O model.
HttpService
relies on HttpProcessor
to generate mandatory
protocol headers for all outgoing messages and apply common, cross-cutting
message transformations to all incoming and outgoing messages, whereas
individual HttpRequestHandler
s are expected to implement
application specific content generation and processing.
HttpService
uses HttpRequestMapper
to map
matching request handler for a particular request URI of an incoming HTTP
request.
- Since:
- 4.0
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ConnectionReuseStrategy
private final HttpProcessor
private final HttpServerRequestHandler
private final Http1StreamListener
-
Constructor Summary
ConstructorsConstructorDescriptionHttpService
(HttpProcessor processor, HttpRequestMapper<HttpRequestHandler> handlerMapper, ConnectionReuseStrategy connReuseStrategy, HttpResponseFactory<ClassicHttpResponse> responseFactory) Create a new HTTP service.HttpService
(HttpProcessor processor, HttpRequestMapper<HttpRequestHandler> handlerMapper, ConnectionReuseStrategy connReuseStrategy, HttpResponseFactory<ClassicHttpResponse> responseFactory, Http1StreamListener streamListener) Create a new HTTP service.HttpService
(HttpProcessor processor, HttpServerRequestHandler requestHandler) Create a new HTTP service.HttpService
(HttpProcessor processor, HttpServerRequestHandler requestHandler, ConnectionReuseStrategy connReuseStrategy, Http1StreamListener streamListener) Create a new HTTP service. -
Method Summary
Modifier and TypeMethodDescriptionstatic HttpService.Builder
builder()
Create a newHttpService.Builder
.protected void
handleException
(HttpException ex, ClassicHttpResponse response) Handles the given exception and generates an HTTP response to be sent back to the client to inform about the exceptional condition encountered in the course of the request processing.void
handleRequest
(HttpServerConnection conn, HttpContext context) Handles receives one HTTP request over the given connection within the given execution context and sends a response back to the client.protected int
-
Field Details
-
processor
-
requestHandler
-
connReuseStrategy
-
streamListener
-
-
Constructor Details
-
HttpService
public HttpService(HttpProcessor processor, HttpRequestMapper<HttpRequestHandler> handlerMapper, ConnectionReuseStrategy connReuseStrategy, HttpResponseFactory<ClassicHttpResponse> responseFactory, Http1StreamListener streamListener) Create a new HTTP service.- Parameters:
processor
- the processor to use on requests and responseshandlerMapper
- the handler mapperconnReuseStrategy
- the connection reuse strategy. Ifnull
DefaultConnectionReuseStrategy.INSTANCE
will be used.responseFactory
- the response factory. Ifnull
DefaultClassicHttpResponseFactory.INSTANCE
will be used.streamListener
- message stream listener.
-
HttpService
public HttpService(HttpProcessor processor, HttpRequestMapper<HttpRequestHandler> handlerMapper, ConnectionReuseStrategy connReuseStrategy, HttpResponseFactory<ClassicHttpResponse> responseFactory) Create a new HTTP service.- Parameters:
processor
- the processor to use on requests and responseshandlerMapper
- the handler mapperconnReuseStrategy
- the connection reuse strategy. Ifnull
DefaultConnectionReuseStrategy.INSTANCE
will be used.responseFactory
- the response factory. Ifnull
DefaultClassicHttpResponseFactory.INSTANCE
will be used.
-
HttpService
public HttpService(HttpProcessor processor, HttpServerRequestHandler requestHandler, ConnectionReuseStrategy connReuseStrategy, Http1StreamListener streamListener) Create a new HTTP service.- Parameters:
processor
- the processor to use on requests and responsesrequestHandler
- the request handler.connReuseStrategy
- the connection reuse strategy. Ifnull
DefaultConnectionReuseStrategy.INSTANCE
will be used.streamListener
- message stream listener.
-
HttpService
Create a new HTTP service.- Parameters:
processor
- the processor to use on requests and responsesrequestHandler
- the request handler.
-
-
Method Details
-
handleRequest
public void handleRequest(HttpServerConnection conn, HttpContext context) throws IOException, HttpException Handles receives one HTTP request over the given connection within the given execution context and sends a response back to the client.- Parameters:
conn
- the active connection to the clientcontext
- the actual execution context.- Throws:
IOException
- in case of an I/O error.HttpException
- in case of HTTP protocol violation or a processing problem.
-
handleException
Handles the given exception and generates an HTTP response to be sent back to the client to inform about the exceptional condition encountered in the course of the request processing.- Parameters:
ex
- the exception.response
- the HTTP response.
-
toStatusCode
-
builder
Create a newHttpService.Builder
.- Since:
- 5.2
-