File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed
servletrequest-propagation
src/main/java/nl/talsmasoftware/context/servletrequest Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change 1+ [ ![ Released Version] [ maven-img ]] [ maven ]
2+
3+ # ServletRequest propagation library
4+
5+ Adding the ` servletrequest-propagation ` jar to your classpath
6+ provides static access to the current ` ServletRequest `
7+ via the ` ServletRequestContextManager.currentServletRequest() ` method
8+ if the ` ServletRequestContextFilter ` was applied to the inbound request.
9+
10+ ## How to use this library
11+
12+ 1 . Add it to your classpath.
13+ ``` xml
14+ <dependency >
15+ <groupId >nl.talsmasoftware.context</groupId >
16+ <artifactId >servletrequest-propagation</artifactId >
17+ <version >[see maven-central version above]</version >
18+ </dependency >
19+ ```
20+
21+ 2 . Include the ` ServletRequestContextFilter ` in your application.
22+
23+ Done!
24+
25+ Now the ` ServletRequestContextManager.currentServletRequest() ` is propagated into each
26+ snapshot created by the ` ContextManagers.createSnapshot() ` method.
27+ This includes all usages of the ` ContextAwareExecutorService ` .
28+
29+
30+ [ maven-img ] : https://img.shields.io/maven-central/v/nl.talsmasoftware.context/servletrequest-propagation.svg
31+ [ maven ] : http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22nl.talsmasoftware.context%22%20AND%20a%3A%22servletrequest-propagation%22
Original file line number Diff line number Diff line change 2727 */
2828public final class ServletRequestContextManager implements ContextManager <ServletRequest > {
2929
30+ /**
31+ * Static utility method to obtain the current {@link ServletRequest} (if available).
32+ *
33+ * @return The current ServletRequest if available, or <code>null</code> otherwise.
34+ */
35+ public static ServletRequest currentServletRequest () {
36+ Context <ServletRequest > current = ServletRequestContext .current ();
37+ return current == null ? null : current .getValue ();
38+ }
39+
3040 public Context <ServletRequest > initializeNewContext (ServletRequest value ) {
3141 return new ServletRequestContext (value );
3242 }
You can’t perform that action at this time.
0 commit comments