Skip to content

Commit 8ca43a4

Browse files
cescoffiergeoand
authored andcommitted
Keep a reference on the parent/original context to allow accessing it from Rest Client interceptors
1 parent f7c4acf commit 8ca43a4

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,18 @@ public ClientRequestContextImpl(RestClientRequestContext restClientRequestContex
6666
// A separate context allows integrations like OTel to create a separate Span for each invocation (expected)
6767
Context current = client.vertx.getOrCreateContext();
6868
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);
6981
restClientRequestContext.properties.put(VERTX_CONTEXT_PROPERTY, context);
7082
}
7183

0 commit comments

Comments
 (0)