org.apache.http.protocol

## Class HttpService

- java.lang.Object
- - org.apache.http.protocol.HttpService

-     @Immutable
      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 `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

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `HttpService(HttpProcessor proc, ConnectionReuseStrategy connStrategy, HttpResponseFactory responseFactory)` Deprecated. (4.1) use `HttpService(HttpProcessor, ConnectionReuseStrategy, HttpResponseFactory, HttpRequestHandlerResolver, HttpParams)`
    `HttpService(HttpProcessor processor, ConnectionReuseStrategy connStrategy, HttpResponseFactory responseFactory, HttpRequestHandlerMapper handlerMapper)` Create a new HTTP service.
    `HttpService(HttpProcessor processor, ConnectionReuseStrategy connStrategy, HttpResponseFactory responseFactory, HttpRequestHandlerMapper handlerMapper, HttpExpectationVerifier expectationVerifier)` Create a new HTTP service.
    `HttpService(HttpProcessor processor, ConnectionReuseStrategy connStrategy, HttpResponseFactory responseFactory, HttpRequestHandlerResolver handlerResolver, HttpExpectationVerifier expectationVerifier, HttpParams params)` Deprecated. (4.3) use `HttpService(HttpProcessor, ConnectionReuseStrategy, HttpResponseFactory, HttpRequestHandlerMapper, HttpExpectationVerifier)`
    `HttpService(HttpProcessor processor, ConnectionReuseStrategy connStrategy, HttpResponseFactory responseFactory, HttpRequestHandlerResolver handlerResolver, HttpParams params)` Deprecated. (4.3) use `HttpService(HttpProcessor, ConnectionReuseStrategy, HttpResponseFactory, HttpRequestHandlerMapper)`
    `HttpService(HttpProcessor processor, HttpRequestHandlerMapper handlerMapper)` Create a new HTTP service.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `doService(HttpRequest request, HttpResponse response, HttpContext 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.
    `HttpParams` | `getParams()` Deprecated. (4.3) no longer used.
    `protected void` | `handleException(HttpException ex, 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.
    `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.
    `void` | `setConnReuseStrategy(ConnectionReuseStrategy connStrategy)` Deprecated. (4.1) set `ConnectionReuseStrategy` using constructor
    `void` | `setExpectationVerifier(HttpExpectationVerifier expectationVerifier)` Deprecated. (4.1) set `HttpExpectationVerifier` using constructor
    `void` | `setHandlerResolver(HttpRequestHandlerResolver handlerResolver)` Deprecated. (4.1) set `HttpRequestHandlerResolver` using constructor
    `void` | `setHttpProcessor(HttpProcessor processor)` Deprecated. (4.1) set `HttpProcessor` using constructor
    `void` | `setParams(HttpParams params)` Deprecated. (4.1) set `HttpResponseFactory` using constructor
    `void` | `setResponseFactory(HttpResponseFactory responseFactory)` Deprecated. (4.1) set `HttpResponseFactory` using constructor

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### HttpService

          @Deprecated
          public HttpService(HttpProcessor processor,
                                ConnectionReuseStrategy connStrategy,
                                HttpResponseFactory responseFactory,
                                HttpRequestHandlerResolver handlerResolver,
                                HttpExpectationVerifier expectationVerifier,
                                HttpParams params)

      Deprecated. (4.3) use `HttpService(HttpProcessor, ConnectionReuseStrategy, HttpResponseFactory, HttpRequestHandlerMapper, HttpExpectationVerifier)`
      Create a new HTTP service.
      Parameters:
        `processor` - the processor to use on requests and responses
        `connStrategy` - the connection reuse strategy
        `responseFactory` - the response factory
        `handlerResolver` - the handler resolver. May be null.
        `expectationVerifier` - the expectation verifier. May be null.
        `params` - the HTTP parameters
      Since:
        4.1

    - #### HttpService

          @Deprecated
          public HttpService(HttpProcessor processor,
                                ConnectionReuseStrategy connStrategy,
                                HttpResponseFactory responseFactory,
                                HttpRequestHandlerResolver handlerResolver,
                                HttpParams params)

      Deprecated. (4.3) use `HttpService(HttpProcessor, ConnectionReuseStrategy, HttpResponseFactory, HttpRequestHandlerMapper)`
      Create a new HTTP service.
      Parameters:
        `processor` - the processor to use on requests and responses
        `connStrategy` - the connection reuse strategy
        `responseFactory` - the response factory
        `handlerResolver` - the handler resolver. May be null.
        `params` - the HTTP parameters
      Since:
        4.1

    - #### HttpService

          @Deprecated
          public HttpService(HttpProcessor proc,
                                ConnectionReuseStrategy connStrategy,
                                HttpResponseFactory responseFactory)

      Deprecated. (4.1) use `HttpService(HttpProcessor, ConnectionReuseStrategy, HttpResponseFactory, HttpRequestHandlerResolver, HttpParams)`
      Create a new HTTP service.
      Parameters:
        `proc` - the processor to use on requests and responses
        `connStrategy` - the connection reuse strategy
        `responseFactory` - the response factory

    - #### HttpService

          public HttpService(HttpProcessor processor,
                     ConnectionReuseStrategy connStrategy,
                     HttpResponseFactory responseFactory,
                     HttpRequestHandlerMapper handlerMapper,
                     HttpExpectationVerifier expectationVerifier)

      Create a new HTTP service.
      Parameters:
        `processor` - the processor to use on requests and responses
        `connStrategy` - the connection reuse strategy. If `null` `DefaultConnectionReuseStrategy.INSTANCE` will be used.
        `responseFactory` - the response factory. If `null` `DefaultHttpResponseFactory.INSTANCE` will be used.
        `handlerMapper` - the handler mapper. May be null.
        `expectationVerifier` - the expectation verifier. May be null.
      Since:
        4.3

    - #### HttpService

          public HttpService(HttpProcessor processor,
                     ConnectionReuseStrategy connStrategy,
                     HttpResponseFactory responseFactory,
                     HttpRequestHandlerMapper handlerMapper)

      Create a new HTTP service.
      Parameters:
        `processor` - the processor to use on requests and responses
        `connStrategy` - the connection reuse strategy. If `null` `DefaultConnectionReuseStrategy.INSTANCE` will be used.
        `responseFactory` - the response factory. If `null` `DefaultHttpResponseFactory.INSTANCE` will be used.
        `handlerMapper` - the handler mapper. May be null.
      Since:
        4.3

    - #### HttpService

          public HttpService(HttpProcessor processor,
                     HttpRequestHandlerMapper handlerMapper)

      Create a new HTTP service.
      Parameters:
        `processor` - the processor to use on requests and responses
        `handlerMapper` - the handler mapper. May be null.
      Since:
        4.3

  - ### Method Detail

    - #### setHttpProcessor

          @Deprecated
          public void setHttpProcessor(HttpProcessor processor)

      Deprecated. (4.1) set `HttpProcessor` using constructor

    - #### setConnReuseStrategy

          @Deprecated
          public void setConnReuseStrategy(ConnectionReuseStrategy connStrategy)

      Deprecated. (4.1) set `ConnectionReuseStrategy` using constructor

    - #### setResponseFactory

          @Deprecated
          public void setResponseFactory(HttpResponseFactory responseFactory)

      Deprecated. (4.1) set `HttpResponseFactory` using constructor

    - #### setParams

          @Deprecated
          public void setParams(HttpParams params)

      Deprecated. (4.1) set `HttpResponseFactory` using constructor

    - #### setHandlerResolver

          @Deprecated
          public void setHandlerResolver(HttpRequestHandlerResolver handlerResolver)

      Deprecated. (4.1) set `HttpRequestHandlerResolver` using constructor

    - #### setExpectationVerifier

          @Deprecated
          public void setExpectationVerifier(HttpExpectationVerifier expectationVerifier)

      Deprecated. (4.1) set `HttpExpectationVerifier` using constructor

    - #### getParams

          @Deprecated
          public HttpParams getParams()

      Deprecated. (4.3) no longer used.

    - #### handleRequest

          public void handleRequest(HttpServerConnection conn,
                           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` - the active connection to the client
        `context` - the actual execution context.
      Throws:
        `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,
                             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` - the exception.
        `response` - the HTTP response.

    - #### doService

          protected void doService(HttpRequest request,
                       HttpResponse response,
                       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` - the HTTP request.
        `response` - the HTTP response.
        `context` - the execution context.
      Throws:
        `IOException` - in case of an I/O error.
        `HttpException` - in case of HTTP protocol violation or a processing problem.

Copyright © 2005–2013 The Apache Software Foundation. All rights reserved.