Top Description Inners Fields Constructors Methods
org.apache.http.protocol

public Class HttpService

extends Object
Class Inheritance
Annotations
@SuppressWarnings:deprecation
@Contract
threading:IMMUTABLE_CONDITIONAL
Imports
java.io.IOException, org.apache.http.ConnectionReuseStrategy, .HttpEntity, .HttpEntityEnclosingRequest, .HttpException, .HttpRequest, .HttpResponse, .HttpResponseFactory, .HttpServerConnection, .HttpStatus, .HttpVersion, .MethodNotSupportedException, .ProtocolException, .UnsupportedHttpVersionException, org.apache.http.annotation.Contract, .ThreadingBehavior, org.apache.http.entity.ByteArrayEntity, org.apache.http.impl.DefaultConnectionReuseStrategy, .DefaultHttpResponseFactory, org.apache.http.params.HttpParams, org.apache.http.util.Args, .EncodingUtils, .EntityUtils

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 HttpRequestHandlerMapper to map matching request handler for a particular request URI of an incoming HTTP request.

HttpService can use optional HttpExpectationVerifier to ensure that incoming requests meet server's expectations.

Since
4.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
HttpService.HttpRequestHandlerResolverAdapter

Deprecated Do not use.
Adaptor class to transition from HttpRequestHandlerResolver to HttpRequestHandlerMapper.

Field Summary

Modifier and TypeField and Description
private volatile ConnectionReuseStrategy
private volatile HttpExpectationVerifier
private volatile HttpRequestHandlerMapper
private volatile HttpParams
params

TODO: make all variables final in the next major version

private volatile HttpProcessor
private volatile HttpResponseFactory

Constructor Summary

AccessConstructor and Description
public
HttpService(final HttpProcessor
the processor to use on requests and responses
processor
,
final ConnectionReuseStrategy
the connection reuse strategy
connStrategy
,
final HttpResponseFactory
the response factory
responseFactory
,
final HttpRequestHandlerResolver
the handler resolver. May be null.
handlerResolver
,
final HttpExpectationVerifier
the expectation verifier. May be null.
expectationVerifier
,
final HttpParams
the HTTP parameters
params
)

Create a new HTTP service.
public
HttpService(final HttpProcessor
the processor to use on requests and responses
processor
,
final ConnectionReuseStrategy
the connection reuse strategy
connStrategy
,
final HttpResponseFactory
the response factory
responseFactory
,
final HttpRequestHandlerResolver
the handler resolver. May be null.
handlerResolver
,
final HttpParams
the HTTP parameters
params
)

Create a new HTTP service.
public
HttpService(final HttpProcessor
the processor to use on requests and responses
proc
,
final ConnectionReuseStrategy
the connection reuse strategy
connStrategy
,
final HttpResponseFactory
the response factory
responseFactory
)

Create a new HTTP service.
public
HttpService(final HttpProcessor
the processor to use on requests and responses
processor
,
final ConnectionReuseStrategy
the connection reuse strategy. If null DefaultConnectionReuseStrategy#INSTANCE will be used.
connStrategy
,
final HttpResponseFactory
the response factory. If null DefaultHttpResponseFactory#INSTANCE will be used.
responseFactory
,
final HttpRequestHandlerMapper
the handler mapper. May be null.
handlerMapper
,
final HttpExpectationVerifier
the expectation verifier. May be null.
expectationVerifier
)

Create a new HTTP service.

public
HttpService(final HttpProcessor
the processor to use on requests and responses
processor
,
final ConnectionReuseStrategy
the connection reuse strategy. If null DefaultConnectionReuseStrategy#INSTANCE will be used.
connStrategy
,
final HttpResponseFactory
the response factory. If null DefaultHttpResponseFactory#INSTANCE will be used.
responseFactory
,
final HttpRequestHandlerMapper
the handler mapper. May be null.
handlerMapper
)

Create a new HTTP service.

public
HttpService(final HttpProcessor
the processor to use on requests and responses
processor
,
final HttpRequestHandlerMapper
the handler mapper. May be null.
handlerMapper
)

Create a new HTTP service.

Method Summary

Modifier and TypeMethod and Description
private boolean
canResponseHaveBody(final HttpRequest request, final HttpResponse response)

protected void
doService(final HttpRequest
the HTTP request.
request
,
final HttpResponse
the HTTP response.
response
,
final HttpContext
the execution context.
context
)

The default implementation of this method attempts to resolve an HttpRequestHandler for the request URI of the given request and, if found, executes its HttpRequestHandler#handle(HttpRequest, HttpResponse, HttpContext) method.

