Created
February 1, 2014 01:07
-
-
Save hvvikram/8746498 to your computer and use it in GitHub Desktop.
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
package foo; | |
import javax.servlet.ServletRequestEvent; | |
import org.springframework.context.i18n.LocaleContextHolder; | |
import org.springframework.web.context.request.AbstractRequestAttributes; | |
import org.springframework.web.context.request.RequestContextHolder; | |
import org.springframework.web.context.request.ServletRequestAttributes; | |
/** | |
* Fixing an issue with Spring's | |
* {@link org.springframework.web.context.request.RequestContextListener}, which was optimistically | |
* casting the request attribute object to {@link ServletRequestAttributes}. | |
* | |
* Instead this class casts the request attribute object to {@link AbstractRequestAttributes}. | |
* | |
* @author Vikram Hullukunte | |
* | |
*/ | |
public class RequestContextListener extends | |
org.springframework.web.context.request.RequestContextListener { | |
public void requestDestroyed( ServletRequestEvent requestEvent ) { | |
AbstractRequestAttributes attributes = (AbstractRequestAttributes) requestEvent | |
.getServletRequest().getAttribute( | |
org.springframework.web.context.request.RequestContextListener.class | |
.getName() + ".REQUEST_ATTRIBUTES"); | |
AbstractRequestAttributes threadAttributes = (AbstractRequestAttributes) RequestContextHolder | |
.getRequestAttributes(); | |
if (threadAttributes != null) { | |
// We're assumably within the original request thread... | |
if (attributes == null) { | |
attributes = threadAttributes; | |
} | |
LocaleContextHolder.resetLocaleContext(); | |
RequestContextHolder.resetRequestAttributes(); | |
} | |
if (attributes != null) { | |
attributes.requestCompleted(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment