Java Code Examples for com.linecorp.armeria.server.ServiceRequestContext#current()
The following examples show how to use
com.linecorp.armeria.server.ServiceRequestContext#current() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GrpcServiceServerTest.java From armeria with Apache License 2.0 | 6 votes |
@Override public void errorWithMessage(SimpleRequest request, StreamObserver<SimpleResponse> responseObserver) { final Metadata metadata = new Metadata(); metadata.put(STRING_VALUE_KEY, StringValue.newBuilder().setValue("custom metadata").build()); metadata.put(CUSTOM_VALUE_KEY, "custom value"); final ServiceRequestContext ctx = ServiceRequestContext.current(); // gRPC wire format allow comma-separated binary headers. ctx.mutateAdditionalResponseTrailers( mutator -> mutator.add( INT_32_VALUE_KEY.name(), Base64.getEncoder().encodeToString( Int32Value.newBuilder().setValue(10).build().toByteArray()) + ',' + Base64.getEncoder().encodeToString( Int32Value.newBuilder().setValue(20).build().toByteArray()))); responseObserver.onError(Status.ABORTED.withDescription("aborted call").asException(metadata)); }
Example 2
Source File: Main.java From armeria with Apache License 2.0 | 4 votes |
@Provides static ServiceRequestContext context() { return ServiceRequestContext.current(); }
Example 3
Source File: ObservableResponseConverterFunctionTest.java From armeria with Apache License 2.0 | 4 votes |
private static void validateContext(RequestContext ctx) { if (ServiceRequestContext.current() != ctx) { throw new RuntimeException("ServiceRequestContext instances are not same!"); } }
Example 4
Source File: AnnotatedServiceTest.java From armeria with Apache License 2.0 | 4 votes |
static void validateContext(RequestContext ctx) { if (ServiceRequestContext.current() != ctx) { throw new RuntimeException("ServiceRequestContext instances are not same!"); } }