Skip to content

Commit 8b9eb75

Browse files
committed
Switch to the new nested context API
1 parent 63f65bf commit 8b9eb75

File tree

2 files changed

+4
-16
lines changed

2 files changed

+4
-16
lines changed

extensions/resteasy-reactive/rest-client/deployment/src/test/java/io/quarkus/rest/client/reactive/ContextLocalPropagationTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ private static Context determineRestClientContext() {
110110
// We will need a proper solution soon, but as we need to have a proper way to
111111
// set contextual information in Quarkus 3.20 (LTS), we can't risk breaking
112112
// client code everywhere, so for now we will tell people to check the context
113-
Optional<Object> maybeParentContext = ContextLocals.get("__PARENT_CONTEXT__");
113+
var maybeParentContext = ContextLocals.getParentContext();
114114
Context effectiveContext;
115-
if (maybeParentContext.isPresent()) {
116-
effectiveContext = (Context) maybeParentContext.get();
115+
if (maybeParentContext != null) {
116+
effectiveContext = maybeParentContext;
117117
} else {
118118
effectiveContext = Vertx.currentContext();
119119
}

independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/impl/ClientRequestContextImpl.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,7 @@ public ClientRequestContextImpl(RestClientRequestContext restClientRequestContex
6565
// Always create a duplicated context because each REST Client invocation must have its own context
6666
// A separate context allows integrations like OTel to create a separate Span for each invocation (expected)
6767
Context current = client.vertx.getOrCreateContext();
68-
this.context = VertxContext.createNewDuplicatedContext(current);
69-
// If an interceptor wants to access the parent context, it can do so by using the "__PARENT_CONTEXT__" key.
70-
// This approach is compatible with the next-to-be nested context support (from SmallRye Common).
71-
// The "__PARENT_CONTEXT__" key will continue to reference the _parent_ context.
72-
// So, currently, an interceptor needing to read from the original context will need to use:
73-
// Context parent = ContextLocals.get("__PARENT_CONTEXT__");
74-
// V v = parent.getLocal("some-key");
75-
// To write to the original context, it will need to use:
76-
// Context parent = ContextLocals.get("__PARENT_CONTEXT__");
77-
// parent.putLocal("some-key", someValue);
78-
// Note that unlike with nested contexts, multiple child contexts can write to the same parent key, and may
79-
// lead to a race condition.
80-
this.context.putLocal("__PARENT_CONTEXT__", current);
68+
this.context = VertxContext.newNestedContext(current);
8169
restClientRequestContext.properties.put(VERTX_CONTEXT_PROPERTY, context);
8270
}
8371

0 commit comments

Comments
 (0)