Skip to content

Commit 3b2bc13

Browse files
committed
Add README to servletrequest-propagation module.
This fixes #12.
1 parent 36f5e8c commit 3b2bc13

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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

servletrequest-propagation/src/main/java/nl/talsmasoftware/context/servletrequest/ServletRequestContextManager.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@
2727
*/
2828
public 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
}

0 commit comments

Comments
 (0)