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.
Support CP for undertow servlet request quarkusio#2981
- Loading branch information
Showing
5 changed files
with
66 additions
and
0 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
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
...ertow/runtime/src/main/java/io/quarkus/undertow/runtime/ServletThreadContextProvider.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 io.quarkus.undertow.runtime; | ||
|
||
import java.util.Map; | ||
|
||
import org.eclipse.microprofile.context.spi.ThreadContextProvider; | ||
import org.eclipse.microprofile.context.spi.ThreadContextSnapshot; | ||
|
||
import io.undertow.servlet.handlers.ServletRequestContext; | ||
|
||
public class ServletThreadContextProvider implements ThreadContextProvider { | ||
|
||
@Override | ||
public ThreadContextSnapshot currentContext(Map<String, String> props) { | ||
ServletRequestContext captured = ServletRequestContext.current(); | ||
return () -> { | ||
ServletRequestContext current = restore(captured); | ||
return () -> restore(current); | ||
}; | ||
} | ||
|
||
private ServletRequestContext restore(ServletRequestContext context) { | ||
ServletRequestContext currentContext = ServletRequestContext.current(); | ||
if (context == null) | ||
ServletRequestContext.clearCurrentServletAttachments(); | ||
else | ||
ServletRequestContext.setCurrentRequestContext(context); | ||
return currentContext; | ||
} | ||
|
||
@Override | ||
public ThreadContextSnapshot clearedContext(Map<String, String> props) { | ||
return () -> { | ||
ServletRequestContext current = restore(null); | ||
return () -> restore(current); | ||
}; | ||
} | ||
|
||
@Override | ||
public String getThreadContextType() { | ||
return "Servlet"; | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...in/resources/META-INF/services/org.eclipse.microprofile.context.spi.ThreadContextProvider
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 @@ | ||
io.quarkus.undertow.runtime.ServletThreadContextProvider |