public HttpParams
getParams()

Deprecated (4.3) no longer used.
protected void
handleException(final HttpException
the exception.
ex
,
final HttpResponse
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.

public void
setConnReuseStrategy(final ConnectionReuseStrategy connStrategy)

Deprecated (4.1) set ConnectionReuseStrategy using constructor
public void
setExpectationVerifier(final HttpExpectationVerifier expectationVerifier)

Deprecated (4.1) set HttpExpectationVerifier using constructor
public void
setHandlerResolver(final HttpRequestHandlerResolver handlerResolver)

Deprecated (4.1) set HttpRequestHandlerResolver using constructor
public void
setHttpProcessor(final HttpProcessor processor)

Deprecated (4.1) set HttpProcessor using constructor
public void
setParams(final HttpParams params)

Deprecated (4.1) set HttpResponseFactory using constructor
public void
setResponseFactory(final HttpResponseFactory responseFactory)

Deprecated (4.1) set HttpResponseFactory using constructor
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

connStrategyback to summary
private volatile ConnectionReuseStrategy connStrategy
expectationVerifierback to summary
private volatile HttpExpectationVerifier expectationVerifier
handlerMapperback to summary
private volatile HttpRequestHandlerMapper handlerMapper
paramsback to summary
private volatile HttpParams params

Deprecated

as a consequence of HttpParams being deprecated. See corresponding docs for further information.

TODO: make all variables final in the next major version

processorback to summary
private volatile HttpProcessor processor
responseFactoryback to summary
private volatile HttpResponseFactory responseFactory

Constructor Detail

HttpServiceback to summary
public HttpService(final HttpProcessor processor, final ConnectionReuseStrategy connStrategy, final HttpResponseFactory responseFactory, final HttpRequestHandlerResolver handlerResolver, final HttpExpectationVerifier expectationVerifier, final HttpParams params)

Create a new HTTP service.

Parameters
processor:HttpProcessor

the processor to use on requests and responses

connStrategy:ConnectionReuseStrategy

the connection reuse strategy

responseFactory:HttpResponseFactory

the response factory

handlerResolver:HttpRequestHandlerResolver

the handler resolver. May be null.

expectationVerifier:HttpExpectationVerifier

the expectation verifier. May be null.

params:HttpParams

the HTTP parameters

Annotations
@Deprecated
Since
4.1
HttpServiceback to summary
public HttpService(final HttpProcessor processor, final ConnectionReuseStrategy connStrategy, final HttpResponseFactory responseFactory, final HttpRequestHandlerResolver handlerResolver, final HttpParams params)

Create a new HTTP service.

Parameters
processor:HttpProcessor

the processor to use on requests and responses

connStrategy:ConnectionReuseStrategy

the connection reuse strategy

responseFactory:HttpResponseFactory

the response factory

handlerResolver:HttpRequestHandlerResolver

the handler resolver. May be null.

params:HttpParams

the HTTP parameters

Annotations
@Deprecated
Since
4.1
HttpServiceback to summary
public HttpService(final HttpProcessor proc, final ConnectionReuseStrategy connStrategy, final HttpResponseFactory responseFactory)

Create a new HTTP service.

Parameters
proc:HttpProcessor

the processor to use on requests and responses

connStrategy:ConnectionReuseStrategy

the connection reuse strategy

responseFactory:HttpResponseFactory

the response factory

Annotations
@Deprecated
HttpServiceback to summary
public HttpService(final HttpProcessor processor, final ConnectionReuseStrategy connStrategy, final HttpResponseFactory responseFactory, final HttpRequestHandlerMapper handlerMapper, final HttpExpectationVerifier expectationVerifier)

Create a new HTTP service.

Parameters
processor:HttpProcessor

the processor to use on requests and responses

connStrategy:ConnectionReuseStrategy

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

responseFactory:HttpResponseFactory

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

handlerMapper:HttpRequestHandlerMapper

the handler mapper. May be null.

expectationVerifier:HttpExpectationVerifier

the expectation verifier. May be null.

Since
4.3
HttpServiceback to summary
public HttpService(final HttpProcessor processor, final ConnectionReuseStrategy connStrategy, final HttpResponseFactory responseFactory, final HttpRequestHandlerMapper handlerMapper)

Create a new HTTP service.

Parameters
processor:HttpProcessor

the processor to use on requests and responses

connStrategy:ConnectionReuseStrategy

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

responseFactory:HttpResponseFactory

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

handlerMapper:HttpRequestHandlerMapper

the handler mapper. May be null.

Since
4.3
HttpServiceback to summary
public HttpService(final HttpProcessor processor, final HttpRequestHandlerMapper handlerMapper)

Create a new HTTP service.

Parameters
processor:HttpProcessor

the processor to use on requests and responses

handlerMapper:HttpRequestHandlerMapper

the handler mapper. May be null.

Since
4.3

Method Detail

canResponseHaveBodyback to summary
private boolean canResponseHaveBody(final HttpRequest request, final HttpResponse response)
doServiceback to summary
protected void doService(final HttpRequest request, final HttpResponse response, final HttpContext context) throws HttpException, IOException

The default implementation of this method attempts to resolve an HttpRequestHandler for the request URI of the given request and, if found, executes its HttpRequestHandler#handle(HttpRequest, HttpResponse, HttpContext) method.

Super-classes can override this method in order to provide a custom implementation of the request processing logic.

Parameters
request:HttpRequest

the HTTP request.

response:HttpResponse

the HTTP response.

context:HttpContext

the execution context.

Exceptions
HttpException:
in case of HTTP protocol violation or a processing problem.
IOException:
in case of an I/O error.
getParamsback to summary
public HttpParams getParams()

Deprecated

(4.3) no longer used.

Annotations
@Deprecated
handleExceptionback to summary
protected void handleException(final HttpException ex, final HttpResponse 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:HttpResponse

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.
setConnReuseStrategyback to summary
public void setConnReuseStrategy(final ConnectionReuseStrategy connStrategy)

Deprecated

(4.1) set ConnectionReuseStrategy using constructor

Annotations
@Deprecated
setExpectationVerifierback to summary
public void setExpectationVerifier(final HttpExpectationVerifier expectationVerifier)

Deprecated

(4.1) set HttpExpectationVerifier using constructor

Annotations
@Deprecated
setHandlerResolverback to summary
public void setHandlerResolver(final HttpRequestHandlerResolver handlerResolver)

Deprecated

(4.1) set HttpRequestHandlerResolver using constructor

Annotations
@Deprecated
setHttpProcessorback to summary
public void setHttpProcessor(final HttpProcessor processor)

Deprecated

(4.1) set HttpProcessor using constructor

Annotations
@Deprecated
setParamsback to summary
public void setParams(final HttpParams params)

Deprecated

(4.1) set HttpResponseFactory using constructor

Annotations
@Deprecated
setResponseFactoryback to summary
public void setResponseFactory(final HttpResponseFactory responseFactory)

Deprecated

(4.1) set HttpResponseFactory using constructor

Annotations
@Deprecated
org.apache.http.protocol back to summary

private Class HttpService.HttpRequestHandlerResolverAdapter

extends Object
implements HttpRequestHandlerMapper
Class Inheritance
  • java.lang.Object
  • org.apache.http.protocol.HttpService.HttpRequestHandlerResolverAdapter
All Implemented Interfaces
org.apache.http.protocol.HttpRequestHandlerMapper
Annotations
@Deprecated

Deprecated

Do not use.

Adaptor class to transition from HttpRequestHandlerResolver to HttpRequestHandlerMapper.

Field Summary

Modifier and TypeField and Description
private final HttpRequestHandlerResolver
resolver

Deprecated as a consequence of HttpRequestHandlerResolver being deprecated.

Constructor Summary

AccessConstructor and Description
public
HttpRequestHandlerResolverAdapter(final HttpRequestHandlerResolver resolver)

Deprecated as a consequence of HttpRequestHandlerResolver being deprecated.

Method Summary

Modifier and TypeMethod and Description
public HttpRequestHandler
lookup(final HttpRequest
the request to map to a handler
request
)

Implements org.apache.http.protocol.HttpRequestHandlerMapper.lookup.

Looks up a handler matching the given request.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

resolverback to summary
private final HttpRequestHandlerResolver resolver

Deprecated

as a consequence of HttpRequestHandlerResolver being deprecated. See corresponding docs for further information.

Constructor Detail

HttpRequestHandlerResolverAdapterback to summary
public HttpRequestHandlerResolverAdapter(final HttpRequestHandlerResolver resolver)

Deprecated

as a consequence of HttpRequestHandlerResolver being deprecated. See corresponding docs for further information.

Method Detail

lookupback to summary
public HttpRequestHandler lookup(final HttpRequest request)

Implements org.apache.http.protocol.HttpRequestHandlerMapper.lookup.

Doc from org.apache.http.protocol.HttpRequestHandlerMapper.lookup.

Looks up a handler matching the given request.

Parameters
request:HttpRequest

the request to map to a handler

Returns:HttpRequestHandler

HTTP request handler or null if no match is found.

Annotations
@Override