1 16 19 20 package org.apache.pluto.invoker.impl; 21 22 import java.io.IOException ; 23 24 import javax.portlet.ActionRequest; 25 import javax.portlet.ActionResponse; 26 import javax.portlet.PortletException; 27 import javax.portlet.PortletRequest; 28 import javax.portlet.PortletResponse; 29 import javax.portlet.RenderRequest; 30 import javax.portlet.RenderResponse; 31 import javax.servlet.ServletContext ; 32 import javax.servlet.ServletRequest ; 33 import javax.servlet.ServletResponse ; 34 35 import org.apache.pluto.PortletContainerServices; 36 import org.apache.pluto.core.CoreUtils; 37 import org.apache.pluto.core.InternalPortletRequest; 38 import org.apache.pluto.core.InternalPortletResponse; 39 import org.apache.pluto.invoker.PortletInvoker; 40 import org.apache.pluto.om.portlet.PortletDefinition; 41 import org.apache.pluto.om.servlet.ServletDefinition; 42 import org.apache.pluto.services.log.LogService; 43 import org.apache.pluto.services.log.Logger; 44 45 public class PortletInvokerImpl implements PortletInvoker 46 { 47 private javax.servlet.ServletConfig servletConfig; 48 private PortletDefinition portletDefinition; 49 50 56 private Logger log = null; 57 58 public PortletInvokerImpl(PortletDefinition portletDefinition, 59 javax.servlet.ServletConfig servletConfig) 60 { 61 this.portletDefinition = portletDefinition; 62 this.servletConfig = servletConfig; 63 } 64 65 public void action(ActionRequest request, ActionResponse response) throws PortletException,IOException 67 { 68 invoke(request,response,org.apache.pluto.Constants.METHOD_ACTION); 69 } 70 71 public void render(RenderRequest request, RenderResponse response) throws PortletException, IOException 72 { 73 invoke(request,response,org.apache.pluto.Constants.METHOD_RENDER); 74 } 75 76 public void load(PortletRequest request, RenderResponse response) throws PortletException 77 { 78 try 79 { 80 invoke(request,response,org.apache.pluto.Constants.METHOD_NOOP); 81 } 82 catch (IOException e) 83 { 84 getLog().error("PortletInvokerImpl.load() - Error while dispatching portlet.",e); 85 throw new PortletException(e); 86 } 87 } 88 90 94 protected void invoke(PortletRequest portletRequest, PortletResponse portletResponse, Integer methodID) 95 throws PortletException,IOException 96 { 97 InternalPortletRequest internalPortletRequest = CoreUtils.getInternalRequest(portletRequest); 98 99 InternalPortletResponse internalPortletResponse = CoreUtils.getInternalResponse(portletResponse); 100 101 ServletRequest servletRequest = ((javax.servlet.http.HttpServletRequestWrapper )internalPortletRequest).getRequest(); 103 104 ServletResponse servletResponse = ((javax.servlet.http.HttpServletResponseWrapper )internalPortletResponse).getResponse(); 105 106 ServletDefinition servletDefinition = portletDefinition.getServletDefinition(); 107 ServletContext servletContext = servletConfig.getServletContext(); 108 109 javax.servlet.RequestDispatcher dispatcher = servletDefinition.getRequestDispatcher(servletContext); 110 111 if (dispatcher != null) 112 { 113 try 114 { 115 servletRequest.setAttribute(org.apache.pluto.Constants.METHOD_ID, methodID); 116 117 servletRequest.setAttribute(org.apache.pluto.Constants.PORTLET_REQUEST, portletRequest); 118 servletRequest.setAttribute(org.apache.pluto.Constants.PORTLET_RESPONSE, portletResponse); 119 120 dispatcher.include(servletRequest, servletResponse); 121 } 122 catch (javax.servlet.UnavailableException e) 123 { 124 getLog().error("PortletInvokerImpl.invoke() - Error while dispatching portlet.",e); 125 if (e.isPermanent()) 126 { 127 throw new javax.portlet.UnavailableException(e.getMessage()); 128 } 129 else 130 { 131 throw new javax.portlet.UnavailableException(e.getMessage(), e.getUnavailableSeconds()); 132 } 133 } 134 catch (javax.servlet.ServletException e) 135 { 136 if (e.getRootCause() != null) 137 { 138 getLog().error("PortletInvokerImpl.render() - Error while dispatching portlet.", 139 e.getRootCause()); 140 if (e.getRootCause() instanceof PortletException) 141 { 142 throw (PortletException)e.getRootCause(); 143 } 144 else 145 { 146 throw new PortletException(e.getRootCause()); 147 } 148 } 149 else 150 { 151 getLog().error("PortletInvokerImpl.invoke() - Error while dispatching portlet.", 152 e); 153 throw new PortletException(e); 154 } 155 } 156 finally 157 { 158 servletRequest.removeAttribute(org.apache.pluto.Constants.METHOD_ID); 159 servletRequest.removeAttribute(org.apache.pluto.Constants.PORTLET_REQUEST); 160 servletRequest.removeAttribute(org.apache.pluto.Constants.PORTLET_RESPONSE); 161 } 162 } 163 else 164 { 165 getLog().error("PortletInvokerImpl.action() - Unable to find RequestDispatcher."); 166 throw new PortletException("Unable to find dispatcher for context: "+servletContext.getServletContextName()); 167 } 168 } 169 171 177 private Logger getLog() { 178 if(log==null) { 179 log = ((LogService)PortletContainerServices 181 .get(LogService.class)) 182 .getLogger(getClass()); 183 } 184 return log; 185 } 186 } 187 | Popular Tags |