Class THttpServiceBuilder

java.lang.Object
com.linecorp.armeria.server.thrift.THttpServiceBuilder

public final class THttpServiceBuilder extends Object
A fluent builder to build an instance of THttpService. This builder allows to bind multiple thrift service implementations along with mixing TMultiplexed protocol to a route.

Example


 Server server =
     Server.builder()
           .http(8080)
           .service("/", THttpService.builder()
                                     .addService(new FooService())              // foo() method
                                     .addService(new BarService())              // bar() method
                                     .addService("foobar", new FooBarService()) // TMultiplexed service
                                     .build())
           .build();
 

When the thrift request has a method foo() then FooService.foo() handles the request and similarly when thrift request has a method bar() then BarService.bar() handles the request. And when the service name is "foobar" then FooBarService

See Also:
  • Method Details

    • addService

      public THttpServiceBuilder addService(String name, Object implementation)
      Adds a new TMultiplexed service to the builder.
      Parameters:
      name - name of the service.
      implementation - an implementation of *.Iface or *.AsyncIface service interface generated by the Apache Thrift compiler.
    • addService

      public THttpServiceBuilder addService(Object implementation)
      Adds a new service implementation to the builder.
      Parameters:
      implementation - an implementation of *.Iface or *.AsyncIface service interface generated by the Apache Thrift compiler
    • otherSerializationFormats

      public THttpServiceBuilder otherSerializationFormats(com.linecorp.armeria.common.SerializationFormat otherSerializationFormat)
      Adds other SerializationFormat to the builder. By default, all SerializationFormats in ThriftSerializationFormats are supported. If nothing is specified then they are added. To add a new custom Thrift serialization format, define a new SPI ThriftProtocolFactoryProvider.

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

    • otherSerializationFormats

      public THttpServiceBuilder otherSerializationFormats(Iterable<com.linecorp.armeria.common.SerializationFormat> otherSerializationFormats)
      Adds other SerializationFormats to the builder. If nothing is specified then all SerializationFormats returned by ThriftSerializationFormats.values() are added.

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

    • defaultSerializationFormat

      public THttpServiceBuilder defaultSerializationFormat(com.linecorp.armeria.common.SerializationFormat defaultSerializationFormat)
      Adds the default serialization format which will be used when the client does not specify one in request.

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

    • maxRequestStringLength

      public THttpServiceBuilder maxRequestStringLength(int maxRequestStringLength)
      Sets the maximum allowed number of bytes to read from the transport for variable-length fields (such as strings or binary). If unspecified, the default value of ServerBuilder.maxRequestLength(long) will be used.

      Note that this options is only valid for TBinaryProtocol and TCompactProtocol.

      Parameters:
      maxRequestStringLength - the maximum allowed string length. 0 disables the length limit.
      See Also:
      • ServerBuilder.maxRequestLength(long)
    • maxRequestContainerLength

      public THttpServiceBuilder maxRequestContainerLength(int maxRequestContainerLength)
      Sets the maximum allowed number of containers to read from the transport for maps, sets and lists. If unspecified, the default value of ServerBuilder.maxRequestLength(long) will be used.

      Note that this options is only valid for TBinaryProtocol and TCompactProtocol.

      Parameters:
      maxRequestContainerLength - the maximum allowed string length. 0 disables the length limit.
    • exceptionHandler

      public THttpServiceBuilder exceptionHandler(BiFunction<? super com.linecorp.armeria.server.ServiceRequestContext,? super Throwable,? extends com.linecorp.armeria.common.RpcResponse> exceptionHandler)
      Sets the BiFunction that returns an RpcResponse using the given Throwable and ServiceRequestContext.
    • decorate

      public THttpServiceBuilder decorate(Function<? super com.linecorp.armeria.server.RpcService,? extends com.linecorp.armeria.server.RpcService> decoratorFunction)
      A Function<? super RpcService, ? extends RpcService> to decorate the RpcService.
    • build

      public THttpService build()
      Builds a new instance of THttpService.
    • newDecorator

      public Function<? super com.linecorp.armeria.server.RpcService,THttpService> newDecorator()
      Returns a newly-created THttpService decorator with the properties of this builder.