Top Description Inners Fields Constructors Methods
org.apache.hc.core5.http.impl.io

public Class HttpService

extends Object
Class Inheritance
Annotations
@Contract
threading:IMMUTABLE_CONDITIONAL
Imports
java.io.IOException, java.util.concurrent.atomic.AtomicBoolean, org.apache.hc.core5.annotation.Contract, .ThreadingBehavior, org.apache.hc.core5.http.ClassicHttpRequest, .ClassicHttpResponse, .ConnectionReuseStrategy, .ContentType, .HeaderElements, .HttpException, .HttpHeaders, .HttpRequestMapper, .HttpResponseFactory, .HttpStatus, .HttpVersion, .ProtocolVersion, .UnsupportedHttpVersionException, org.apache.hc.core5.http.impl.DefaultConnectionReuseStrategy, .Http1StreamListener, .ServerSupport, org.apache.hc.core5.http.io.HttpRequestHandler, .HttpServerConnection, .HttpServerRequestHandler, org.apache.hc.core5.http.io.entity.EntityUtils, .StringEntity, org.apache.hc.core5.http.io.support.BasicHttpServerExpectationDecorator, .BasicHttpServerRequestHandler, org.apache.hc.core5.http.message.BasicClassicHttpResponse, .MessageSupport, org.apache.hc.core5.http.protocol.HttpContext, .HttpCoreContext, .HttpProcessor, org.apache.hc.core5.util.Args

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 HttpRequestHandlers 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 and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
private final ConnectionReuseStrategy
private final HttpProcessor
private final HttpServerRequestHandler
private final Http1StreamListener

Constructor Summary

AccessConstructor and Description
public
HttpService(final HttpProcessor
the processor to use on requests and responses
processor
,
final HttpRequestMapper<HttpRequestHandler>
the handler mapper
handlerMapper
,
final ConnectionReuseStrategy
the connection reuse strategy. If null DefaultConnectionReuseStrategy#INSTANCE will be used.
connReuseStrategy
,
final HttpResponseFactory<ClassicHttpResponse>
the response factory. If null DefaultClassicHttpResponseFactory#INSTANCE will be used.
responseFactory
,
final Http1StreamListener
message stream listener.
streamListener
)

Create a new HTTP service.

public
HttpService(final HttpProcessor
the processor to use on requests and responses
processor
,
final HttpRequestMapper<HttpRequestHandler>
the handler mapper
handlerMapper
,
final ConnectionReuseStrategy
the connection reuse strategy. If null DefaultConnectionReuseStrategy#INSTANCE will be used.
connReuseStrategy
,
final HttpResponseFactory<ClassicHttpResponse>
the response factory. If null DefaultClassicHttpResponseFactory#INSTANCE will be used.
responseFactory
)

Create a new HTTP service.

public
HttpService(final HttpProcessor
the processor to use on requests and responses
processor
,
final HttpServerRequestHandler
the request handler.
requestHandler
,
final ConnectionReuseStrategy
the connection reuse strategy. If null DefaultConnectionReuseStrategy#INSTANCE will be used.
connReuseStrategy
,
final Http1StreamListener
message stream listener.
streamListener
)

Create a new HTTP service.

public
HttpService(final HttpProcessor
the processor to use on requests and responses
processor
,
final HttpServerRequestHandler
the request handler.
requestHandler
)

Create a new HTTP service.

Method Summary

Modifier and TypeMethod and Description
public static HttpService.Builder
builder()

Create a new Builder.

