Servlet/Portlet ApplicationContexts use a specific id based on servlet/portlet name; DefaultListableBeanFactory references are serializable now when initialized with an id; scoped proxies are serializable now, for web scopes as well as for singleton beans; injected request/session references are serializable proxies for the current request now
This commit is contained in:
@@ -340,6 +340,7 @@ public abstract class FrameworkPortlet extends GenericPortletBean
|
||||
|
||||
ConfigurablePortletApplicationContext pac =
|
||||
(ConfigurablePortletApplicationContext) BeanUtils.instantiateClass(getContextClass());
|
||||
pac.setId(getPortletContext().getPortletContextName() + "." + getPortletName());
|
||||
pac.setParent(parent);
|
||||
pac.setPortletContext(getPortletContext());
|
||||
pac.setPortletConfig(getPortletConfig());
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.web.portlet.context;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
@@ -120,24 +121,8 @@ public abstract class PortletApplicationContextUtils {
|
||||
pc.setAttribute(PortletContextScope.class.getName(), appScope);
|
||||
}
|
||||
|
||||
beanFactory.registerResolvableDependency(PortletRequest.class, new ObjectFactory<PortletRequest>() {
|
||||
public PortletRequest getObject() {
|
||||
RequestAttributes requestAttr = RequestContextHolder.currentRequestAttributes();
|
||||
if (!(requestAttr instanceof PortletRequestAttributes)) {
|
||||
throw new IllegalStateException("Current request is not a portlet request");
|
||||
}
|
||||
return ((PortletRequestAttributes) requestAttr).getRequest();
|
||||
}
|
||||
});
|
||||
beanFactory.registerResolvableDependency(PortletSession.class, new ObjectFactory<PortletSession>() {
|
||||
public PortletSession getObject() {
|
||||
RequestAttributes requestAttr = RequestContextHolder.currentRequestAttributes();
|
||||
if (!(requestAttr instanceof PortletRequestAttributes)) {
|
||||
throw new IllegalStateException("Current request is not a portlet request");
|
||||
}
|
||||
return ((PortletRequestAttributes) requestAttr).getRequest().getPortletSession();
|
||||
}
|
||||
});
|
||||
beanFactory.registerResolvableDependency(PortletRequest.class, new RequestObjectFactory());
|
||||
beanFactory.registerResolvableDependency(PortletSession.class, new SessionObjectFactory());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -197,4 +182,44 @@ public abstract class PortletApplicationContextUtils {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Factory that exposes the current request object on demand.
|
||||
*/
|
||||
private static class RequestObjectFactory implements ObjectFactory<PortletRequest>, Serializable {
|
||||
|
||||
public PortletRequest getObject() {
|
||||
RequestAttributes requestAttr = RequestContextHolder.currentRequestAttributes();
|
||||
if (!(requestAttr instanceof PortletRequestAttributes)) {
|
||||
throw new IllegalStateException("Current request is not a portlet request");
|
||||
}
|
||||
return ((PortletRequestAttributes) requestAttr).getRequest();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Current PortletRequest";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Factory that exposes the current session object on demand.
|
||||
*/
|
||||
private static class SessionObjectFactory implements ObjectFactory<PortletSession>, Serializable {
|
||||
|
||||
public PortletSession getObject() {
|
||||
RequestAttributes requestAttr = RequestContextHolder.currentRequestAttributes();
|
||||
if (!(requestAttr instanceof PortletRequestAttributes)) {
|
||||
throw new IllegalStateException("Current request is not a portlet request");
|
||||
}
|
||||
return ((PortletRequestAttributes) requestAttr).getRequest().getPortletSession();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Current PortletSession";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user