Author: cziegeler
Date: Thu Nov 22 14:26:16 2012
New Revision: 1412557

URL: http://svn.apache.org/viewvc?rev=1412557&view=rev
Log:
Add portlet bridge support

Added:
    sling/whiteboard/portal/portlet-bridge/
    sling/whiteboard/portal/portlet-bridge/pom.xml   (with props)
    sling/whiteboard/portal/portlet-bridge/src/
    sling/whiteboard/portal/portlet-bridge/src/main/
    sling/whiteboard/portal/portlet-bridge/src/main/java/
    sling/whiteboard/portal/portlet-bridge/src/main/java/org/
    sling/whiteboard/portal/portlet-bridge/src/main/java/org/apache/
    sling/whiteboard/portal/portlet-bridge/src/main/java/org/apache/sling/
    
sling/whiteboard/portal/portlet-bridge/src/main/java/org/apache/sling/portal/
    
sling/whiteboard/portal/portlet-bridge/src/main/java/org/apache/sling/portal/bridge/
    
sling/whiteboard/portal/portlet-bridge/src/main/java/org/apache/sling/portal/bridge/ServletContextProviderImpl.java
   (with props)
Modified:
    
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/services/DefaultPortletInvokerService.java

Modified: 
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/services/DefaultPortletInvokerService.java
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/services/DefaultPortletInvokerService.java?rev=1412557&r1=1412556&r2=1412557&view=diff
==============================================================================
--- 
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/services/DefaultPortletInvokerService.java
 (original)
+++ 
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/services/DefaultPortletInvokerService.java
 Thu Nov 22 14:26:16 2012
@@ -43,6 +43,8 @@ import org.apache.pluto.container.Portle
 import org.apache.pluto.container.PortletRequestContext;
 import org.apache.pluto.container.PortletResponseContext;
 import org.apache.pluto.container.PortletWindow;
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.SlingHttpServletResponse;
 import org.apache.sling.portal.container.PortletEntityId;
 import org.apache.sling.portal.container.PortletRegistryService;
 import org.apache.sling.portal.container.SlingPortletConfig;
@@ -50,6 +52,7 @@ import org.apache.sling.portal.container
 import org.apache.sling.portal.container.SlingPortletEntity;
 import org.apache.sling.portal.container.SlingPortletWindow;
 import org.apache.sling.portal.container.api.Container;
+import org.apache.sling.portal.container.api.SlingRequestDispatcher;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -178,6 +181,8 @@ public class DefaultPortletInvokerServic
                 final HttpServletResponse containerResponse = 
