From 767b33ab98da2455d709e1fd9ab87942082eda1c Mon Sep 17 00:00:00 2001 From: Toropanov Nikolai Date: Thu, 17 Feb 2022 15:44:59 +0300 Subject: [PATCH] closes #30 --- README.md | 28 +++++++++---------- .../HeaderPropagationInterceptor.java | 8 +++++- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index a7b57a7..a247274 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ [![Stability: Maintenance](https://masterminds.github.io/stability/maintenance.svg)](https://masterminds.github.io/stability/maintenance.html) [![Docker Cloud Build Status](https://img.shields.io/docker/cloud/build/adven27/grpc-wiremock?label=build&logo=docker)](https://hub.docker.com/repository/docker/adven27/grpc-wiremock/builds) -[![Docker Image Version (tag latest semver)](https://img.shields.io/docker/v/adven27/grpc-wiremock/1.3.4?logo=docker)](https://hub.docker.com/repository/docker/adven27/grpc-wiremock/general) +[![Docker Image Version (tag latest semver)](https://img.shields.io/docker/v/adven27/grpc-wiremock/1.3.6?logo=docker)](https://hub.docker.com/repository/docker/adven27/grpc-wiremock/general) # Overview grpc-wiremock is a **mock server** for **GRPC** services implemented as a wrapper around the [WireMock](http://wiremock.org) http server. @@ -71,19 +71,19 @@ Stubbing should be done via [WireMock JSON API](http://wiremock.org/docs/stubbin Default error (not `200 OK`) mapping is based on https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto : -| HTTP Status Code | GRPC Status | -| ------------------------ |:-----------------:| -| 400 Bad Request | INVALID_ARGUMENT | -| 401 Unauthorized | UNAUTHENTICATED | -| 403 Forbidden | PERMISSION_DENIED | -| 404 Not Found | NOT_FOUND | -| 409 Conflict | ALREADY_EXISTS | -| 429 Too Many Requests | RESOURCE_EXHAUSTED| -| 499 Client Closed Request| CANCELLED | -| 500 Internal Server Error| INTERNAL | -| 501 Not Implemented | UNIMPLEMENTED | -| 503 Service Unavailable | UNAVAILABLE | -| 504 Gateway Timeout | DEADLINE_EXCEEDED | +| HTTP Status Code | GRPC Status | +|---------------------------|:-------------------| +| 400 Bad Request | INVALID_ARGUMENT | +| 401 Unauthorized | UNAUTHENTICATED | +| 403 Forbidden | PERMISSION_DENIED | +| 404 Not Found | NOT_FOUND | +| 409 Conflict | ALREADY_EXISTS | +| 429 Too Many Requests | RESOURCE_EXHAUSTED | +| 499 Client Closed Request | CANCELLED | +| 500 Internal Server Error | INTERNAL | +| 501 Not Implemented | UNIMPLEMENTED | +| 503 Service Unavailable | UNAVAILABLE | +| 504 Gateway Timeout | DEADLINE_EXCEEDED | And could be overridden or augmented by overriding or augmenting the following properties: ```yaml diff --git a/src/main/java/io/adven/grpc/wiremock/HeaderPropagationInterceptor.java b/src/main/java/io/adven/grpc/wiremock/HeaderPropagationInterceptor.java index fc565f4..ae7fa2f 100644 --- a/src/main/java/io/adven/grpc/wiremock/HeaderPropagationInterceptor.java +++ b/src/main/java/io/adven/grpc/wiremock/HeaderPropagationInterceptor.java @@ -18,19 +18,25 @@ import static java.util.stream.Collectors.toMap; public class HeaderPropagationInterceptor implements ServerInterceptor { + public static final String X_GRPC_FULL_METHOD_NAME = "x-grpc-full-method-name"; public static final Context.Key> HEADERS = Context.key("GRPC_WIREMOCK_HEADERS"); private static final BaseEncoding BASE64_ENCODING_OMIT_PADDING = BaseEncoding.base64().omitPadding(); @Override public ServerCall.Listener interceptCall(ServerCall call, final Metadata headers, ServerCallHandler next) { return Contexts.interceptCall( - Context.current().withValue(HEADERS, asMap(headers)), + Context.current().withValue(HEADERS, enriched(asMap(headers), call)), call, headers, next ); } + private Map enriched(Map map, ServerCall call) { + map.put(X_GRPC_FULL_METHOD_NAME, call.getMethodDescriptor().getFullMethodName()); + return map; + } + private Map asMap(Metadata headers) { return headers.keys().stream().collect( toMap(