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
HttpServiceis a server side HTTP protocol handler based on the classic (blocking) I/O model.HttpServicerelies onHttpProcessorto generate mandatory protocol headers for all outgoing messages and apply common, cross-cutting message transformations to all incoming and outgoing messages, whereas individualHttpRequestHandlers are expected to implement application specific content generation and processing.HttpServiceusesHttpRequestMapperto 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 classHttpService.BuilderBuilder forHttpService.
-
Field Summary
Fields Modifier and Type Field Description private ConnectionReuseStrategyconnReuseStrategyprivate HttpProcessorprocessorprivate HttpServerRequestHandlerrequestHandlerprivate Http1StreamListenerstreamListener
-
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.Builderbuilder()Create a newHttpService.Builder.protected voidhandleException(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.voidhandleRequest(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 inttoStatusCode(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. IfnullDefaultClassicHttpResponseFactory.INSTANCEwill be used.connReuseStrategy- the connection reuse strategy. IfnullDefaultConnectionReuseStrategy.INSTANCEwill 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. IfnullDefaultConnectionReuseStrategy.INSTANCEwill be used.responseFactory- the response factory. IfnullDefaultClassicHttpResponseFactory.INSTANCEwill 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. IfnullDefaultConnectionReuseStrategy.INSTANCEwill 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
-
-