context.getContainerResponse();
 
                 try {
+                    
containerRequest.setAttribute(SlingRequestDispatcher.REQ_ATTR, new 
SlingRequestDispatcherImpl(
+                        (SlingHttpServletRequest)containerRequest, 
(SlingHttpServletResponse)containerResponse));
                     containerRequest.setAttribute(ATTR_PORTLET, portletEntity);
                     containerRequest.setAttribute(Container.ATTR_CONTAINER, 
this);
                     
containerRequest.setAttribute(PortletInvokerService.METHOD_ID, methodID);
@@ -225,6 +230,7 @@ public class DefaultPortletInvokerServic
                     
containerRequest.removeAttribute(PortletInvokerService.PORTLET_RESPONSE);
                     
containerRequest.removeAttribute(PortletInvokerService.FILTER_MANAGER);
                     
containerRequest.removeAttribute(PortletInvokerService.PORTLET_CONFIG);
+                    
containerRequest.removeAttribute(SlingRequestDispatcher.REQ_ATTR);
                 }
             } else {
                 throw new PortletException("Unable to retrieve portlet invoker 
dispatcher. Check if the container servlet is running in the portlet 
application.");

Added: sling/whiteboard/portal/portlet-bridge/pom.xml
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/portal/portlet-bridge/pom.xml?rev=1412557&view=auto
==============================================================================
--- sling/whiteboard/portal/portlet-bridge/pom.xml (added)
+++ sling/whiteboard/portal/portlet-bridge/pom.xml Thu Nov 22 14:26:16 2012
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied.  See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.sling</groupId>
+        <artifactId>sling</artifactId>
+        <version>13</version>
+    </parent>
+
+    <groupId>org.apache.sling.portal</groupId>
+    <artifactId>org.apache.sling.portal.bridge</artifactId>
+    <version>0.1.0-SNAPSHOT</version>
+
+    <name>Apache Sling Portal Bridge</name>
+    <description>
+        The Apache Sling Portal Bridge.
+    </description>
+
+    <scm>
+        
<connection>scm:svn:http://svn.apache.org/repos/asf/sling/whiteboard/portal/portlet-bridge</connection>
+        
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/whiteboard/portal/portlet-bridge</developerConnection>
+        
<url>http://svn.apache.org/viewvc/sling/whiteboard/portal/portlet-bridge</url>
+    </scm>
+
+    <dependencies>
+        <dependency>
+            <groupId>javax.servlet</groupId>
+            <artifactId>servlet-api</artifactId>
+            <version>2.4</version>
+            <scope>provided</scope>
+        </dependency>
+
+      <!-- Portlet API -->
+        <dependency>
+            <groupId>javax.portlet</groupId>
+            <artifactId>portlet-api</artifactId>
+            <version>2.0</version>
+            <scope>provided</scope>
+        </dependency>
+        
+        <dependency>
+            <groupId>org.apache.portals.bridges</groupId>
+            <artifactId>portals-bridges-common</artifactId>
+            <version>2.0</version>
+            <scope>provided</scope>
+        </dependency>
+
+    </dependencies>
+</project>

Propchange: sling/whiteboard/portal/portlet-bridge/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/whiteboard/portal/portlet-bridge/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Id

Added: 
sling/whiteboard/portal/portlet-bridge/src/main/java/org/apache/sling/portal/bridge/ServletContextProviderImpl.java
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/portal/portlet-bridge/src/main/java/org/apache/sling/portal/bridge/ServletContextProviderImpl.java?rev=1412557&view=auto
==============================================================================
--- 
sling/whiteboard/portal/portlet-bridge/src/main/java/org/apache/sling/portal/bridge/ServletContextProviderImpl.java
 (added)
+++ 
sling/whiteboard/portal/portlet-bridge/src/main/java/org/apache/sling/portal/bridge/ServletContextProviderImpl.java
 Thu Nov 22 14:26:16 2012
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.portal.bridge;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import javax.portlet.GenericPortlet;
+import javax.portlet.PortletRequest;
+import javax.portlet.PortletResponse;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.portals.bridges.common.ServletContextProvider;
+
+public class ServletContextProviderImpl implements ServletContextProvider {
+
+    private Method getRequestContext;
+    private Method getContainerRequest;
+    private Method getResponseContext;
+    private Method getContainerResponse;
+    private Method getServletContext;
+
+    private Method searchMethod(final Class<?> clazz, final String name) {
+        final Method m = findMethod(clazz, name);
+        if ( m == null ) {
+            new NoSuchMethodException(clazz + " : " + name).printStackTrace();
+        }
+        return m;
+    }
+
+    private Method findMethod(final Class<?> clazz, final String name) {
+        try {
+            final Method m = clazz.getDeclaredMethod(name, null);
+            m.setAccessible(true);
+            return m;
+        } catch (SecurityException e) {
+            // ignore
+        } catch (NoSuchMethodException e) {
+            // ignore
+        } catch (IllegalArgumentException e) {
+            // ignore
+        }
+        if ( clazz.getSuperclass() != null ) {
+            return findMethod(clazz.getSuperclass(), name);
+        }
+        return null;
+    }
+
+    private Object invoke(final Object obj, final Method m) {
+        if ( m != null ) {
+            try {
+                return m.invoke(obj, null);
+            } catch (IllegalAccessException e) {
+                // ignore
+            } catch (InvocationTargetException e) {
+                // ignore
+            }
+        }
+        return null;
+    }
+
+    public HttpServletRequest getHttpServletRequest(final GenericPortlet 
portlet,
+            final PortletRequest req) {
+        if ( getRequestContext == null ) {
+            getRequestContext = searchMethod(req.getClass(), 
"getRequestContext");
+        }
+        final Object context = invoke(req, getRequestContext);
+        if ( context != null ) {
+            if ( getContainerRequest == null ) {
+                getContainerRequest = searchMethod(context.getClass(), 
"getContainerRequest");
+            }
+            return (HttpServletRequest)invoke(context, getContainerRequest);
+        }
+
+        return null;
+    }
+
+    public HttpServletResponse getHttpServletResponse(final GenericPortlet 
portlet,
+            final PortletResponse res) {
+        if ( getResponseContext == null ) {
+            getResponseContext = searchMethod(res.getClass(), 
"getResponseContext");
+        }
+        final Object context = invoke(res, getResponseContext);
+        if ( context != null ) {
+            if ( getContainerResponse == null ) {
+                getContainerResponse = searchMethod(context.getClass(), 
"getContainerResponse");
+            }
+            return (HttpServletResponse)invoke(context, getContainerResponse);
+        }
+
+        return null;
+    }
+
+    public ServletContext getServletContext(final GenericPortlet portlet) {
+        if ( getServletContext == null ) {
+            getServletContext = 
searchMethod(portlet.getPortletContext().getClass(), "getServletContext");
+        }
+        return (ServletContext)invoke(portlet.getPortletContext(), 
getServletContext);
+    }
+}

Propchange: 
sling/whiteboard/portal/portlet-bridge/src/main/java/org/apache/sling/portal/bridge/ServletContextProviderImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
sling/whiteboard/portal/portlet-bridge/src/main/java/org/apache/sling/portal/bridge/ServletContextProviderImpl.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url


Reply via email to