@FunctionalInterface public interface HeaderServiceCall<Request,Response> extends ServerServiceCall<Request,Response>
This exists as a convenience functional interface for implementing service calls that handle
the request and response headers. It is intended for use in two ways, one is by changing the
return type of the server implementation of a service call to be this more specific type,
allowing the service call to be implemented as a lambda. The other way is to invoke the 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, handleResponseHeaderinvoke, withResponseHeaderCompletionStage<akka.japi.Pair<ResponseHeader,Response>> invokeWithHeaders(RequestHeader requestHeader, Request request)
This is overridden from 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)
ServiceCallinvoke 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)
This is useful for implementing service call composition. For example:
<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)
This is useful for implementing service call composition. For example:
<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.