Skip to content

Commit

Permalink
UP-4678: Prevent a ClassCastException on WebAsyncManager in cross-con…
Browse files Browse the repository at this point in the history
…text (portlet) dispatched request (this is a workaround)
  • Loading branch information
drewwills committed May 10, 2016
1 parent e8611f5 commit 8fafdbf
Showing 1 changed file with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.context.request.async.WebAsyncUtils;

/**
* Scopes set request attributes to just this request.
*
* @author Eric Dalquist
* @version $Revision$
*/
public class PortletHttpServletRequestWrapper extends AbstractHttpServletRequestWrapper {
/**
* {@link javax.servlet.http.HttpServletRequest} attribute that this {@link HttpServletRequest} object
* will be available.
*/
public static final String ATTRIBUTE__HTTP_SERVLET_REQUEST = PortletHttpServletRequestWrapper.class.getName() + ".PORTLET_HTTP_SERVLET_REQUEST";

private final Map<String, Object> attributes = new LinkedHashMap<String, Object>();

public PortletHttpServletRequestWrapper(HttpServletRequest httpServletRequest) {
super(httpServletRequest);
}
Expand All @@ -51,12 +51,23 @@ public Object getAttribute(String name) {
if (ATTRIBUTE__HTTP_SERVLET_REQUEST.equals(name)) {
return this;
}

final Object attribute = this.attributes.get(name);
if (attribute != null) {
return attribute;
}

if (WebAsyncUtils.WEB_ASYNC_MANAGER_ATTRIBUTE.equals(name)) {
/*
* Spring WebAsyncManager has an issue with cross-context request
* dispatching; it has the potential to break the portlet
* container. See the following page:
*
* - http://stackoverflow.com/questions/22128150/spring-and-cross-context-webasyncmanager-cannot-be-cast-to-webasyncmanager
*/
return null;
}

return super.getAttribute(name);
}

Expand All @@ -75,4 +86,5 @@ public void removeAttribute(String name) {
public void setAttribute(String name, Object o) {
this.attributes.put(name, o);
}

}

0 comments on commit 8fafdbf

Please sign in to comment.