if (portletDefinition == null)
{
portletDefinition = this.portletDefinition;
}
MutablePortletApplication app = (MutablePortletApplication)portletDefinition.getPortletApplicationDefinition();
WebApplicationDefinition webApplicationDefinition = app.getWebApplicationDefinition();
if(webApplicationDefinition == null)
{
throw new IllegalStateException("Portlet application "+app.getName()+ " has no associated web application.");
}
String portletApplicationName = webApplicationDefinition.getContextRoot();
// gather all required data from request and response
ServletRequest servletRequest = ((HttpServletRequestWrapper)((HttpServletRequestWrapper)((HttpServletRequestWrapper)portletRequest).getRequest()).getRequest()).getRequest();
ServletResponse servletResponse = ((HttpServletResponseWrapper) portletResponse).getResponse();
ServletContext appContext = jetspeedContext.getContext(portletApplicationName);
if (null == appContext)
{
String message = "Failed to find Servlet context for Portlet Application: " + portletApplicationName;
log.error(message);
throw new PortletException(message);
}
PortletInstance portletInstance = portletFactory.getPortletInstance(appContext, portletDefinition);
RequestDispatcher dispatcher = appContext.getRequestDispatcher(servletMappingName);
if (null == dispatcher)
{
String message =
"Failed to get Request Dispatcher for Portlet Application: "
+ portletApplicationName
+ ", servlet: "
+ servletMappingName;
log.error(message);
throw new PortletException(message);
}
try
{
servletRequest.setAttribute(ContainerConstants.PORTLET, portletInstance);
servletRequest.setAttribute(ContainerConstants.PORTLET_CONFIG, portletInstance.getConfig());
servletRequest.setAttribute(ContainerConstants.PORTLET_REQUEST, portletRequest);
servletRequest.setAttribute(ContainerConstants.PORTLET_RESPONSE, portletResponse);
servletRequest.setAttribute(ContainerConstants.METHOD_ID, methodID);
servletRequest.setAttribute(ContainerConstants.PORTLET_NAME, app.getName()+"::"+portletDefinition.getName());
RequestContext requestContext = (RequestContext)servletRequest.getAttribute(PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE);
servletRequest.setAttribute(ContainerConstants.PORTAL_CONTEXT, requestContext.getRequest().getContextPath());
// Store same request attributes into the worker in parallel mode.
if (isParallelMode)
{
CurrentWorkerContext.setAttribute(ContainerConstants.PORTLET, portletInstance);
CurrentWorkerContext.setAttribute(ContainerConstants.PORTLET_CONFIG, portletInstance.getConfig());
CurrentWorkerContext.setAttribute(ContainerConstants.PORTLET_REQUEST, portletRequest);
CurrentWorkerContext.setAttribute(ContainerConstants.PORTLET_RESPONSE, portletResponse);
CurrentWorkerContext.setAttribute(ContainerConstants.METHOD_ID, methodID);
CurrentWorkerContext.setAttribute(ContainerConstants.PORTLET_NAME, app.getName()+"::"+portletDefinition.getName());
CurrentWorkerContext.setAttribute(ContainerConstants.PORTAL_CONTEXT, requestContext.getRequest().getContextPath());
}
PortletRequestContext.createContext(portletDefinition, portletInstance, portletRequest, portletResponse);
dispatcher.include(servletRequest, servletResponse);