Author: woonsan
Date: Wed Dec 2 16:25:46 2009
New Revision: 886193
URL: http://svn.apache.org/viewvc?rev=886193&view=rev
Log:
JS2-1087: Makes service beans leverage spring dependency injection.
Added:
portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/JetspeedJaxrsApplication.java
(with props)
Modified:
portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/pipeline/valve/impl/ServletDelegatingValve.java
portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/PortletRegistryService.java
portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/jetspeed-restful-services.xml
Modified:
portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/pipeline/valve/impl/ServletDelegatingValve.java
URL:
http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/pipeline/valve/impl/ServletDelegatingValve.java?rev=886193&r1=886192&r2=886193&view=diff
==============================================================================
---
portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/pipeline/valve/impl/ServletDelegatingValve.java
(original)
+++
portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/pipeline/valve/impl/ServletDelegatingValve.java
Wed Dec 2 16:25:46 2009
@@ -38,6 +38,7 @@
{
protected HttpServlet servlet;
protected ServletConfig config;
+ protected boolean servletInitialized;
public ServletDelegatingValve(HttpServlet servlet, ServletConfig config)
{
@@ -48,19 +49,21 @@
@Override
public void initialize() throws PipelineException
{
- try
- {
- servlet.init(config);
- }
- catch (Exception e)
- {
- throw new PipelineException(e);
- }
}
-
+
public void destroy()
{
- servlet.destroy();
+ if (servlet != null && servletInitialized)
+ {
+ try
+ {
+ servlet.destroy();
+ }
+ finally
+ {
+ servletInitialized = false;
+ }
+ }
}
@Override
@@ -68,6 +71,11 @@
{
try
{
+ if (!servletInitialized)
+ {
+ initServlet();
+ }
+
servlet.service(request.getRequest(), request.getResponse());
}
catch (Exception e)
@@ -78,6 +86,22 @@
// continue
context.invokeNext(request);
}
+
+ private synchronized void initServlet() throws PipelineException
+ {
+ if (!servletInitialized)
+ {
+ try
+ {
+ servlet.init(config);
+ servletInitialized = true;
+ }
+ catch (Exception e)
+ {
+ throw new PipelineException(e);
+ }
+ }
+ }
public static class ServletConfigImpl implements ServletConfig
{
Added:
portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/JetspeedJaxrsApplication.java
URL:
http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/JetspeedJaxrsApplication.java?rev=886193&view=auto
==============================================================================
---
portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/JetspeedJaxrsApplication.java
(added)
+++
portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/JetspeedJaxrsApplication.java
Wed Dec 2 16:25:46 2009
@@ -0,0 +1,84 @@
+/*
+ * 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 java.util.Set;
+import java.util.HashSet;
+
+import javax.ws.rs.core.Application;
+
+import org.apache.jetspeed.Jetspeed;
+
+/**
+ * JetspeedJaxrsApplication
+ *
+ * @version $Id$
+ */
+public class JetspeedJaxrsApplication extends Application
+{
+
+ public static final String CLASSES_ID =
JetspeedJaxrsApplication.class.getPackage().getName() + ".classes";
+
+ public static final String SINGLETONS_ID =
JetspeedJaxrsApplication.class.getPackage().getName() + ".singletons";
+
+
+ private Set<Class<?>> classes = new HashSet<Class<?>>();
+
+ private Set<Object> singletons = new HashSet<Object>();
+
+ public JetspeedJaxrsApplication()
+ {
+ super();
+
+ String classesId = System.getProperty(CLASSES_ID);
+
+ if (classesId != null &&
Jetspeed.getComponentManager().containsComponent(classesId))
+ {
+ classes = (Set<Class<?>>)
Jetspeed.getComponentManager().getComponent(classesId);
+ }
+
+ String singletonsId = System.getProperty(SINGLETONS_ID);
+
+ if (singletonsId != null &&
Jetspeed.getComponentManager().containsComponent(singletonsId))
+ {
+ singletons = (Set<Object>)
Jetspeed.getComponentManager().getComponent(singletonsId);
+ }
+ }
+
+ @Override
+ public Set<Class<?>> getClasses()
+ {
+ return classes;
+ }
+
+ public void setClasses(final Set<Class<?>> classes)
+ {
+ this.classes = classes;
+ }
+
+ @Override
+ public Set<Object> getSingletons()
+ {
+ return singletons;
+ }
+
+ public void setSingletons(final Set<Object> singletons)
+ {
+ this.singletons = singletons;
+ }
+
+}
\ No newline at end of file
Propchange:
portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/JetspeedJaxrsApplication.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/JetspeedJaxrsApplication.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange:
portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/JetspeedJaxrsApplication.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified:
portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/PortletRegistryService.java
URL:
http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/PortletRegistryService.java?rev=886193&r1=886192&r2=886193&view=diff
==============================================================================
---
portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/PortletRegistryService.java
(original)
+++
portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/PortletRegistryService.java
Wed Dec 2 16:25:46 2009
@@ -33,7 +33,6 @@
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;
-import org.apache.jetspeed.Jetspeed;
import org.apache.jetspeed.components.portletregistry.PortletRegistry;
import org.apache.jetspeed.om.portlet.PortletApplication;
import org.apache.jetspeed.om.portlet.PortletDefinition;
@@ -67,25 +66,21 @@
@Context
private ServletContext servletContext;
- @Context
- private HttpServletRequest servletRequest;
-
- @Context
- private UriInfo uriInfo;
-
private PortletRegistry portletRegistry;
private SearchEngine searchEngine;
- public PortletRegistryService()
+ public PortletRegistryService(PortletRegistry portletRegistry,
SearchEngine searchEngine)
{
- portletRegistry = (PortletRegistry)
Jetspeed.getComponentManager().getComponent(PortletRegistry.class);
- searchEngine = (SearchEngine)
Jetspeed.getComponentManager().getComponent(SearchEngine.class);
+ this.portletRegistry = portletRegistry;
+ this.searchEngine = searchEngine;
}
@GET
@Path("/application/{path:.*}")
- public PortletApplicationBeans getPortletApplication(@PathParam("path")
List<PathSegment> pathSegments,
+ public PortletApplicationBeans getPortletApplication(@Context
HttpServletRequest servletRequest,
+ @Context UriInfo
uriInfo,
+ @PathParam("path")
List<PathSegment> pathSegments,
@QueryParam("query")
String queryParam,
@QueryParam("begin")
String beginIndexParam,
@QueryParam("max")
String maxResultsParam)
@@ -152,7 +147,9 @@
@GET
@Path("/definition/{path:.*}")
- public PortletDefinitionBeans getPortletDefinition(@PathParam("path")
List<PathSegment> pathSegments,
+ public PortletDefinitionBeans getPortletDefinition(@Context
HttpServletRequest servletRequest,
+ @Context UriInfo
uriInfo,
+ @PathParam("path")
List<PathSegment> pathSegments,
@QueryParam("query")
String queryParam,
@QueryParam("begin")
String beginIndexParam,
@QueryParam("max")
String maxResultsParam)
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=886193&r1=886192&r2=886193&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 2 16:25:46 2009
@@ -18,7 +18,9 @@
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
+ <!-- To enable log4j logging instead of the default java logging of cxf. -->
<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">
@@ -29,18 +31,32 @@
</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>
- <!-- White space separted resource class names -->
- <prop key="jaxrs.serviceClasses">
- org.apache.jetspeed.services.rest.PortletRegistryService
+ <prop key="javax.ws.rs.Application">
+ org.apache.jetspeed.services.rest.JetspeedJaxrsApplication
</prop>
</props>
</constructor-arg>
@@ -52,4 +68,21 @@
</property>
</bean>
+ <!-- JAX-RS Service Singleton Resource Beans -->
+ <bean id="org.apache.jetspeed.services.rest.singletons"
class="org.springframework.beans.factory.config.SetFactoryBean">
+ <meta key="j2:cat" value="default" />
+ <property name="sourceSet">
+ <set>
+ <ref bean="jaxrsPortletRegistryService" />
+ </set>
+ </property>
+ </bean>
+
+ <!-- Portlet Registry JAX-RS Service -->
+ <bean id="jaxrsPortletRegistryService"
class="org.apache.jetspeed.services.rest.PortletRegistryService">
+ <meta key="j2:cat" value="default" />
+ <constructor-arg
ref="org.apache.jetspeed.components.portletregistry.PortletRegistry" />
+ <constructor-arg ref="org.apache.jetspeed.search.SearchEngine" />
+ </bean>
+
</beans>
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]