portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From woon...@apache.org
Subject svn commit: r888853 - in /portals/jetspeed-2/portal/trunk: components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/ jetspeed-portal-resources/src/main/resources/assembly/
Date Wed, 09 Dec 2009 16:09:58 GMT
Author: woonsan
Date: Wed Dec  9 16:09:57 2009
New Revision: 888853

URL: http://svn.apache.org/viewvc?rev=888853&view=rev
Log:
JS2-1087: Removing static access to jetspeed component manager from jaxrs application.

Added:
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/JaxrsServiceValve.java
  (with props)
Removed:
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/JetspeedJaxrsApplication.java
Modified:
    portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/jetspeed-restful-services.xml
    portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/pipelines.xml

Added: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/JaxrsServiceValve.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/JaxrsServiceValve.java?rev=888853&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/JaxrsServiceValve.java
(added)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/JaxrsServiceValve.java
Wed Dec  9 16:09:57 2009
@@ -0,0 +1,117 @@
+/*
+ * 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.jetspeed.services.rest;
+
+import org.apache.commons.beanutils.MethodUtils;
+import org.apache.jetspeed.pipeline.PipelineException;
+import org.apache.jetspeed.pipeline.valve.AbstractValve;
+import org.apache.jetspeed.pipeline.valve.ValveContext;
+import org.apache.jetspeed.request.RequestContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * JaxrsServiceValve
+ *
+ * @version $Id$
+ */
+public class JaxrsServiceValve extends AbstractValve
+{
+    
+    private static final Logger log = LoggerFactory.getLogger(JaxrsServiceValve.class);
+
+    private Class<?> busFactoryClass;       // org.apache.cxf.BusFactory
+    private Object bus;                     // org.apache.cxf.Bus
+    private Object servletController;       // org.apache.cxf.transport.servlet.ServletController
+    private Object jaxrsServerFactoryBean;  // org.apache.cxf.jaxrs.JAXRSServerFactoryBean
+    
+    public JaxrsServiceValve(Class<?> busFactoryClass, Object bus, Object servletController,
Object jaxrsServerFactoryBean)
+    {
+        this.busFactoryClass = busFactoryClass;
+        this.bus = bus;
+        this.servletController = servletController;
+        this.jaxrsServerFactoryBean = jaxrsServerFactoryBean;
+    }
+    
+    @Override
+    public void initialize() throws PipelineException
+    {
+        try 
+        {
+            MethodUtils.invokeStaticMethod(busFactoryClass, "setThreadDefaultBus", new Object
[] { bus });
+            MethodUtils.invokeMethod(jaxrsServerFactoryBean, "create", null);
+        }
+        catch (Exception e)
+        {
+            log.error("Failed to initialize jaxrs server.", e);
+        }
+        finally 
+        {
+            try
+            {
+                MethodUtils.invokeStaticMethod(busFactoryClass, "setThreadDefaultBus",  new
Object [] { null });
+            }
+            catch (Exception ignore)
+            {
+            }
+        }
+    }
+    
+    public void destroy() 
+    {
+        try
+        {
+            MethodUtils.invokeMethod(bus, "shutdown", Boolean.TRUE);
+        }
+        catch (Exception e)
+        {
+            log.error("Failed to destroy jaxrs bus.", e);
+        }
+    }
+    
+    @Override
+    public void invoke(RequestContext request, ValveContext context) throws PipelineException
+    {
+        try 
+        {
+            MethodUtils.invokeStaticMethod(busFactoryClass, "setThreadDefaultBus", new Object
[] { bus });
+            MethodUtils.invokeMethod(servletController, "invoke", new Object [] { request.getRequest(),
request.getResponse() });
+        }
+        catch (Exception e)
+        {
+            if (log.isDebugEnabled())
+            {
+                log.error("Failed to invoke jaxrs service.", e);
+            }
+            else
+            {
+                log.error("Failed to invoke jaxrs service. {}", e.toString());
+            }
+        }
+        finally 
+        {
+            try
+            {
+                MethodUtils.invokeStaticMethod(busFactoryClass, "setThreadDefaultBus",  new
Object [] { null });
+            }
+            catch (Exception ignore)
+            {
+            }
+        }
+    }
+    
+}

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/JaxrsServiceValve.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/JaxrsServiceValve.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/JaxrsServiceValve.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/jetspeed-restful-services.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/jetspeed-restful-services.xml?rev=888853&r1=888852&r2=888853&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/jetspeed-restful-services.xml
(original)
+++ portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/jetspeed-restful-services.xml
Wed Dec  9 16:09:57 2009
@@ -32,43 +32,6 @@
     </property>
   </bean>
   
