preserve custom pre-bound RequestAttributes implementations (for Grails)
This commit is contained in:
parent
68e07239c7
commit
5ff6191d72
|
|
@ -502,8 +502,11 @@ public abstract class FrameworkPortlet extends GenericPortletBean
|
||||||
|
|
||||||
// Expose current RequestAttributes to current thread.
|
// Expose current RequestAttributes to current thread.
|
||||||
RequestAttributes previousRequestAttributes = RequestContextHolder.getRequestAttributes();
|
RequestAttributes previousRequestAttributes = RequestContextHolder.getRequestAttributes();
|
||||||
PortletRequestAttributes requestAttributes = new PortletRequestAttributes(request);
|
PortletRequestAttributes requestAttributes = null;
|
||||||
|
if (previousRequestAttributes == null || previousRequestAttributes.getClass().equals(PortletRequestAttributes.class)) {
|
||||||
|
requestAttributes = new PortletRequestAttributes(request);
|
||||||
RequestContextHolder.setRequestAttributes(requestAttributes, this.threadContextInheritable);
|
RequestContextHolder.setRequestAttributes(requestAttributes, this.threadContextInheritable);
|
||||||
|
}
|
||||||
|
|
||||||
if (logger.isTraceEnabled()) {
|
if (logger.isTraceEnabled()) {
|
||||||
logger.trace("Bound request context to thread: " + request);
|
logger.trace("Bound request context to thread: " + request);
|
||||||
|
|
@ -541,12 +544,12 @@ public abstract class FrameworkPortlet extends GenericPortletBean
|
||||||
}
|
}
|
||||||
|
|
||||||
finally {
|
finally {
|
||||||
// Reset thread-bound context.
|
// Clear request attributes and reset thread-bound context.
|
||||||
RequestContextHolder.setRequestAttributes(previousRequestAttributes, this.threadContextInheritable);
|
|
||||||
LocaleContextHolder.setLocaleContext(previousLocaleContext, this.threadContextInheritable);
|
LocaleContextHolder.setLocaleContext(previousLocaleContext, this.threadContextInheritable);
|
||||||
|
if (requestAttributes != null) {
|
||||||
// Clear request attributes.
|
RequestContextHolder.setRequestAttributes(previousRequestAttributes, this.threadContextInheritable);
|
||||||
requestAttributes.requestCompleted();
|
requestAttributes.requestCompleted();
|
||||||
|
}
|
||||||
if (logger.isTraceEnabled()) {
|
if (logger.isTraceEnabled()) {
|
||||||
logger.trace("Cleared thread-bound resource request context: " + request);
|
logger.trace("Cleared thread-bound resource request context: " + request);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -603,8 +603,11 @@ public abstract class FrameworkServlet extends HttpServletBean
|
||||||
|
|
||||||
// Expose current RequestAttributes to current thread.
|
// Expose current RequestAttributes to current thread.
|
||||||
RequestAttributes previousRequestAttributes = RequestContextHolder.getRequestAttributes();
|
RequestAttributes previousRequestAttributes = RequestContextHolder.getRequestAttributes();
|
||||||
ServletRequestAttributes requestAttributes = new ServletRequestAttributes(request);
|
ServletRequestAttributes requestAttributes = null;
|
||||||
|
if (previousRequestAttributes == null || previousRequestAttributes.getClass().equals(ServletRequestAttributes.class)) {
|
||||||
|
requestAttributes = new ServletRequestAttributes(request);
|
||||||
RequestContextHolder.setRequestAttributes(requestAttributes, this.threadContextInheritable);
|
RequestContextHolder.setRequestAttributes(requestAttributes, this.threadContextInheritable);
|
||||||
|
}
|
||||||
|
|
||||||
if (logger.isTraceEnabled()) {
|
if (logger.isTraceEnabled()) {
|
||||||
logger.trace("Bound request context to thread: " + request);
|
logger.trace("Bound request context to thread: " + request);
|
||||||
|
|
@ -627,12 +630,12 @@ public abstract class FrameworkServlet extends HttpServletBean
|
||||||
}
|
}
|
||||||
|
|
||||||
finally {
|
finally {
|
||||||
// Reset thread-bound context.
|
// Clear request attributes and reset thread-bound context.
|
||||||
RequestContextHolder.setRequestAttributes(previousRequestAttributes, this.threadContextInheritable);
|
|
||||||
LocaleContextHolder.setLocaleContext(previousLocaleContext, this.threadContextInheritable);
|
LocaleContextHolder.setLocaleContext(previousLocaleContext, this.threadContextInheritable);
|
||||||
|
if (requestAttributes != null) {
|
||||||
// Clear request attributes.
|
RequestContextHolder.setRequestAttributes(previousRequestAttributes, this.threadContextInheritable);
|
||||||
requestAttributes.requestCompleted();
|
requestAttributes.requestCompleted();
|
||||||
|
}
|
||||||
if (logger.isTraceEnabled()) {
|
if (logger.isTraceEnabled()) {
|
||||||
logger.trace("Cleared thread-bound request context: " + request);
|
logger.trace("Cleared thread-bound request context: " + request);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2008 the original author or authors.
|
* Copyright 2002-2009 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -80,8 +80,8 @@ public class RequestContextListener implements ServletRequestListener {
|
||||||
if (attributes == null) {
|
if (attributes == null) {
|
||||||
attributes = threadAttributes;
|
attributes = threadAttributes;
|
||||||
}
|
}
|
||||||
RequestContextHolder.resetRequestAttributes();
|
|
||||||
LocaleContextHolder.resetLocaleContext();
|
LocaleContextHolder.resetLocaleContext();
|
||||||
|
RequestContextHolder.resetRequestAttributes();
|
||||||
}
|
}
|
||||||
if (attributes != null) {
|
if (attributes != null) {
|
||||||
attributes.requestCompleted();
|
attributes.requestCompleted();
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2008 the original author or authors.
|
* Copyright 2002-2009 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -17,7 +17,6 @@
|
||||||
package org.springframework.web.filter;
|
package org.springframework.web.filter;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import javax.servlet.FilterChain;
|
import javax.servlet.FilterChain;
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
@ -84,8 +83,8 @@ public class RequestContextFilter extends OncePerRequestFilter {
|
||||||
filterChain.doFilter(request, response);
|
filterChain.doFilter(request, response);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
RequestContextHolder.resetRequestAttributes();
|
|
||||||
LocaleContextHolder.resetLocaleContext();
|
LocaleContextHolder.resetLocaleContext();
|
||||||
|
RequestContextHolder.resetRequestAttributes();
|
||||||
attributes.requestCompleted();
|
attributes.requestCompleted();
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug("Cleared thread-bound request context: " + request);
|
logger.debug("Cleared thread-bound request context: " + request);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue