Class THttpService

All Implemented Interfaces:
Unwrappable, HttpService, Service<HttpRequest,HttpResponse>

public final class THttpService extends DecoratingService<RpcRequest,RpcResponse,HttpRequest,HttpResponse> implements HttpService
An HttpService that handles a Thrift call.
See Also:
  • Method Details

    • builder

      public static THttpServiceBuilder builder()
      Creates a new instance of THttpServiceBuilder which can build an instance of THttpService fluently.

      The default SerializationFormat ThriftSerializationFormats.BINARY will be used when client does not specify one in the request, but also supports ThriftSerializationFormats.values().

      Currently, the only way to specify a serialization format is by using the HTTP session protocol and setting the "Content-Type" header to the appropriate SerializationFormat.mediaType().

    • of

      public static THttpService of(Object implementation)
      Creates a new THttpService with the specified service implementation, supporting all thrift protocols and defaulting to TBinary protocol when the client doesn't specify one.

      Currently, the only way to specify a serialization format is by using the HTTP session protocol and setting the "Content-Type" header to the appropriate SerializationFormat.mediaType().

      Parameters:
      implementation - an implementation of *.Iface or *.AsyncIface service interface generated by the Apache Thrift compiler
    • of

      public static THttpService of(Object implementation, SerializationFormat defaultSerializationFormat)
      Creates a new THttpService with the specified service implementation, supporting all thrift protocols and defaulting to the specified defaultSerializationFormat when the client doesn't specify one.

      Currently, the only way to specify a serialization format is by using the HTTP session protocol and setting the "Content-Type" header to the appropriate SerializationFormat.mediaType().

      Parameters:
      implementation - an implementation of *.Iface or *.AsyncIface service interface generated by the Apache Thrift compiler
      defaultSerializationFormat - the default serialization format to use when not specified by the client
    • ofFormats

      public static THttpService ofFormats(Object implementation, SerializationFormat defaultSerializationFormat, SerializationFormat... otherSupportedSerializationFormats)
      Creates a new THttpService with the specified service implementation, supporting only the formats specified and defaulting to the specified defaultSerializationFormat when the client doesn't specify one.

      Currently, the only way to specify a serialization format is by using the HTTP session protocol and setting the "Content-Type" header to the appropriate SerializationFormat.mediaType().

      Parameters:
      implementation - an implementation of *.Iface or *.AsyncIface service interface generated by the Apache Thrift compiler
      defaultSerializationFormat - the default serialization format to use when not specified by the client
      otherSupportedSerializationFormats - other serialization formats that should be supported by this service in addition to the default
    • ofFormats

      public static THttpService ofFormats(Object implementation, SerializationFormat defaultSerializationFormat, Iterable<SerializationFormat> otherSupportedSerializationFormats)
      Creates a new THttpService with the specified service implementation, supporting the protocols specified in otherSupportedSerializationFormats and defaulting to the specified defaultSerializationFormat when the client doesn't specify one.

      Currently, the only way to specify a serialization format is by using the HTTP session protocol and setting the "Content-Type" header to the appropriate SerializationFormat.mediaType().

      Parameters:
      implementation - an implementation of *.Iface or *.AsyncIface service interface generated by the Apache Thrift compiler
      defaultSerializationFormat - the default serialization format to use when not specified by the client
      otherSupportedSerializationFormats - other serialization formats that should be supported by this service in addition to the default
    • newDecorator

      public static Function<? super RpcService,THttpService> newDecorator()
      Creates a new decorator that supports all thrift protocols and defaults to TBinary protocol when the client doesn't specify one.

      Currently, the only way to specify a serialization format is by using the HTTP session protocol and setting the "Content-Type" header to the appropriate SerializationFormat.mediaType().

    • newDecorator

      public static Function<? super RpcService,THttpService> newDecorator(SerializationFormat defaultSerializationFormat)
      Creates a new decorator that supports all thrift protocols and defaults to the specified defaultSerializationFormat when the client doesn't specify one. Currently, the only way to specify a serialization format is by using the HTTP session protocol and setting the "Content-Type" header to the appropriate SerializationFormat.mediaType().
      Parameters:
      defaultSerializationFormat - the default serialization format to use when not specified by the client
    • newDecorator

      public static Function<? super RpcService,THttpService> newDecorator(SerializationFormat defaultSerializationFormat, SerializationFormat... otherSupportedSerializationFormats)
      Creates a new decorator that supports only the formats specified and defaults to the specified defaultSerializationFormat when the client doesn't specify one. Currently, the only way to specify a serialization format is by using the HTTP session protocol and setting the "Content-Type" header to the appropriate SerializationFormat.mediaType().
      Parameters:
      defaultSerializationFormat - the default serialization format to use when not specified by the client
      otherSupportedSerializationFormats - other serialization formats that should be supported by this service in addition to the default
    • newDecorator

      public static Function<? super RpcService,THttpService> newDecorator(SerializationFormat defaultSerializationFormat, Iterable<SerializationFormat> otherSupportedSerializationFormats)
      Creates a new decorator that supports the protocols specified in otherSupportedSerializationFormats and defaults to the specified defaultSerializationFormat when the client doesn't specify one. Currently, the only way to specify a serialization format is by using the HTTP session protocol and setting the "Content-Type" header to the appropriate SerializationFormat.mediaType().
      Parameters:
      defaultSerializationFormat - the default serialization format to use when not specified by the client
      otherSupportedSerializationFormats - other serialization formats that should be supported by this service in addition to the default
    • entries

      public Map<String,ThriftServiceEntry> entries()
      Returns the information about the Thrift services being served.
      Returns:
      a Map whose key is a service name, which could be an empty string if this service is not multiplexed
    • supportedSerializationFormats

      public Set<SerializationFormat> supportedSerializationFormats()
      Returns the SerializationFormats supported by this service.
    • defaultSerializationFormat

      public SerializationFormat defaultSerializationFormat()
      Returns the default SerializationFormat of this service.
    • serviceAdded

      public void serviceAdded(ServiceConfig cfg) throws Exception
      Description copied from interface: Service
      Invoked when this service has been added to a Server with the specified configuration. Please note that this method can be invoked more than once if this service has been added more than once.
      Specified by:
      serviceAdded in interface Service<HttpRequest,HttpResponse>
      Overrides:
      serviceAdded in class DecoratingService<RpcRequest,RpcResponse,HttpRequest,HttpResponse>
      Throws:
      Exception
    • serve

      public HttpResponse serve(ServiceRequestContext ctx, HttpRequest req) throws Exception
      Description copied from interface: Service
      Serves an incoming Request.
      Specified by:
      serve in interface HttpService
      Specified by:
      serve in interface Service<HttpRequest,HttpResponse>
      Parameters:
      ctx - the context of the received Request
      req - the received Request
      Returns:
      the Response
      Throws:
      Exception
    • exchangeType

      public ExchangeType exchangeType(RoutingContext routingContext)
      Description copied from interface: HttpService
      Determines an ExchangeType for this HttpService from the given RoutingContext. By default, ExchangeType.BIDI_STREAMING is set.

      Note that an HttpRequest will be aggregated before serving the HttpService if ExchangeType.UNARY or ExchangeType.RESPONSE_STREAMING is set.

      Specified by:
      exchangeType in interface HttpService