Package org.apache.hc.core5.http.impl.io
Class HttpService
- java.lang.Object
-
- org.apache.hc.core5.http.impl.io.HttpService
-
@Contract(threading=IMMUTABLE_CONDITIONAL) public class HttpService extends java.lang.Object
HttpService
is a server side HTTP protocol handler based on the classic (blocking) I/O model.HttpService
relies onHttpProcessor
to generate mandatory protocol headers for all outgoing messages and apply common, cross-cutting message transformations to all incoming and outgoing messages, whereas individualHttpRequestHandler
s are expected to implement application specific content generation and processing.HttpService
usesHttpRequestMapper
to map matching request handler for a particular request URI of an incoming HTTP request.- Since:
- 4.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
HttpService.Builder
Builder forHttpService
.
-
Field Summary
Fields Modifier and Type Field Description private ConnectionReuseStrategy
connReuseStrategy
private HttpProcessor
processor
private HttpServerRequestHandler
requestHandler
private Http1StreamListener
streamListener
-
Constructor Summary
Constructors Constructor Description HttpService(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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static 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
toStatusCode(java.lang.Exception ex)
-
-
-
Field Detail
-
processor
private final HttpProcessor processor
-
requestHandler
private final HttpServerRequestHandler requestHandler
-
connReuseStrategy
private final ConnectionReuseStrategy connReuseStrategy
-
streamListener
private final Http1StreamListener streamListener
-
-
Constructor Detail
-
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 mapperresponseFactory
- the response factory. Ifnull
DefaultClassicHttpResponseFactory.INSTANCE
will be used.connReuseStrategy
- the connection reuse strategy. Ifnull
DefaultConnectionReuseStrategy.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
public HttpService(HttpProcessor processor, HttpServerRequestHandler requestHandler)
Create a new HTTP service.- Parameters:
processor
- the processor to use on requests and responsesrequestHandler
- the request handler.
-
-
Method Detail
-
handleRequest
public void handleRequest(HttpServerConnection conn, HttpContext context) throws java.io.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:
java.io.IOException
- in case of an I/O error.HttpException
- in case of HTTP protocol violation or a processing problem.
-
handleException
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.- Parameters:
ex
- the exception.response
- the HTTP response.
-
toStatusCode
protected int toStatusCode(java.lang.Exception ex)
-
builder
public static HttpService.Builder builder()
Create a newHttpService.Builder
.- Since:
- 5.2
-
-