Skip to content

Instantly share code, notes, and snippets.

@hvvikram
Created February 1, 2014 01:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hvvikram/8746498 to your computer and use it in GitHub Desktop.
Save hvvikram/8746498 to your computer and use it in GitHub Desktop.
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