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:
ThriftProtocolFactories
  • 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

      @Deprecated public static THttpService of​(Map<String,​?> implementations)
      Deprecated.
      Creates a new multiplexed THttpService with the specified service implementations, 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:
      implementations - a Map whose key is service name and value is the 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
    • of

      @Deprecated public static THttpService of​(Map<String,​?> implementations, SerializationFormat defaultSerializationFormat)
      Deprecated.
      Creates a new multiplexed THttpService with the specified service implementations, 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:
      implementations - a Map whose key is service name and value is the 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

      @Deprecated public static THttpService ofFormats​(Map<String,​?> implementations, SerializationFormat defaultSerializationFormat, SerializationFormat... otherSupportedSerializationFormats)
      Deprecated.
      Creates a new multiplexed THttpService with the specified service implementations, 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:
      implementations - a Map whose key is service name and value is the 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
    • ofFormats

      @Deprecated public static THttpService ofFormats​(Map<String,​?> implementations, SerializationFormat defaultSerializationFormat, Iterable<SerializationFormat> otherSupportedSerializationFormats)
      Deprecated.
      Creates a new multiplexed THttpService with the specified service implementations, 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:
      implementations - a Map whose key is service name and value is the 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
    • allowedSerializationFormats

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

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

      public SerializationFormat defaultSerializationFormat()
      Returns the default SerializationFormat of this service.
    • 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