Class THttpServiceBuilder
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 Summary
Modifier and TypeMethodDescriptionaddService
(Object implementation) Adds a new service implementation to the builder.addService
(String name, Object implementation) Adds a newTMultiplexed
service to the builder.build()
Builds a new instance ofTHttpService
.decorate
(Function<? super RpcService, ? extends RpcService> decoratorFunction) AFunction<? super RpcService, ? extends RpcService>
to decorate theRpcService
.defaultSerializationFormat
(SerializationFormat defaultSerializationFormat) Adds the default serialization format which will be used when the client does not specify one in request.exceptionHandler
(BiFunction<? super ServiceRequestContext, ? super Throwable, ? extends RpcResponse> exceptionHandler) Sets theBiFunction
that returns anRpcResponse
using the givenThrowable
andServiceRequestContext
.Function<? super RpcService,
THttpService> Returns a newly-createdTHttpService
decorator with the properties of this builder.otherSerializationFormats
(SerializationFormat otherSerializationFormat) Adds otherSerializationFormat
to the builder.otherSerializationFormats
(Iterable<SerializationFormat> otherSerializationFormats) Adds otherSerializationFormat
s to the builder.
-
Method Details
-
addService
Adds a newTMultiplexed
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
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
Adds otherSerializationFormat
to the builder. By default, allSerializationFormat
s inThriftSerializationFormats
are supported. If nothing is specified then they are added. To add a new custom Thrift serialization format, define a new SPIThriftProtocolFactoryProvider
.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 appropriateSerializationFormat.mediaType()
. -
otherSerializationFormats
public THttpServiceBuilder otherSerializationFormats(Iterable<SerializationFormat> otherSerializationFormats) Adds otherSerializationFormat
s to the builder. If nothing is specified then allSerializationFormat
s returned byThriftSerializationFormats.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 appropriateSerializationFormat.mediaType()
. -
defaultSerializationFormat
public THttpServiceBuilder defaultSerializationFormat(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 appropriateSerializationFormat.mediaType()
. -
exceptionHandler
public THttpServiceBuilder exceptionHandler(BiFunction<? super ServiceRequestContext, ? super Throwable, ? extends RpcResponse> exceptionHandler) Sets theBiFunction
that returns anRpcResponse
using the givenThrowable
andServiceRequestContext
. -
decorate
public THttpServiceBuilder decorate(Function<? super RpcService, ? extends RpcService> decoratorFunction) AFunction<? super RpcService, ? extends RpcService>
to decorate theRpcService
. -
build
Builds a new instance ofTHttpService
. -
newDecorator
Returns a newly-createdTHttpService
decorator with the properties of this builder.
-