|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectGenericPortlet
org.springframework.web.portlet.GenericPortletBean
org.springframework.web.portlet.FrameworkPortlet
public abstract class FrameworkPortlet
Base portlet for Spring's portlet framework. Provides integration with a Spring application context, in a JavaBean-based overall solution.
This class offers the following functionality:
ApplicationContext
instance per portlet. The portlet's configuration is determined by beans
in the portlet's namespace.
Subclasses must implement doActionService(ActionRequest, ActionResponse)
and doRenderService(RenderRequest, RenderResponse)
to handle action and render requests. Because this extends GenericPortletBean
rather than Portlet directly, bean properties are mapped onto it. Subclasses can
override initFrameworkPortlet()
for custom initialization.
Regards a "contextClass" parameter at the portlet init-param level,
falling back to the default context class
(XmlPortletApplicationContext
)
if not found. Note that, with the default FrameworkPortlet,
a context class needs to implement the
ConfigurablePortletApplicationContext
SPI.
Passes a "contextConfigLocation" portlet init-param to the context instance, parsing it into potentially multiple file paths which can be separated by any number of commas and spaces, like "test-portlet.xml, myPortlet.xml". If not explicitly specified, the context implementation is supposed to build a default location from the namespace of the portlet.
Note: In case of multiple config locations, later bean definitions will override ones defined in earlier loaded files, at least when using one of Spring's default ApplicationContext implementations. This can be leveraged to deliberately override certain bean definitions via an extra XML file.
The default namespace is "'portlet-name'-portlet", e.g. "test-portlet" for a portlet-name "test" (leading to a "/WEB-INF/test-portlet.xml" default location with XmlPortletApplicationContext). The namespace can also be set explicitly via the "namespace" portlet init-param.
doActionService(ActionRequest, ActionResponse)
,
doRenderService(RenderRequest, RenderResponse)
,
setContextClass(java.lang.Class)
,
setContextConfigLocation(java.lang.String)
,
setNamespace(java.lang.String)
Field Summary | |
---|---|
private java.lang.Class |
contextClass
Portlet ApplicationContext implementation class to use |
private java.lang.String |
contextConfigLocation
Explicit context config location |
static java.lang.Class |
DEFAULT_CONTEXT_CLASS
Default context class for FrameworkPortlet. |
static java.lang.String |
DEFAULT_NAMESPACE_SUFFIX
Suffix for Portlet ApplicationContext namespaces. |
static java.lang.String[] |
DEFAULT_USERINFO_ATTRIBUTE_NAMES
Default USER_INFO attribute names to search for the current username: "user.login.id", "user.name". |
private java.lang.String |
namespace
Namespace for this portlet |
static java.lang.String |
PORTLET_CONTEXT_PREFIX
Prefix for the PortletContext attribute for the Portlet ApplicationContext. |
private ApplicationContext |
portletApplicationContext
ApplicationContext for this portlet |
private boolean |
publishContext
Should we publish the context as a PortletContext attribute? |
private boolean |
publishEvents
Should we publish a PortletRequestHandledEvent at the end of each request? |
private boolean |
refreshEventReceived
Flag used to detect whether onRefresh has already been called |
private boolean |
threadContextInheritable
Expose LocaleContext and RequestAttributes as inheritable for child threads? |
private java.lang.String[] |
userinfoUsernameAttributes
USER_INFO attributes that may contain the username of the current user |
Fields inherited from class org.springframework.web.portlet.GenericPortletBean |
---|
logger |
Constructor Summary | |
---|---|
FrameworkPortlet()
|
Method Summary | |
---|---|
protected LocaleContext |
buildLocaleContext(PortletRequest request)
Build a LocaleContext for the given request, exposing the request's primary locale as current locale. |
protected ApplicationContext |
createPortletApplicationContext(ApplicationContext parent)
Instantiate the Portlet ApplicationContext for this portlet, either a default XmlPortletApplicationContext or a custom context class if set. |
void |
destroy()
Close the ApplicationContext of this portlet. |
protected abstract void |
doActionService(ActionRequest request,
ActionResponse response)
Subclasses must implement this method to do the work of action request handling. |
protected void |
doDispatch(RenderRequest request,
RenderResponse response)
Delegate render requests to processRequest/doRenderService. |
protected abstract void |
doEventService(EventRequest request,
EventResponse response)
Subclasses must implement this method to do the work of event request handling. |
protected abstract void |
doRenderService(RenderRequest request,
RenderResponse response)
Subclasses must implement this method to do the work of render request handling. |
protected abstract void |
doResourceService(ResourceRequest request,
ResourceResponse response)
Subclasses must implement this method to do the work of resource request handling. |
java.lang.Class |
getContextClass()
Return the custom context class. |
java.lang.String |
getContextConfigLocation()
Return the explicit context config location, if any. |
java.lang.String |
getNamespace()
Return the namespace for this portlet, falling back to default scheme if no custom namespace was set. |
ApplicationContext |
getPortletApplicationContext()
Return this portlet's ApplicationContext. |
java.lang.String |
getPortletContextAttributeName()
Return the PortletContext attribute name for this portlets's ApplicationContext. |
protected java.lang.String |
getTitle(RenderRequest renderRequest)
Overridden for friendlier behavior in unit tests. |
protected java.lang.String |
getUsernameForRequest(PortletRequest request)
Determine the username for the given request. |
protected void |
initFrameworkPortlet()
This method will be invoked after any bean properties have been set and the ApplicationContext has been loaded. |
protected ApplicationContext |
initPortletApplicationContext()
Initialize and publish the Portlet ApplicationContext for this portlet. |
protected void |
initPortletBean()
Overridden method of GenericPortletBean, invoked after any bean properties have been set. |
void |
onApplicationEvent(ContextRefreshedEvent event)
ApplicationListener endpoint that receives events from this servlet's WebApplicationContext. |
protected void |
onRefresh(ApplicationContext context)
Template method which can be overridden to add portlet-specific refresh work. |
protected void |
postProcessPortletApplicationContext(ConfigurableApplicationContext pac)
Post-process the given Portlet ApplicationContext before it is refreshed and activated as context for this portlet. |
void |
processAction(ActionRequest request,
ActionResponse response)
Delegate action requests to processRequest/doActionService. |
void |
processEvent(EventRequest request,
EventResponse response)
|
protected void |
processRequest(PortletRequest request,
PortletResponse response)
Process this request, publishing an event regardless of the outcome. |
void |
refresh()
Refresh this portlet's application context, as well as the dependent state of the portlet. |
void |
serveResource(ResourceRequest request,
ResourceResponse response)
|
void |
setContextClass(java.lang.Class contextClass)
Set a custom context class. |
void |
setContextConfigLocation(java.lang.String contextConfigLocation)
Set the context config location explicitly, instead of relying on the default location built from the namespace. |
void |
setNamespace(java.lang.String namespace)
Set a custom namespace for this portlet, to be used for building a default context config location. |
void |
setPublishContext(boolean publishContext)
Set whether to publish this portlet's context as a PortletContext attribute, available to all objects in the web container. |
void |
setPublishEvents(boolean publishEvents)
Set whether this portlet should publish a PortletRequestHandledEvent at the end of each request. |
void |
setThreadContextInheritable(boolean threadContextInheritable)
Set whether to expose the LocaleContext and RequestAttributes as inheritable for child threads (using an InheritableThreadLocal ). |
void |
setUserinfoUsernameAttributes(java.lang.String[] userinfoUsernameAttributes)
Set the list of attributes to search in the USER_INFO map when trying to find the username of the current user. |
Methods inherited from class org.springframework.web.portlet.GenericPortletBean |
---|
addRequiredProperty, getPortletContext, getPortletName, init, initBeanWrapper |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface org.springframework.context.ApplicationListener |
---|
onApplicationEvent |
Field Detail |
---|
public static final java.lang.Class DEFAULT_CONTEXT_CLASS
XmlPortletApplicationContext
public static final java.lang.String DEFAULT_NAMESPACE_SUFFIX
public static final java.lang.String PORTLET_CONTEXT_PREFIX
public static final java.lang.String[] DEFAULT_USERINFO_ATTRIBUTE_NAMES
private java.lang.Class contextClass
private java.lang.String namespace
private java.lang.String contextConfigLocation
private boolean publishContext
private boolean publishEvents
private boolean threadContextInheritable
private java.lang.String[] userinfoUsernameAttributes
private ApplicationContext portletApplicationContext
private boolean refreshEventReceived
Constructor Detail |
---|
public FrameworkPortlet()
Method Detail |
---|
public void setContextClass(java.lang.Class contextClass)
createPortletApplicationContext(org.springframework.context.ApplicationContext)
public java.lang.Class getContextClass()
public void setNamespace(java.lang.String namespace)
public java.lang.String getNamespace()
public void setContextConfigLocation(java.lang.String contextConfigLocation)
public java.lang.String getContextConfigLocation()
public void setPublishContext(boolean publishContext)
This is especially handy during testing, although it is debatable whether it's good practice to let other application objects access the context this way.
public void setPublishEvents(boolean publishEvents)
PortletRequestHandledEvent
public void setThreadContextInheritable(boolean threadContextInheritable)
InheritableThreadLocal
).
Default is "false", to avoid side effects on spawned background threads. Switch this to "true" to enable inheritance for custom child threads which are spawned during request processing and only used for this request (that is, ending after their initial task, without reuse of the thread).
WARNING: Do not use inheritance for child threads if you are
accessing a thread pool which is configured to potentially add new threads
on demand (e.g. a JDK ThreadPoolExecutor
),
since this will expose the inherited context to such a pooled thread.
public void setUserinfoUsernameAttributes(java.lang.String[] userinfoUsernameAttributes)
getUsernameForRequest(PortletRequest)
protected final void initPortletBean() throws PortletException
initPortletBean
in class GenericPortletBean
PortletException
- if subclass initialization failsprotected ApplicationContext initPortletApplicationContext()
Delegates to createPortletApplicationContext(org.springframework.context.ApplicationContext)
for actual creation.
Can be overridden in subclasses.
protected ApplicationContext createPortletApplicationContext(ApplicationContext parent)
This implementation expects custom contexts to implement ConfigurablePortletApplicationContext. Can be overridden in subclasses.
parent
- the parent ApplicationContext to use, or null if none
setContextClass(java.lang.Class)
,
XmlPortletApplicationContext
protected void postProcessPortletApplicationContext(ConfigurableApplicationContext pac)
The default implementation is empty. refresh()
will
be called automatically after this method returns.
pac
- the configured Portlet ApplicationContext (not refreshed yet)createPortletApplicationContext(org.springframework.context.ApplicationContext)
,
ConfigurableApplicationContext.refresh()
public java.lang.String getPortletContextAttributeName()
The default implementation returns PORTLET_CONTEXT_PREFIX + portlet name.
PORTLET_CONTEXT_PREFIX
,
GenericPortletBean.getPortletName()
public final ApplicationContext getPortletApplicationContext()
protected void initFrameworkPortlet() throws PortletException
The default implementation is empty; subclasses may override this method to perform any initialization they require.
PortletException
- in case of an initialization exceptionpublic void refresh()
getPortletApplicationContext()
,
ConfigurableApplicationContext.refresh()
public void onApplicationEvent(ContextRefreshedEvent event)
The default implementation calls onRefresh(org.springframework.context.ApplicationContext)
in case of a
ContextRefreshedEvent
,
triggering a refresh of this servlet's context-dependent state.
event
- the incoming ApplicationContext eventprotected void onRefresh(ApplicationContext context)
This implementation is empty.
context
- the current Portlet ApplicationContextrefresh()
protected java.lang.String getTitle(RenderRequest renderRequest)
public final void processAction(ActionRequest request, ActionResponse response) throws PortletException, java.io.IOException
PortletException
java.io.IOException
protected final void doDispatch(RenderRequest request, RenderResponse response) throws PortletException, java.io.IOException
PortletException
java.io.IOException
public void serveResource(ResourceRequest request, ResourceResponse response) throws PortletException, java.io.IOException
PortletException
java.io.IOException
public void processEvent(EventRequest request, EventResponse response) throws PortletException, java.io.IOException
PortletException
java.io.IOException
protected final void processRequest(PortletRequest request, PortletResponse response) throws PortletException, java.io.IOException
doActionService()
and doRenderService()
template methods.
PortletException
java.io.IOException
doActionService(ActionRequest, ActionResponse)
,
doRenderService(RenderRequest, RenderResponse)
protected LocaleContext buildLocaleContext(PortletRequest request)
request
- current HTTP request
protected java.lang.String getUsernameForRequest(PortletRequest request)
The default implementation first tries the UserPrincipal. If that does not exist, then it checks the USER_INFO map. Can be overridden in subclasses.
request
- current portlet request
null
if none foundjavax.portlet.PortletRequest#getUserPrincipal()
,
javax.portlet.PortletRequest#getRemoteUser()
,
javax.portlet.PortletRequest#USER_INFO
,
setUserinfoUsernameAttributes(java.lang.String[])
protected abstract void doActionService(ActionRequest request, ActionResponse response) throws java.lang.Exception
The contract is essentially the same as that for the processAction
method of GenericPortlet.
This class intercepts calls to ensure that exception handling and event publication takes place.
request
- current action requestresponse
- current action response
java.lang.Exception
- in case of any kind of processing failurejavax.portlet.GenericPortlet#processAction
protected abstract void doRenderService(RenderRequest request, RenderResponse response) throws java.lang.Exception
The contract is essentially the same as that for the doDispatch
method of GenericPortlet.
This class intercepts calls to ensure that exception handling and event publication takes place.
request
- current render requestresponse
- current render response
java.lang.Exception
- in case of any kind of processing failurejavax.portlet.GenericPortlet#doDispatch
protected abstract void doResourceService(ResourceRequest request, ResourceResponse response) throws java.lang.Exception
The contract is essentially the same as that for the serveResource
method of GenericPortlet.
This class intercepts calls to ensure that exception handling and event publication takes place.
request
- current resource requestresponse
- current resource response
java.lang.Exception
- in case of any kind of processing failurejavax.portlet.GenericPortlet#serveResource
protected abstract void doEventService(EventRequest request, EventResponse response) throws java.lang.Exception
The contract is essentially the same as that for the processEvent
method of GenericPortlet.
This class intercepts calls to ensure that exception handling and event publication takes place.
request
- current event requestresponse
- current event response
java.lang.Exception
- in case of any kind of processing failurejavax.portlet.GenericPortlet#processEvent
public void destroy()
ConfigurableApplicationContext.close()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |