1 9 package org.jboss.portal.portlet.impl; 10 11 import java.io.IOException ; 12 13 import javax.portlet.PortletConfig; 14 import javax.portlet.PortletException; 15 import javax.portlet.PortletRequestDispatcher; 16 import javax.portlet.RenderRequest; 17 import javax.portlet.RenderResponse; 18 import javax.servlet.RequestDispatcher ; 19 import javax.servlet.ServletException ; 20 import javax.servlet.FilterChain ; 21 import javax.servlet.http.HttpServletRequest ; 22 import javax.servlet.http.HttpServletResponse ; 23 import javax.servlet.http.HttpServletRequestWrapper ; 24 25 import org.jboss.portal.portlet.invocation.PortletKey; 26 import org.jboss.portal.server.PortalRequest; 27 import org.jboss.portal.server.PortalResponse; 28 import org.jboss.portal.server.invocation.AttachmentKey; 29 import org.jboss.portal.server.invocation.Invocation; 30 import org.jboss.portal.server.invocation.component.ContextDispatcherInterceptor; 31 import org.jboss.portal.server.servlet.CommandServlet; 32 import org.jboss.portal.server.servlet.FilterCommand; 33 import org.jboss.portal.server.servlet.ServletCommand; 34 35 39 public class PortletRequestDispatcherImpl 40 implements PortletRequestDispatcher, 41 FilterCommand 42 { 43 44 45 private RequestDispatcher dispatcher; 46 47 48 private String path; 49 50 public PortletRequestDispatcherImpl(RequestDispatcher dispatcher) 51 { 52 this(dispatcher, null); 53 } 54 55 public PortletRequestDispatcherImpl(RequestDispatcher dispatcher, String path) 56 { 57 this.dispatcher = dispatcher; 58 this.path = path; 59 } 60 61 public Object execute(HttpServletRequest req, HttpServletResponse resp, FilterChain chain) throws ServletException , IOException 62 { 63 HttpServletRequest wrappedReq = new HttpServletRequestWrapper (req) 64 { 65 public StringBuffer getRequestURL() 66 { 67 return null; 69 } 70 }; 71 chain.doFilter(wrappedReq, resp); 72 return null; 73 } 74 75 public void include(RenderRequest req, RenderResponse resp) throws PortletException, IOException 76 { 77 try 78 { 79 ContextDispatcherInterceptor.InvokeNextCommand cmd = (ContextDispatcherInterceptor.InvokeNextCommand)req.getAttribute(ServletCommand.REQ_ATT_KEY); 81 Invocation invocation = cmd.getInvocation(); 82 83 PortalRequest preq = (PortalRequest)invocation.getAttachment(AttachmentKey.PORTAL_REQUEST); 85 PortalResponse presp = (PortalResponse)invocation.getAttachment(AttachmentKey.PORTAL_RESPONSE); 86 87 HttpServletRequest hreq = (HttpServletRequest )invocation.getAttachment(AttachmentKey.DISPATCHED_REQUEST); 89 HttpServletResponse hresp = (HttpServletResponse )invocation.getAttachment(AttachmentKey.DISPATCHED_RESPONSE); 90 91 DispatchedHttpServletRequest dreq = new DispatchedHttpServletRequest(preq, req, hreq, path); 93 DispatchedHttpServletResponse dresp = new DispatchedHttpServletResponse(presp, resp, hresp); 94 95 PortletConfig cfg = (PortletConfig)invocation.getAttachment(PortletKey.PORTLET_CONFIG); 97 98 try 99 { 100 102 108 109 dreq.setAttribute(FilterCommand.REQ_ATT_KEY, this); 111 112 dispatcher.include(dreq, dresp); 114 } 115 finally 116 { 117 dreq.removeAttribute(FilterCommand.REQ_ATT_KEY); 119 120 126 } 127 } 128 catch (ServletException e) 129 { 130 throw new PortletException(e); 132 } 133 } 134 } 135 | Popular Tags |