📄 portletservlet.java
字号:
}
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
{
dispatch(request, response);
}
protected void doPut(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
{
dispatch(request, response);
}
// Private Methods ---------------------------------------------------------
/**
* Dispatch the request to the appropriate portlet methods. This method
* assumes that the following attributes are set in the servlet request
* scope:
* <ul>
* <li>METHOD_ID: indicating which method to dispatch.</li>
* <li>PORTLET_REQUEST: the internal portlet request.</li>
* <li>PORTLET_RESPONSE: the internal portlet response.</li>
* </ul>
*
* @param request
* the servlet request.
* @param response
* the servlet response.
* @throws ServletException
* @throws IOException
*/
private void dispatch(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
{
if (portlet == null)
{
throw new javax.servlet.UnavailableException("Portlet "+portletName+" unavailable");
}
InternalPortletRequest portletRequest = null;
InternalPortletResponse portletResponse = null;
// Save portlet config into servlet request.
request.setAttribute(Constants.PORTLET_CONFIG, portletConfig);
// Retrieve attributes from the servlet request.
Integer methodId = (Integer) request.getAttribute(Constants.METHOD_ID);
portletRequest = (InternalPortletRequest) request
.getAttribute(Constants.PORTLET_REQUEST);
portletResponse = (InternalPortletResponse) request
.getAttribute(Constants.PORTLET_RESPONSE);
FilterManager filterManager = (FilterManager) request
.getAttribute(Constants.FILTER_MANAGER);
portletRequest.init(portletContext, request);
PortletWindow window = containerInvocationService.getInvocation()
.getPortletWindow();
PortletInvocationEvent event = new PortletInvocationEvent(
portletRequest, window, methodId.intValue());
notify(event, true, null);
// Init the classloader for the filter and get the Service for
// processing the filters.
ClassLoader loader = Thread.currentThread().getContextClassLoader();
// FilterManager filtermanager = (FilterManager) request.getAttribute(
// "filter-manager");
try
{
// The requested method is RENDER: call Portlet.render(..)
if (methodId == Constants.METHOD_RENDER)
{
RenderRequest renderRequest = (RenderRequest) portletRequest;
RenderResponse renderResponse = (RenderResponse) portletResponse;
filterManager.processFilter(renderRequest, renderResponse,
loader, portlet, portletContext);
}
// The requested method is RESOURCE: call
// ResourceServingPortlet.serveResource(..)
else if (methodId == Constants.METHOD_RESOURCE)
{
ResourceRequest resourceRequest = (ResourceRequest) portletRequest;
ResourceResponse resourceResponse = (ResourceResponse) portletResponse;
filterManager.processFilter(resourceRequest, resourceResponse,
loader, resourceServingPortlet, portletContext);
}
// The requested method is ACTION: call Portlet.processAction(..)
else if (methodId == Constants.METHOD_ACTION)
{
ActionRequest actionRequest = (ActionRequest) portletRequest;
ActionResponse actionResponse = (ActionResponse) portletResponse;
filterManager.processFilter(actionRequest, actionResponse,
loader, portlet, portletContext);
}
// The request methode is Event: call Portlet.processEvent(..)
else if (methodId == Constants.METHOD_EVENT)
{
EventRequest eventRequest = (EventRequest) portletRequest;
EventResponse eventResponse = (EventResponse) portletResponse;
filterManager.processFilter(eventRequest, eventResponse,
loader, eventPortlet, portletContext);
}
// The requested method is ADMIN: call handlers.
else if (methodId == Constants.METHOD_ADMIN)
{
ContainerInvocation inv = containerInvocationService
.getInvocation();
PortalAdministrationService pas = inv.getPortletContainer()
.getOptionalContainerServices()
.getPortalAdministrationService();
Iterator it = pas.getAdministrativeRequestListeners()
.iterator();
while (it.hasNext())
{
AdministrativeRequestListener l = (AdministrativeRequestListener) it
.next();
l.administer(portletRequest, portletResponse);
}
}
// The requested method is NOOP: do nothing.
else if (methodId == Constants.METHOD_NOOP)
{
// Do nothing.
}
notify(event, false, null);
}
catch (javax.portlet.UnavailableException ex)
{
System.err.println(ex.getMessage());
/*
* if (e.isPermanent()) { throw new
* UnavailableException(e.getMessage()); } else { throw new
* UnavailableException(e.getMessage(), e.getUnavailableSeconds());
* }
*/
// Portlet.destroy() isn't called by Tomcat, so we have to fix it.
try
{
portlet.destroy();
}
catch (Throwable th)
{
System.err.println(ex.getMessage());
// Don't care for Exception
}
// take portlet out of service
portlet = null;
// TODO: Handle everything as permanently for now.
throw new javax.servlet.UnavailableException(ex.getMessage());
}
catch (PortletException ex)
{
notify(event, false, ex);
System.err.println(ex.getMessage());
throw new ServletException(ex);
}
finally
{
request.removeAttribute(Constants.PORTLET_CONFIG);
if (portletRequest != null)
{
portletRequest.release();
}
}
}
protected void notify(PortletInvocationEvent event, boolean pre, Throwable e)
{
ContainerInvocation inv = containerInvocationService.getInvocation();
PortalAdministrationService pas = inv.getPortletContainer()
.getOptionalContainerServices()
.getPortalAdministrationService();
Iterator i = pas.getPortletInvocationListeners().iterator();
while (i.hasNext())
{
PortletInvocationListener listener = (PortletInvocationListener) i
.next();
if (pre)
{
listener.onBegin(event);
}
else if (e == null)
{
listener.onEnd(event);
}
else
{
listener.onError(event, e);
}
}
}
private void initializeEventPortlet()
{
if (portlet instanceof EventPortlet)
{
eventPortlet = (EventPortlet) portlet;
}
else
{
eventPortlet = new NullPortlet();
}
}
private void initializeResourceServingPortlet()
{
if (portlet instanceof ResourceServingPortlet)
{
resourceServingPortlet = (ResourceServingPortlet) portlet;
}
else
{
resourceServingPortlet = new NullPortlet();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -