@FunctionalInterface public interface HeaderServiceCall<Request,Response> extends ServerServiceCall<Request,Response>
of(HeaderServiceCall)
method.
Generally, you shouldn't need to implement this interface with anything but a lambda.Modifier and Type | Method and Description |
---|---|
static <Request,Response> |
compose(Function<RequestHeader,? extends ServerServiceCall<Request,Response>> block)
Compose a header service call.
|
static <Request,Response> |
composeAsync(Function<RequestHeader,CompletionStage<? extends ServerServiceCall<Request,Response>>> block)
Compose a header service call asynchronously.
|
default CompletionStage<Response> |
invoke(Request request)
Invoke the service call.
|
CompletionStage<akka.japi.Pair<ResponseHeader,Response>> |
invokeWithHeaders(RequestHeader requestHeader,
Request request)
Invoke the given action with the request and response headers.
|
static <Request,Response> |
of(HeaderServiceCall<Request,Response> serviceCall)
Convenience method for providing a
HeaderServiceCall when a method accepts a less specific type, eg
ServerServiceCall . |
handleRequestHeader, handleResponseHeader
invoke, withResponseHeader
CompletionStage<akka.japi.Pair<ResponseHeader,Response>> invokeWithHeaders(RequestHeader requestHeader, Request request)
ServerServiceCall.invokeWithHeaders(RequestHeader, Object)
to allow
it to be made an abstract method.invokeWithHeaders
in interface ServerServiceCall<Request,Response>
requestHeader
- The request header.request
- The request message.default CompletionStage<Response> invoke(Request request)
ServiceCall
invoke
in interface ServiceCall<Request,Response>
request
- The request entity.static <Request,Response> HeaderServiceCall<Request,Response> of(HeaderServiceCall<Request,Response> serviceCall)
HeaderServiceCall
when a method accepts a less specific type, eg
ServerServiceCall
. For example, the following method:
<Request, Response> ServerServiceCall<Request, Response> authenticated( Function<User, ServerServiceCall<Request, Response>> serviceCall );Could be invoked like this:
authenticated(user -> HeaderServiceCall.of( (requestHeader, request) -> { ... }));
serviceCall
- The service call.static <Request,Response> HeaderServiceCall<Request,Response> compose(Function<RequestHeader,? extends ServerServiceCall<Request,Response>> block)
<Request, Response> ServerServiceCall<Request, Response> authenticated( Function<String, ServerServiceCall<Request, Response>> block) { return HeaderServiceCall.compose(requestHeader -> { // Get the user String user = requestHeader.principal().orElseGet(() -> { throw new NotAuthenticated("Not authenticated"); }).getName(); // Pass it to the block, and return the resulting call return block.apply(user); }); }
block
- The block that will do the composition.static <Request,Response> HeaderServiceCall<Request,Response> composeAsync(Function<RequestHeader,CompletionStage<? extends ServerServiceCall<Request,Response>>> block)
<Request, Response> ServerServiceCall<Request, Response> authenticated( Function<String, ServerServiceCall<Request, Response>> block) { return HeaderServiceCall.composeAsync(requestHeader -> { // Get the user String userName = requestHeader.principal().orElseGet(() -> { throw new NotAuthenticated("Not authenticated"); }).getName(); // Load the user CompletionStage<User> userFuture = userService.getUser(userName); // Pass it to the block, and return the resulting call return userFuture.thenApply(user -> block.apply(user)); }); }
block
- The block that will do the composition.