protected void
handleException(final HttpException
the exception.
ex
,
final ClassicHttpResponse
the HTTP response.
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.

public void
handleRequest(final HttpServerConnection
the active connection to the client
conn
,
final HttpContext
the actual execution context.
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
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

connReuseStrategyback to summary
private final ConnectionReuseStrategy connReuseStrategy
processorback to summary
private final HttpProcessor processor
requestHandlerback to summary
private final HttpServerRequestHandler requestHandler
streamListenerback to summary
private final Http1StreamListener streamListener

Constructor Detail

HttpServiceback to summary
public HttpService(final HttpProcessor processor, final HttpRequestMapper<HttpRequestHandler> handlerMapper, final ConnectionReuseStrategy connReuseStrategy, final HttpResponseFactory<ClassicHttpResponse> responseFactory, final Http1StreamListener streamListener)

Create a new HTTP service.

Parameters
processor:HttpProcessor

the processor to use on requests and responses

handlerMapper:HttpRequestMapper<HttpRequestHandler>

the handler mapper

connReuseStrategy:ConnectionReuseStrategy

the connection reuse strategy. If null DefaultConnectionReuseStrategy#INSTANCE will be used.

responseFactory:HttpResponseFactory<ClassicHttpResponse>

the response factory. If null DefaultClassicHttpResponseFactory#INSTANCE will be used.

streamListener:Http1StreamListener

message stream listener.

HttpServiceback to summary
public HttpService(final HttpProcessor processor, final HttpRequestMapper<HttpRequestHandler> handlerMapper, final ConnectionReuseStrategy connReuseStrategy, final HttpResponseFactory<ClassicHttpResponse> responseFactory)

Create a new HTTP service.

Parameters
processor:HttpProcessor

the processor to use on requests and responses

handlerMapper:HttpRequestMapper<HttpRequestHandler>

the handler mapper

connReuseStrategy:ConnectionReuseStrategy

the connection reuse strategy. If null DefaultConnectionReuseStrategy#INSTANCE will be used.

responseFactory:HttpResponseFactory<ClassicHttpResponse>

the response factory. If null DefaultClassicHttpResponseFactory#INSTANCE will be used.

HttpServiceback to summary
public HttpService(final HttpProcessor processor, final HttpServerRequestHandler requestHandler, final ConnectionReuseStrategy connReuseStrategy, final Http1StreamListener streamListener)

Create a new HTTP service.

Parameters
processor:HttpProcessor

the processor to use on requests and responses

requestHandler:HttpServerRequestHandler

the request handler.

connReuseStrategy:ConnectionReuseStrategy

the connection reuse strategy. If null DefaultConnectionReuseStrategy#INSTANCE will be used.

streamListener:Http1StreamListener

message stream listener.

HttpServiceback to summary
public HttpService(final HttpProcessor processor, final HttpServerRequestHandler requestHandler)

Create a new HTTP service.

Parameters
processor:HttpProcessor

the processor to use on requests and responses

requestHandler:HttpServerRequestHandler

the request handler.

Method Detail

builderback to summary
public static HttpService.Builder builder()

Create a new Builder.

Since
5.2
handleExceptionback to summary
protected void handleException(final HttpException ex, final 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:HttpException

the exception.

response:ClassicHttpResponse

the HTTP response.

handleRequestback to summary
public void handleRequest(final HttpServerConnection conn, final 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:HttpServerConnection

the active connection to the client

context:HttpContext

the actual execution context.

Exceptions
IOException:
in case of an I/O error.
HttpException:
in case of HTTP protocol violation or a processing problem.
toStatusCodeback to summary
protected int toStatusCode(final Exception ex)
org.apache.hc.core5.http.impl.io back to summary

public final Class HttpService.Builder

extends Object
Class Inheritance

Builder for HttpService.
Since
5.2

Field Summary

Modifier and TypeField and Description
private ConnectionReuseStrategy
private HttpProcessor
private HttpServerRequestHandler
private Http1StreamListener

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public HttpService
build()

Create a new HTTP service.

public HttpService.Builder
public HttpService.Builder
public HttpService.Builder
public HttpService.Builder
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

connReuseStrategyback to summary
private ConnectionReuseStrategy connReuseStrategy
processorback to summary
private HttpProcessor processor
requestHandlerback to summary
private HttpServerRequestHandler requestHandler
streamListenerback to summary
private Http1StreamListener streamListener

Constructor Detail

Builderback to summary
private Builder()

Method Detail

buildback to summary
public HttpService build()

Create a new HTTP service.

Since
5.2
withConnectionReuseStrategyback to summary
public HttpService.Builder withConnectionReuseStrategy(final ConnectionReuseStrategy connReuseStrategy)
withHttp1StreamListenerback to summary
public HttpService.Builder withHttp1StreamListener(final Http1StreamListener streamListener)
withHttpProcessorback to summary
public HttpService.Builder withHttpProcessor(final HttpProcessor processor)
withHttpServerRequestHandlerback to summary
public HttpService.Builder withHttpServerRequestHandler(final HttpServerRequestHandler requestHandler)