Skip to content

Commit ed01396

Browse files
committed
fix: forward request context and session in fault tolerance request filter
1 parent 88175fa commit ed01396

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

gateway/src/main/java/com/mx/path/gateway/connect/filter/FaultTolerantRequestFilter.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import com.mx.path.core.common.http.HttpStatus;
88
import com.mx.path.core.common.process.FaultTolerantExecutor;
99
import com.mx.path.core.context.RequestContext;
10+
import com.mx.path.core.context.ResponseContext;
11+
import com.mx.path.core.context.Session;
1012
import com.mx.path.core.context.facility.Facilities;
1113
import com.mx.path.gateway.context.GatewayRequestContext;
1214

@@ -21,8 +23,26 @@ public final void execute(Request request, Response response) {
2123
FaultTolerantExecutor faultTolerantExecutor = Facilities.getFaultTolerantExecutor(RequestContext.current().getClientId());
2224
if (faultTolerantExecutor != null) {
2325
try {
26+
RequestContext currentRequestContext = RequestContext.current();
27+
ResponseContext currentResponseContext = ResponseContext.current();
28+
Session currentSession = Session.current();
29+
2430
String scope = request.getFaultTolerantScope() != null ? request.getFaultTolerantScope() : buildScope();
2531
faultTolerantExecutor.submit(scope, scopeConfigurations -> {
32+
33+
// Forward context objects to current thread.
34+
if (currentRequestContext != null) {
35+
currentRequestContext.register();
36+
}
37+
38+
if (currentResponseContext != null) {
39+
currentResponseContext.register();
40+
}
41+
42+
if (currentSession != null) {
43+
Session.setCurrent(currentSession);
44+
}
45+
2646
// If a request timeout was explicitly provided (should be rare) we respect it. Otherwise, we use the timeout
2747
// that the FaultTolerantExecutor is using for this request.
2848
if (request.getRequestTimeOut() == null) {

0 commit comments

Comments
 (0)