[utilities COMMIT] in /java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/net: HttpServletRequest...
noreply at shibboleth.net
noreply at shibboleth.net
Wed Apr 24 21:04:08 EDT 2013
Author: putmanb
Date: Wed Apr 24 21:04:07 2013
New Revision: 387
URL: http://svn.shibboleth.net/view/utilities?rev=387&view=rev
Log:
Clean up thread-local holder class, get rid of unnecessary object instantiation.
Non-null constraint checking in proxies.
Modified:
java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/net/HttpServletRequestResponseContext.java
java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/net/ThreadLocalHttpServletRequestProxy.java
java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/net/ThreadLocalHttpServletResponseProxy.java
Modified: java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/net/HttpServletRequestResponseContext.java
URL: http://svn.shibboleth.net/view/utilities/java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/net/HttpServletRequestResponseContext.java?rev=387&r1=386&r2=387&view=diff
==============================================================================
--- java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/net/HttpServletRequestResponseContext.java (original)
+++ java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/net/HttpServletRequestResponseContext.java Wed Apr 24 21:04:07 2013
@@ -16,19 +16,16 @@
* and clean up this context in a servlet container.
* </p>
*/
-public class HttpServletRequestResponseContext {
+public final class HttpServletRequestResponseContext {
- /** ThreadLocal storage for request and response. */
- private static ThreadLocal<HttpServletRequestResponseContext> curr = new ThreadLocal<HttpServletRequestResponseContext>();
+ /** ThreadLocal storage for request. */
+ private static ThreadLocal<HttpServletRequest> currentRequest = new ThreadLocal<HttpServletRequest>();
- /** The stored HTTP servlet request. */
- private HttpServletRequest req;
+ /** ThreadLocal storage for request. */
+ private static ThreadLocal<HttpServletResponse> currentResponse = new ThreadLocal<HttpServletResponse>();
- /** The stored HTTP servlet response. */
- private HttpServletResponse resp;
-
- /** Constructor. Only allow local and subclass instantiation */
- protected HttpServletRequestResponseContext() {};
+ /** Constructor. */
+ private HttpServletRequestResponseContext() {};
/**
* Load the thread-local storage with the current request and response.
@@ -40,28 +37,16 @@
Constraint.isNotNull(request, "HttpServletRequest may not be null");
Constraint.isNotNull(response, "HttpServletResponse may not be null");
- HttpServletRequestResponseContext current = new HttpServletRequestResponseContext();
-
- current.req = request;
- current.resp = response;
-
- curr.set(current);
- }
-
- /**
- * Get the thread-local context instance holding the current request and response.
- *
- * @return the current thread-local context instance
- */
- @Nullable public static HttpServletRequestResponseContext getCurrent() {
- return curr.get();
+ currentRequest.set(request);
+ currentResponse.set(response);
}
/**
- * Clear the current thread-local context instance.
+ * Clear the current thread-local context instances.
*/
public static void clearCurrent() {
- curr.remove();
+ currentRequest.remove();
+ currentResponse.remove();
}
/**
@@ -69,8 +54,8 @@
*
* @return the current request
*/
- @Nonnull public HttpServletRequest getRequest() {
- return req;
+ @Nullable public static HttpServletRequest getRequest() {
+ return currentRequest.get();
}
/**
@@ -78,8 +63,8 @@
*
* @return the current response
*/
- @Nonnull public HttpServletResponse getResponse() {
- return resp;
+ @Nullable public static HttpServletResponse getResponse() {
+ return currentResponse.get();
}
}
Modified: java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/net/ThreadLocalHttpServletRequestProxy.java
URL: http://svn.shibboleth.net/view/utilities/java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/net/ThreadLocalHttpServletRequestProxy.java?rev=387&r1=386&r2=387&view=diff
==============================================================================
--- java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/net/ThreadLocalHttpServletRequestProxy.java (original)
+++ java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/net/ThreadLocalHttpServletRequestProxy.java Wed Apr 24 21:04:07 2013
@@ -31,6 +31,8 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
+import net.shibboleth.utilities.java.support.logic.Constraint;
+
/**
* An implementation of {@link HttpServletRequest} which serves as a proxy for the
* current thread-local servlet request obtained from {@link HttpServletRequestResponseContext}.
@@ -313,7 +315,8 @@
* @return the current request
*/
protected HttpServletRequest getCurrent() {
- return HttpServletRequestResponseContext.getCurrent().getRequest();
+ return Constraint.isNotNull(HttpServletRequestResponseContext.getRequest(),
[... 30 lines stripped ...]
More information about the commits
mailing list