@Contract(threading=IMMUTABLE_CONDITIONAL) public class HttpService extends Object
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.
Constructor and 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.
|
Modifier and Type | Method and Description |
---|---|
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(Exception ex) |
public HttpService(HttpProcessor processor, HttpRequestMapper<HttpRequestHandler> handlerMapper, ConnectionReuseStrategy connReuseStrategy, HttpResponseFactory<ClassicHttpResponse> responseFactory, Http1StreamListener streamListener)
processor
- the processor to use on requests and responseshandlerMapper
- the handler mapperresponseFactory
- the response factory. If null
DefaultClassicHttpResponseFactory.INSTANCE
will be used.connReuseStrategy
- the connection reuse strategy. If null
DefaultConnectionReuseStrategy.INSTANCE
will be used.streamListener
- message stream listener.public HttpService(HttpProcessor processor, HttpRequestMapper<HttpRequestHandler> handlerMapper, ConnectionReuseStrategy connReuseStrategy, HttpResponseFactory<ClassicHttpResponse> responseFactory)
processor
- the processor to use on requests and responseshandlerMapper
- the handler mapperconnReuseStrategy
- the connection reuse strategy. If null
DefaultConnectionReuseStrategy.INSTANCE
will be used.responseFactory
- the response factory. If null
DefaultClassicHttpResponseFactory.INSTANCE
will be used.public HttpService(HttpProcessor processor, HttpServerRequestHandler requestHandler, ConnectionReuseStrategy connReuseStrategy, Http1StreamListener streamListener)
processor
- the processor to use on requests and responsesrequestHandler
- the request handler.connReuseStrategy
- the connection reuse strategy. If null
DefaultConnectionReuseStrategy.INSTANCE
will be used.streamListener
- message stream listener.public HttpService(HttpProcessor processor, HttpServerRequestHandler requestHandler)
processor
- the processor to use on requests and responsesrequestHandler
- the request handler.public void handleRequest(HttpServerConnection conn, HttpContext context) throws IOException, HttpException
conn
- the active connection to the clientcontext
- the actual execution context.IOException
- in case of an I/O error.HttpException
- in case of HTTP protocol violation or a processing
problem.protected void handleException(HttpException ex, ClassicHttpResponse response)
ex
- the exception.response
- the HTTP response.protected int toStatusCode(Exception ex)
Copyright © 2005–2022 The Apache Software Foundation. All rights reserved.