KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > bridge > BridgeInterceptor


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  *****************************************/

9 package org.jboss.portal.bridge;
10
11 import org.jboss.portal.server.invocation.Interceptor;
12 import org.jboss.portal.server.invocation.Invocation;
13 import org.jboss.portal.server.invocation.AttachmentKey;
14 import org.jboss.portal.server.Window;
15 import org.jboss.portal.server.Instance;
16 import org.jboss.portal.server.Component;
17 import org.jboss.portal.server.Application;
18 import org.jboss.portal.server.PortalRequest;
19 import org.jboss.portal.server.PortalResponse;
20 import org.jboss.portal.portlet.impl.DispatchedHttpServletRequest;
21
22 import javax.servlet.http.HttpServletResponse JavaDoc;
23 import javax.servlet.http.HttpServletRequest JavaDoc;
24 import javax.servlet.ServletContext JavaDoc;
25 import java.net.MalformedURLException JavaDoc;
26 import java.net.URL JavaDoc;
27
28 /**
29  * The bridge interceptor set the bridge for the duration of the request made to the portlet.
30  *
31  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
32  * @version $Revision: 1.1.1.1 $
33  */

34 public class BridgeInterceptor implements Interceptor
35 {
36    public Object JavaDoc invoke(Invocation invocation)
37    {
38
39       // Get servlet context associated with the dispatched application
40
Window window = (Window)invocation.getAttachment(AttachmentKey.WINDOW);
41       Instance instance = window.getInstance();
42       Component component = instance.getComponent();
43       Application application = component.getApplication();
44       ServletContext JavaDoc ctx = application.getServletContext();
45
46       // Get request infos
47
PortalRequest preq = (PortalRequest)invocation.getAttachment(AttachmentKey.PORTAL_REQUEST);
48       PortalResponse presp = (PortalResponse)invocation.getAttachment(AttachmentKey.PORTAL_RESPONSE);
49       HttpServletRequest req = (HttpServletRequest)invocation.getAttachment(AttachmentKey.DISPATCHED_REQUEST);
50       HttpServletResponse JavaDoc resp = (HttpServletResponse JavaDoc)invocation.getAttachment(AttachmentKey.DISPATCHED_RESPONSE);
51
52       try
53       {
54          // Set bridge
55
JBossServletContextProvider.BridgeInfo bridgeInfo = new JBossServletContextProvider.BridgeInfo(ctx, preq, presp, req, resp);
56          JBossServletContextProvider.set(bridgeInfo);
57
58          // Proceed to invocation
59
return invocation.invokeNext();
60       }
61       finally
62       {
63          // Remove bridge
64
JBossServletContextProvider.set(null);
65       }
66    }
67 }
68
Popular Tags