-  <!-- To set resource singletons bean id properties -->
-  <bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
-    <meta key="j2:cat" value="default" />
-    <property name="targetClass" value="java.lang.System"/>
-    <property name="targetMethod" value="setProperty"/>
-    <property name="arguments">
-      <list>
-        <value>org.apache.jetspeed.services.rest.singletons</value>
-        <value>org.apache.jetspeed.services.rest.singletons</value>
-      </list>
-    </property>
-  </bean>
-  
-  <!-- Delegating CXF Servlet -->
-  <bean id="cxfServlet" class="org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet">
-    <meta key="j2:cat" value="default" />
-  </bean>
-  
-  <!-- CXF Servlet Config -->
-  <bean id="cxfServletConfig" class="org.apache.jetspeed.pipeline.valve.impl.ServletDelegatingValve$ServletConfigImpl">
-    <meta key="j2:cat" value="default" />
-    <constructor-arg value="CXFNonSpringJaxrsServlet" />
-    <constructor-arg>
-      <props>
-        <prop key="javax.ws.rs.Application">
-          org.apache.jetspeed.services.rest.JetspeedJaxrsApplication
-        </prop>
-      </props>
-    </constructor-arg>
-    <property name="servletContext">
-      <bean class="org.springframework.beans.factory.config.PropertyPathFactoryBean">
-        <property name="targetObject" ref="javax.servlet.ServletConfig" />
-        <property name="propertyPath" value="servletContext"/>
-      </bean>
-    </property>
-  </bean>
-
   <bean id="jacksonObjectMapper" class="org.codehaus.jackson.map.ObjectMapper">
     <meta key="j2:cat" value="default" />
   </bean>
@@ -116,20 +79,56 @@
     <property name="mapper" ref="jacksonObjectMapper" />
   </bean>
   
-  <!-- JAX-RS Service Singleton Resource Beans  -->
-  <bean id="org.apache.jetspeed.services.rest.singletons" class="org.springframework.beans.factory.config.SetFactoryBean">
+  <bean id="cxfJaxrsBus" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
     <meta key="j2:cat" value="default" />
-    <property name="sourceSet">
-      <set>
-        
-        <!-- JAX-RS Providers -->
+    <property name="targetClass" value="org.apache.cxf.BusFactory"/>
+    <property name="targetMethod" value="getThreadDefaultBus"/>
+    <property name="arguments">
+      <list>
+        <value>true</value>
+      </list>
+    </property>
+  </bean>
+  
+  <bean id="cxfDestinationFactory" class="org.apache.cxf.transport.servlet.ServletTransportFactory">
+    <meta key="j2:cat" value="default" />
+    <constructor-arg ref="cxfJaxrsBus" />
+  </bean>
+  
+  <bean id="cxfJaxrsServletController" class="org.apache.cxf.transport.servlet.ServletController">
+    <meta key="j2:cat" value="default" />
+    <constructor-arg ref="cxfDestinationFactory" />
+    <constructor-arg ref="javax.servlet.ServletConfig" />
+    <constructor-arg>
+      <bean class="org.springframework.beans.factory.config.PropertyPathFactoryBean">
+        <meta key="j2:cat" value="default" />
+        <property name="targetObject" ref="javax.servlet.ServletConfig" />
+        <property name="propertyPath" value="servletContext"/>
+      </bean>
+    </constructor-arg>
+    <constructor-arg ref="cxfJaxrsBus" />
+  </bean>
+  
+  <bean id="cxfJaxrsServerFactoryBean" class="org.apache.cxf.jaxrs.JAXRSServerFactoryBean">
+    <meta key="j2:cat" value="default" />
+    <property name="address" value="/" />
+    <property name="destinationFactory" ref="cxfDestinationFactory" />
+    <property name="providers">
+      <list>
         <ref bean="jaxrsJsonProvider" />
-        
-        <!-- Resource providers -->
-        <ref bean="jaxrsPortletRegistryService" />
-        <ref bean="jaxrsPageManagementService" />
-        
-      </set>
+      </list>
+    </property>
+    <property name="resourceProviders">
+      <list>
+        <bean class="org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider">
+          <meta key="j2:cat" value="default" />
+          <constructor-arg ref="jaxrsPortletRegistryService" />
+        </bean>
+        <bean class="org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider">
+          <meta key="j2:cat" value="default" />
+          <constructor-arg ref="jaxrsPageManagementService" />
+        </bean>
+      </list>
     </property>
   </bean>
   

Modified: portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/pipelines.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/pipelines.xml?rev=888853&r1=888852&r2=888853&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/pipelines.xml
(original)
+++ portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/pipelines.xml
Wed Dec  9 16:09:57 2009
@@ -350,11 +350,13 @@
     </constructor-arg>
   </bean>
   
-  <bean id="RestfulServicesValve" class="org.apache.jetspeed.pipeline.valve.impl.ServletDelegatingValve"

+  <bean id="RestfulServicesValve" class="org.apache.jetspeed.services.rest.JaxrsServiceValve"

         init-method="initialize" destroy-method="destroy">
     <meta key="j2:cat" value="default" />
-    <constructor-arg ref="cxfServlet" />
-    <constructor-arg ref="cxfServletConfig" />
+    <constructor-arg value="org.apache.cxf.BusFactory" />
+    <constructor-arg ref="cxfJaxrsBus" />
+    <constructor-arg ref="cxfJaxrsServletController" />
+    <constructor-arg ref="cxfJaxrsServerFactoryBean" />
   </bean>
   
   <bean id="DecorationValve" class="org.apache.jetspeed.decoration.DecorationValve" init-method="initialize">



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message