From 9e4766a7234839ed79f48cd8156288b9dd7bb0d9 Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Mon, 24 Apr 2023 23:02:32 +0200 Subject: [PATCH] Remove deprecated PropagationWebGraphQlInterceptor See gh-675 --- .../PropagationWebGraphQlInterceptor.java | 67 ---------- ...PropagationWebGraphQlInterceptorTests.java | 117 ------------------ 2 files changed, 184 deletions(-) delete mode 100644 spring-graphql/src/main/java/org/springframework/graphql/observation/PropagationWebGraphQlInterceptor.java delete mode 100644 spring-graphql/src/test/java/org/springframework/graphql/observation/PropagationWebGraphQlInterceptorTests.java diff --git a/spring-graphql/src/main/java/org/springframework/graphql/observation/PropagationWebGraphQlInterceptor.java b/spring-graphql/src/main/java/org/springframework/graphql/observation/PropagationWebGraphQlInterceptor.java deleted file mode 100644 index d7d9845f..00000000 --- a/spring-graphql/src/main/java/org/springframework/graphql/observation/PropagationWebGraphQlInterceptor.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2020-2022 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.graphql.observation; - -import io.micrometer.tracing.propagation.Propagator; -import reactor.core.publisher.Mono; - -import org.springframework.graphql.server.WebGraphQlInterceptor; -import org.springframework.graphql.server.WebGraphQlRequest; -import org.springframework.graphql.server.WebGraphQlResponse; -import org.springframework.http.HttpHeaders; -import org.springframework.util.Assert; - -/** - * {@link WebGraphQlInterceptor} that copies {@link Propagator propagation} headers - * from the HTTP request to the {@link graphql.GraphQLContext}. - * This makes it possible to propagate tracing information sent by HTTP clients. - * - * @author Brian Clozel - * @since 1.1.1 - * @deprecated since 1.1.4 with no replacement. - */ -@Deprecated(since = "1.1.4", forRemoval = true) -public class PropagationWebGraphQlInterceptor implements WebGraphQlInterceptor { - - private final Propagator propagator; - - /** - * Create an interceptor that leverages the field names used by the given - * {@link Propagator} instance. - * - * @param propagator the propagator that will be used for tracing support - */ - public PropagationWebGraphQlInterceptor(Propagator propagator) { - Assert.notNull(propagator, "propagator should not be null"); - this.propagator = propagator; - } - - @Override - public Mono intercept(WebGraphQlRequest request, Chain chain) { - request.configureExecutionInput((input, inputBuilder) -> { - HttpHeaders headers = request.getHeaders(); - for (String field : this.propagator.fields()) { - if (headers.containsKey(field)) { - inputBuilder.graphQLContext(contextBuilder -> contextBuilder.of(field, headers.getFirst(field))); - } - } - return inputBuilder.build(); - }); - return chain.next(request); - } - -} diff --git a/spring-graphql/src/test/java/org/springframework/graphql/observation/PropagationWebGraphQlInterceptorTests.java b/spring-graphql/src/test/java/org/springframework/graphql/observation/PropagationWebGraphQlInterceptorTests.java deleted file mode 100644 index 1c6186a9..00000000 --- a/spring-graphql/src/test/java/org/springframework/graphql/observation/PropagationWebGraphQlInterceptorTests.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright 2020-2023 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.graphql.observation; - - -import java.net.URI; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import graphql.ExecutionInput; -import graphql.ExecutionResultImpl; -import graphql.GraphQLContext; -import io.micrometer.tracing.Span; -import io.micrometer.tracing.TraceContext; -import io.micrometer.tracing.propagation.Propagator; -import org.junit.jupiter.api.Test; -import reactor.core.publisher.Mono; - -import org.springframework.graphql.ExecutionGraphQlRequest; -import org.springframework.graphql.ExecutionGraphQlResponse; -import org.springframework.graphql.server.WebGraphQlHandler; -import org.springframework.graphql.server.WebGraphQlRequest; -import org.springframework.graphql.support.DefaultExecutionGraphQlResponse; -import org.springframework.http.HttpHeaders; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - -/** - * Tests for {@link PropagationWebGraphQlInterceptor}. - * - * @author Brian Clozel - */ -@SuppressWarnings("removal") -class PropagationWebGraphQlInterceptorTests { - - PropagationWebGraphQlInterceptor interceptor = new PropagationWebGraphQlInterceptor(new TestPropagator()); - - @Test - void rejectsNullPropagator() { - assertThatThrownBy(() -> new PropagationWebGraphQlInterceptor(null)) - .isInstanceOf(IllegalArgumentException.class).hasMessageContaining("propagator should not be null"); - } - - @Test - void copiesPropagationHeadersWhenPresent() { - Map tracingHeaders = Map.of("X-Test-TraceId", "traceId", "baggage", "project=spring"); - Map httpHeaders = new HashMap<>(); - httpHeaders.put("Accept", "application/graphql+json"); - httpHeaders.putAll(tracingHeaders); - WebGraphQlRequest webRequest = createRequest(httpHeaders); - - WebGraphQlHandler handler = WebGraphQlHandler.builder(request -> { - GraphQLContext context = request.toExecutionInput().getGraphQLContext(); - assertThatContextContains(context, tracingHeaders); - return emptyExecutionResult(request); - }).interceptor(this.interceptor).build(); - handler.handleRequest(webRequest).block(); - } - - private void assertThatContextContains(GraphQLContext context, Map tracingHeaders) { - tracingHeaders.forEach((key, value) -> { - String actual = context.get(key); - assertThat(actual).isEqualTo(value); - }); - } - - WebGraphQlRequest createRequest(Map headers) { - HttpHeaders httpHeaders = new HttpHeaders(); - headers.forEach(httpHeaders::set); - return new WebGraphQlRequest( - URI.create("https://example.org/graphql"), httpHeaders, null, Collections.emptyMap(), - Map.of("query", "{ notUsed }"), "1", null); - } - - private Mono emptyExecutionResult(ExecutionGraphQlRequest request) { - return Mono.just(new DefaultExecutionGraphQlResponse( - ExecutionInput.newExecutionInput("{}").build(), - ExecutionResultImpl.newExecutionResult().build())); - } - - - static class TestPropagator implements Propagator { - - @Override - public List fields() { - return List.of("X-Test-TraceId", "baggage"); - } - - @Override - public void inject(TraceContext context, C carrier, Setter setter) { - - } - - @Override - public Span.Builder extract(C carrier, Getter getter) { - return null; - } - } - -} \ No newline at end of file