Author: julien(a)jboss.com
Date: 2007-03-17 10:34:52 -0400 (Sat, 17 Mar 2007)
New Revision: 6725
Added:
trunk/portlet-server/src/main/org/jboss/portal/web/
trunk/portlet-server/src/main/org/jboss/portal/web/jboss/
trunk/portlet-server/src/main/org/jboss/portal/web/jboss/JBossWebContext.java
trunk/portlet/src/main/org/jboss/portal/web/
trunk/portlet/src/main/org/jboss/portal/web/spi/
trunk/portlet/src/main/org/jboss/portal/web/spi/RequestDispatchCallback.java
trunk/portlet/src/main/org/jboss/portal/web/spi/ServletContainerContext.java
Removed:
trunk/portlet-server/src/main/org/jboss/portal/portlet/container/
trunk/portlet/src/main/org/jboss/portal/portlet/container/runtime/
Modified:
trunk/core/src/resources/portal-core-sar/META-INF/jboss-service.xml
trunk/portlet-server/src/resources/test-sar/META-INF/jboss-service.xml
trunk/portlet/src/main/org/jboss/portal/portlet/aspects/portlet/ContextDispatcherInterceptor.java
trunk/portlet/src/main/org/jboss/portal/portlet/container/PortletContainerInvoker.java
trunk/wsrp/src/resources/tests/test-wsrp-producer-sar/META-INF/jboss-service.xml
Log:
PortletRuntimeContext -> ServletContainerContext : portlet agnostic and in an upper
package, to be extracted probably later
Modified: trunk/core/src/resources/portal-core-sar/META-INF/jboss-service.xml
===================================================================
--- trunk/core/src/resources/portal-core-sar/META-INF/jboss-service.xml 2007-03-17
03:16:26 UTC (rev 6724)
+++ trunk/core/src/resources/portal-core-sar/META-INF/jboss-service.xml 2007-03-17
14:34:52 UTC (rev 6725)
@@ -53,8 +53,8 @@
<!-- Runtime context for running portlet container -->
<mbean
-
code="org.jboss.portal.portlet.container.runtime.PortletRuntimeContextImpl"
- name="portal:service=PortletRuntimeContext"
+ code="org.jboss.portal.web.jboss.JBossWebContext"
+ name="portal:service=ServletContainerContext"
xmbean-dd=""
xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
<xmbean/>
@@ -267,8 +267,8 @@
xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
<xmbean/>
<depends
- optional-attribute-name="RuntimeContext"
-
proxy-type="attribute">portal:service=PortletRuntimeContext</depends>
+ optional-attribute-name="ServletContainerContext"
+
proxy-type="attribute">portal:service=ServletContainerContext</depends>
</mbean>
<mbean
code="org.jboss.portal.portlet.aspects.portlet.PortletSessionSynchronizationInterceptor"
@@ -792,9 +792,6 @@
<depends
optional-attribute-name="Registry"
proxy-type="attribute">portal:service=WebAppRegistry</depends>
- <depends
- optional-attribute-name="RuntimeContext"
-
proxy-type="attribute">portal:service=PortletRuntimeContext</depends>
</mbean>
<!-- The producer portlet invoker -->
Modified:
trunk/portlet/src/main/org/jboss/portal/portlet/aspects/portlet/ContextDispatcherInterceptor.java
===================================================================
---
trunk/portlet/src/main/org/jboss/portal/portlet/aspects/portlet/ContextDispatcherInterceptor.java 2007-03-17
03:16:26 UTC (rev 6724)
+++
trunk/portlet/src/main/org/jboss/portal/portlet/aspects/portlet/ContextDispatcherInterceptor.java 2007-03-17
14:34:52 UTC (rev 6725)
@@ -25,8 +25,8 @@
import org.jboss.portal.common.invocation.InvocationException;
import org.jboss.portal.portlet.container.PortletApplication;
import org.jboss.portal.portlet.container.PortletContainer;
-import org.jboss.portal.portlet.container.runtime.PortletRuntimeContext;
-import org.jboss.portal.portlet.container.runtime.RequestDispatchCallback;
+import org.jboss.portal.web.spi.ServletContainerContext;
+import org.jboss.portal.web.spi.RequestDispatchCallback;
import org.jboss.portal.portlet.impl.jsr168.info.ContainerPortletInfo;
import org.jboss.portal.portlet.invocation.PortletInterceptor;
import org.jboss.portal.portlet.invocation.PortletInvocation;
@@ -34,6 +34,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import javax.servlet.ServletContext;
/**
* This interceptor dispatch the call to the target web application.
@@ -48,16 +49,16 @@
public static final String REQ_ATT_COMPONENT_INVOCATION =
"org.jboss.portal.attribute.component_invocation";
/** . */
- private PortletRuntimeContext runtimeContext;
+ private ServletContainerContext servletContainerContext;
- public PortletRuntimeContext getRuntimeContext()
+ public ServletContainerContext getServletContainerContext()
{
- return runtimeContext;
+ return servletContainerContext;
}
- public void setRuntimeContext(PortletRuntimeContext runtimeContext)
+ public void setServletContainerContext(ServletContainerContext
servletContainerContext)
{
- this.runtimeContext = runtimeContext;
+ this.servletContainerContext = servletContainerContext;
}
protected Object invoke(PortletInvocation invocation) throws Exception,
InvocationException
@@ -65,7 +66,15 @@
PortletContainer container =
((ContainerPortletInfo)invocation.getInfo()).getContainer();
PortletApplication portletApplication = container.getApplication();
RequestContext reqCtx = invocation.getRequestContext();
- return runtimeContext.dispatch(reqCtx.getClientRequest(),
reqCtx.getClientResponse(), portletApplication, callback, invocation);
+ ServletContext targetCtx = portletApplication.getContext().getServletContext();
+ HttpServletRequest clientRequest = reqCtx.getClientRequest();
+ HttpServletResponse clientResponse = reqCtx.getClientResponse();
+ return servletContainerContext.dispatch(
+ clientRequest,
+ clientResponse,
+ targetCtx,
+ callback,
+ invocation);
}
private static final RequestDispatchCallback callback = new RequestDispatchCallback()
Modified:
trunk/portlet/src/main/org/jboss/portal/portlet/container/PortletContainerInvoker.java
===================================================================
---
trunk/portlet/src/main/org/jboss/portal/portlet/container/PortletContainerInvoker.java 2007-03-17
03:16:26 UTC (rev 6724)
+++
trunk/portlet/src/main/org/jboss/portal/portlet/container/PortletContainerInvoker.java 2007-03-17
14:34:52 UTC (rev 6725)
@@ -31,7 +31,6 @@
import org.jboss.portal.portlet.PortletContext;
import org.jboss.portal.portlet.PortletInvoker;
import org.jboss.portal.portlet.PortletInvokerException;
-import org.jboss.portal.portlet.container.runtime.PortletRuntimeContext;
import org.jboss.portal.portlet.impl.jsr168.info.ContainerPortletInfo;
import org.jboss.portal.portlet.impl.jsr168.info.ContainerPreferencesInfo;
import org.jboss.portal.portlet.impl.jsr168.info.ContainerPreferenceInfo;
@@ -68,9 +67,6 @@
private Map portlets;
/** . */
- private PortletRuntimeContext runtimeContext;
-
- /** . */
private InvocationHandler handler = new InvocationHandler()
{
public Object invoke(Invocation invocation) throws Exception,
org.jboss.portal.common.invocation.InvocationException
@@ -90,16 +86,6 @@
}
};
- public PortletRuntimeContext getRuntimeContext()
- {
- return runtimeContext;
- }
-
- public void setRuntimeContext(PortletRuntimeContext runtimeContext)
- {
- this.runtimeContext = runtimeContext;
- }
-
public PortletApplicationRegistry getRegistry()
{
return registry;
Copied: trunk/portlet/src/main/org/jboss/portal/web/spi/RequestDispatchCallback.java (from
rev 6720,
trunk/portlet/src/main/org/jboss/portal/portlet/container/runtime/RequestDispatchCallback.java)
===================================================================
--- trunk/portlet/src/main/org/jboss/portal/web/spi/RequestDispatchCallback.java
(rev 0)
+++
trunk/portlet/src/main/org/jboss/portal/web/spi/RequestDispatchCallback.java 2007-03-17
14:34:52 UTC (rev 6725)
@@ -0,0 +1,46 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.web.spi;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * Callback contract.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public interface RequestDispatchCallback
+{
+ /**
+ * Called by the runtime context when request dispatching has been done.
+ *
+ * @param dispatchedRequest the dispatched request
+ * @param dispatchedResponse the dispatched response
+ * @param handback the handback object provided to the dispatched
+ * @return any object
+ * @throws Exception any exception
+ */
+ Object doCallback(HttpServletRequest dispatchedRequest, HttpServletResponse
dispatchedResponse, Object handback) throws Exception;
+}
Copied: trunk/portlet/src/main/org/jboss/portal/web/spi/ServletContainerContext.java (from
rev 6720,
trunk/portlet/src/main/org/jboss/portal/portlet/container/runtime/PortletRuntimeContext.java)
===================================================================
--- trunk/portlet/src/main/org/jboss/portal/web/spi/ServletContainerContext.java
(rev 0)
+++
trunk/portlet/src/main/org/jboss/portal/web/spi/ServletContainerContext.java 2007-03-17
14:34:52 UTC (rev 6725)
@@ -0,0 +1,54 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.web.spi;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.ServletContext;
+
+/**
+ * Defines the service provider interface that a servlet container offers.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public interface ServletContainerContext
+{
+ /**
+ * Generic detyped request dispatch to a servlet context.
+ *
+ * @param request the request valid in the current servlet context
+ * @param response the response valid in the current servlet context
+ * @param targetServletContext the target servlet context to dispatch to
+ * @param callback the callback to perform after the dispatch operation
+ * @param handback the handback object to provide
+ * @return any object
+ * @throws Exception any exception
+ */
+ Object dispatch(
+ HttpServletRequest request,
+ HttpServletResponse response,
+ ServletContext targetServletContext,
+ RequestDispatchCallback callback,
+ Object handback) throws Exception;
+}
Added: trunk/portlet-server/src/main/org/jboss/portal/web/jboss/JBossWebContext.java
===================================================================
--- trunk/portlet-server/src/main/org/jboss/portal/web/jboss/JBossWebContext.java
(rev 0)
+++
trunk/portlet-server/src/main/org/jboss/portal/web/jboss/JBossWebContext.java 2007-03-17
14:34:52 UTC (rev 6725)
@@ -0,0 +1,137 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.web.jboss;
+
+import org.jboss.portal.portlet.PortletInvokerException;
+import org.jboss.portal.server.servlet.CommandServlet;
+import org.jboss.portal.server.servlet.ServletCommand;
+import org.jboss.portal.web.spi.ServletContainerContext;
+import org.jboss.portal.web.spi.RequestDispatchCallback;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import java.io.IOException;
+
+/**
+ * JBossWeb implementation of the spi.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class JBossWebContext implements ServletContainerContext
+{
+
+ /** . */
+ private static final ThreadLocal localResponse = new ThreadLocal();
+
+ public Object dispatch(
+ HttpServletRequest req,
+ HttpServletResponse resp,
+ ServletContext targetServletContext,
+ RequestDispatchCallback callback,
+ Object handback) throws Exception
+ {
+ try
+ {
+ //
+ ServletCommand cmd = new InvokeNextCommand(callback, handback);
+
+ //
+ CommandServlet.include(req, resp, cmd, targetServletContext);
+
+ // Rethrow any InvocationException
+ Object response = localResponse.get();
+
+ //
+ if (response instanceof Exception)
+ {
+ throw (Exception)response;
+ }
+ else
+ {
+ return response;
+ }
+ }
+ catch (IOException e)
+ {
+ throw new PortletInvokerException(e);
+ }
+ catch (ServletException e)
+ {
+ // Unwrap underlying exception if any
+ Throwable t = e.getRootCause();
+
+ //
+ if (t instanceof Error)
+ {
+ // Rethrow any error
+ throw(Error)t;
+ }
+ else if (t == null)
+ {
+ // If no nested exception use the servlet exception
+ t = e;
+ }
+
+ //
+ throw new PortletInvokerException(t);
+ }
+ finally
+ {
+ localResponse.set(null);
+ }
+ }
+
+ public static class InvokeNextCommand implements ServletCommand
+ {
+
+ /** . */
+ private final RequestDispatchCallback invocation;
+
+ /** . */
+ private final Object handback;
+
+ public InvokeNextCommand(RequestDispatchCallback invocation, Object handback)
+ {
+ this.invocation = invocation;
+ this.handback = handback;
+ }
+
+ public void execute(HttpServletRequest req, HttpServletResponse resp) throws
ServletException, IOException
+ {
+ try
+ {
+ Object response = invocation.doCallback(req, resp, handback);
+
+ //
+ localResponse.set(response);
+ }
+ catch (Exception e)
+ {
+ localResponse.set(e);
+ }
+ }
+ }
+}
Modified: trunk/portlet-server/src/resources/test-sar/META-INF/jboss-service.xml
===================================================================
--- trunk/portlet-server/src/resources/test-sar/META-INF/jboss-service.xml 2007-03-17
03:16:26 UTC (rev 6724)
+++ trunk/portlet-server/src/resources/test-sar/META-INF/jboss-service.xml 2007-03-17
14:34:52 UTC (rev 6725)
@@ -56,8 +56,8 @@
<!-- Runtime context for running portlet container -->
<mbean
-
code="org.jboss.portal.portlet.container.runtime.PortletRuntimeContextImpl"
- name="portal:service=PortletRuntimeContext"
+ code="org.jboss.portal.web.jboss.JBossWebContext"
+ name="portal:service=ServletContainerContext"
xmbean-dd=""
xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
<xmbean/>
@@ -138,8 +138,8 @@
xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
<xmbean/>
<depends
- optional-attribute-name="RuntimeContext"
-
proxy-type="attribute">portal:service=PortletRuntimeContext</depends>
+ optional-attribute-name="ServletContainerContext"
+
proxy-type="attribute">portal:service=ServletContainerContext</depends>
</mbean>
<mbean
code="org.jboss.portal.portlet.aspects.portlet.PortletSessionSynchronizationInterceptor"
@@ -253,7 +253,6 @@
<xmbean/>
<depends optional-attribute-name="StackFactory"
proxy-type="attribute">portal:service=InterceptorStackFactory,type=Container</depends>
<depends optional-attribute-name="Registry"
proxy-type="attribute">portal:service=WebAppRegistry</depends>
- <depends optional-attribute-name="RuntimeContext"
proxy-type="attribute">portal:service=PortletRuntimeContext</depends>
</mbean>
<!-- The portlet controller -->
Modified:
trunk/wsrp/src/resources/tests/test-wsrp-producer-sar/META-INF/jboss-service.xml
===================================================================
---
trunk/wsrp/src/resources/tests/test-wsrp-producer-sar/META-INF/jboss-service.xml 2007-03-17
03:16:26 UTC (rev 6724)
+++
trunk/wsrp/src/resources/tests/test-wsrp-producer-sar/META-INF/jboss-service.xml 2007-03-17
14:34:52 UTC (rev 6725)
@@ -44,6 +44,15 @@
<attribute
name="ExportedInterfaces">org.jboss.portal.test.framework.driver.http.HttpTestDriver</attribute>
</mbean>
+ <!-- Runtime context for running portlet container -->
+ <mbean
+ code="org.jboss.portal.web.jboss.JBossWebContext"
+ name="portal:service=ServletContainerContext"
+ xmbean-dd=""
+ xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
+ <xmbean/>
+ </mbean>
+
<!-- Webapp registry -->
<mbean
code="org.jboss.portal.portlet.container.PortletApplicationRegistryImpl"
@@ -78,6 +87,9 @@
xmbean-dd=""
xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
<xmbean/>
+ <depends
+ optional-attribute-name="ServletContainerContext"
+
proxy-type="attribute">portal:service=ServletContainerContext</depends>
</mbean>
<mbean
code="org.jboss.portal.portlet.aspects.portlet.WindowStatesInterceptor"