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 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.

  Since:
    4.0

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `HttpService.Builder` Builder for `HttpService`.

  - ### Constructor Summary

    Constructors
    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.
    `HttpService(HttpProcessor processor, HttpServerRequestHandler requestHandler, Http1Config http1Config, ConnectionReuseStrategy connReuseStrategy, Http1StreamListener streamListener)` Create a new HTTP service.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static HttpService.Builder` | `builder()` Create a new `HttpService.Builder`.
    `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 localContext)` 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)`

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

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

- - ### 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 responses
        `handlerMapper` - the handler mapper
        `responseFactory` - 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.

    - #### 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 responses
        `handlerMapper` - the handler mapper
        `connReuseStrategy` - the connection reuse strategy. If `null` `DefaultConnectionReuseStrategy.INSTANCE` will be used.
        `responseFactory` - the response factory. If `null` `DefaultClassicHttpResponseFactory.INSTANCE` will 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 responses
        `requestHandler` - the request handler.
        `connReuseStrategy` - the connection reuse strategy. If `null` `DefaultConnectionReuseStrategy.INSTANCE` will be used.
        `streamListener` - message stream listener.

    - #### HttpService

          public HttpService(HttpProcessor processor,
                             HttpServerRequestHandler requestHandler,
                             Http1Config http1Config,
                             ConnectionReuseStrategy connReuseStrategy,
                             Http1StreamListener streamListener)

      Create a new HTTP service.
      Parameters:
        `processor` - the processor to use on requests and responses
        `requestHandler` - the request handler.
        `http1Config` - HTTP/1 protocol configuration.
        `connReuseStrategy` - the connection reuse strategy. If `null` `DefaultConnectionReuseStrategy.INSTANCE` will be used.
        `streamListener` - message stream listener.
      Since:
        5.3

    - #### HttpService

          public HttpService(HttpProcessor processor,
                             HttpServerRequestHandler requestHandler)

      Create a new HTTP service.
      Parameters:
        `processor` - the processor to use on requests and responses
        `requestHandler` - the request handler.

  - ### Method Detail

    - #### handleRequest

          public void handleRequest(HttpServerConnection conn,
                                    HttpContext localContext)
                             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
        `localContext` - 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,
                                         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(Exception ex)

    - #### builder

          public static HttpService.Builder builder()

      Create a new `HttpService.Builder`.
      Since:
        5.2

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