forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix inconsistent behaviour in REST Client reactive when using contexts
Fix quarkusio#32839
- Loading branch information
Showing
4 changed files
with
54 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
.../org/jboss/resteasy/reactive/client/handlers/ClientSwitchToRequestContextRestHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package org.jboss.resteasy.reactive.client.handlers; | ||
|
||
import java.util.concurrent.Executor; | ||
|
||
import org.jboss.resteasy.reactive.client.impl.ClientRequestContextImpl; | ||
import org.jboss.resteasy.reactive.client.impl.RestClientRequestContext; | ||
import org.jboss.resteasy.reactive.client.spi.ClientRestHandler; | ||
|
||
import io.vertx.core.Context; | ||
import io.vertx.core.Handler; | ||
import io.vertx.core.Vertx; | ||
|
||
/** | ||
* This handler ensures that the context to use is the same as the client request context, which is important to keep the | ||
* request context in sync when updating the response. | ||
*/ | ||
public class ClientSwitchToRequestContextRestHandler implements ClientRestHandler { | ||
@Override | ||
public void handle(RestClientRequestContext requestContext) throws Exception { | ||
Context current = Vertx.currentContext(); | ||
ClientRequestContextImpl clientRequestContext = requestContext.getClientRequestContext(); | ||
if (clientRequestContext == null) { | ||
return; | ||
} | ||
|
||
Context captured = clientRequestContext.getContext(); | ||
if (captured != null && current != captured) { | ||
requestContext.suspend(); | ||
requestContext.resume(new Executor() { | ||
@Override | ||
public void execute(Runnable command) { | ||
captured.runOnContext(new Handler<Void>() { | ||
@Override | ||
public void handle(Void unused) { | ||
command.run(); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters