cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1558850 - in /cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring: AbstractSpringComponentScanServer.java AbstractSpringConfigurationFactory.java SpringComponentScanServer.java SpringResourceServer.java
Date Thu, 16 Jan 2014 16:40:17 GMT
Author: sergeyb
Date: Thu Jan 16 16:40:17 2014
New Revision: 1558850

URL: http://svn.apache.org/r1558850
Log:
[CXF-5495] Initial refactoring to JAX-RS SpringResourceServer based on the input from Paul
Wilson and David Clark

Added:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/AbstractSpringComponentScanServer.java
  (with props)
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/AbstractSpringConfigurationFactory.java
  (with props)
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/SpringComponentScanServer.java
      - copied, changed from r1557999, cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/SpringResourceServer.java
Removed:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/SpringResourceServer.java

Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/AbstractSpringComponentScanServer.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/AbstractSpringComponentScanServer.java?rev=1558850&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/AbstractSpringComponentScanServer.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/AbstractSpringComponentScanServer.java
Thu Jan 16 16:40:17 2014
@@ -0,0 +1,80 @@
+/**
+ * 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.cxf.jaxrs.spring;
+
+import java.lang.annotation.Annotation;
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.ws.rs.Path;
+import javax.ws.rs.ext.Provider;
+
+import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
+import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.FilterType;
+
+@ComponentScan(
+    includeFilters = @ComponentScan.Filter(type = FilterType.ANNOTATION, value = {Path.class,
Provider.class })
+)
+public abstract class AbstractSpringComponentScanServer extends AbstractSpringConfigurationFactory
{
+
+    private List<ResourceProvider> resourceProviders = new LinkedList<ResourceProvider>();
+    private List<Object> jaxrsProviders = new LinkedList<Object>();
+
+    
+    protected void setRootResources(JAXRSServerFactoryBean factory) {
+        boolean checkJaxrsRoots = checkJaxrsRoots();
+        boolean checkJaxrsProviders = checkJaxrsProviders(); 
+        
+        for (String beanName : applicationContext.getBeanDefinitionNames()) {
+            if (checkJaxrsRoots && isAnnotationAvailable(beanName, Path.class)) {
+                SpringResourceFactory resourceFactory = new SpringResourceFactory(beanName);
+                resourceFactory.setApplicationContext(applicationContext);
+                resourceProviders.add(resourceFactory);
+            } else if (checkJaxrsProviders && isAnnotationAvailable(beanName, Provider.class))
{
+                jaxrsProviders.add(applicationContext.getBean(beanName));
+            }
+        }
+
+        factory.setResourceProviders(getResourceProviders());
+    }
+    
+    protected <A extends Annotation> boolean isAnnotationAvailable(String beanName,
Class<A> annClass) {
+        return applicationContext.findAnnotationOnBean(beanName, annClass) != null;
+    }
+    
+    protected boolean checkJaxrsProviders() {
+        return true;    
+    }
+    
+    protected boolean checkJaxrsRoots() {
+        return true;    
+    }
+
+    protected List<ResourceProvider> getResourceProviders() {
+        return resourceProviders;
+    }
+    
+    protected List<Object> getJaxrsProviders() {
+        return jaxrsProviders;
+    }
+    
+    
+}

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/AbstractSpringComponentScanServer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/AbstractSpringComponentScanServer.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/AbstractSpringConfigurationFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/AbstractSpringConfigurationFactory.java?rev=1558850&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/AbstractSpringConfigurationFactory.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/AbstractSpringConfigurationFactory.java
Thu Jan 16 16:40:17 2014
@@ -0,0 +1,95 @@
+/**
+ * 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.cxf.jaxrs.spring;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.cxf.bus.spring.SpringBus;
+import org.apache.cxf.endpoint.Server;
+import org.apache.cxf.feature.Feature;
+import org.apache.cxf.interceptor.Interceptor;
+import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
+import org.apache.cxf.message.Message;
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.context.annotation.Import;
+
+@Import(JaxRsConfig.class)
+public abstract class AbstractSpringConfigurationFactory implements ApplicationContextAware
{
+
+    protected ApplicationContext applicationContext;
+    
+    protected Server createJaxRsServer() {
+
+        JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean();
+        factory.setAddress(getAddress());
+        factory.setTransportId(getTransportId());
+        factory.setBus(applicationContext.getBean(SpringBus.class));
+        
+        setRootResources(factory);
+        factory.setProviders(getJaxrsProviders());
+        factory.setInInterceptors(getInInterceptors());
+        factory.setOutInterceptors(getOutInterceptors());
+        factory.setOutFaultInterceptors(getOutFaultInterceptors());
+        factory.setFeatures(getFeatures());
+        finalizeFactorySetup(factory);
+        return factory.create();
+    }
+    
+    @Override
+    public void setApplicationContext(ApplicationContext ac) throws BeansException {
+        applicationContext = ac;
+    }
+    
+    protected abstract void setRootResources(JAXRSServerFactoryBean factory);
+    
+    protected List<Object> getJaxrsProviders() {
+        return Collections.emptyList();
+    }
+    
+    protected List<Interceptor<? extends Message>> getInInterceptors() {
+        return Collections.emptyList();
+    }
+    
+    protected List<Interceptor<? extends Message>> getOutInterceptors() {
+        return Collections.emptyList();
+    }
+    
+    protected List<Feature> getFeatures() {
+        return Collections.emptyList();
+    }
+    
+    protected List<Interceptor<? extends Message>> getOutFaultInterceptors()
{
+        return Collections.emptyList();
+    }
+    
+    protected String getAddress() {
+        return "/";
+    }
+    
+    protected String getTransportId() {
+        return "http://cxf.apache.org/transports/http";
+    }
+    
+    protected void finalizeFactorySetup(JAXRSServerFactoryBean factory) {
+        // complete
+    }
+}

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/AbstractSpringConfigurationFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/AbstractSpringConfigurationFactory.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Copied: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/SpringComponentScanServer.java
(from r1557999, cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/SpringResourceServer.java)
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/SpringComponentScanServer.java?p2=cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/SpringComponentScanServer.java&p1=cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/SpringResourceServer.java&r1=1557999&r2=1558850&rev=1558850&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/SpringResourceServer.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/SpringComponentScanServer.java
Thu Jan 16 16:40:17 2014
@@ -18,101 +18,15 @@
  */
 package org.apache.cxf.jaxrs.spring;
 
-import java.lang.annotation.Annotation;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Set;
-
-import javax.ws.rs.Path;
-import javax.ws.rs.ext.Provider;
-
-import org.apache.cxf.bus.spring.SpringBus;
 import org.apache.cxf.endpoint.Server;
-import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
-import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.ApplicationContext;
 import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.ComponentScan;
-import org.springframework.context.annotation.Import;
 
-@Import(JaxRsConfig.class)
-@ComponentScan
-public class SpringResourceServer {
-    @Autowired
-    protected ApplicationContext applicationContext;
 
-    private String address = "/";
-    private Set<String> supportedBeanNames;
-    private List<ResourceProvider> resourceProviders = new LinkedList<ResourceProvider>();
-    private List<Object> jaxrsProviders = new LinkedList<Object>();
-    
+public class SpringComponentScanServer extends AbstractSpringComponentScanServer {
+
     @Bean
     public Server jaxRsServer() {
-        boolean checkJaxrsRoots = checkJaxrsRoots();
-        boolean checkJaxrsProviders = checkJaxrsProviders(); 
-        
-        for (String beanName : applicationContext.getBeanDefinitionNames()) {
-            if (checkJaxrsRoots && isAnnotationAvailable(beanName, Path.class)) {
-                SpringResourceFactory factory = new SpringResourceFactory(beanName);
-                factory.setApplicationContext(applicationContext);
-                resourceProviders.add(factory);
-            } else if (checkJaxrsProviders && isAnnotationAvailable(beanName, Provider.class))
{
-                jaxrsProviders.add(applicationContext.getBean(beanName));
-            }
-        }
-
-        JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean();
-        factory.setBus(applicationContext.getBean(SpringBus.class));
-        factory.setResourceProviders(getResourceProviders());
-        factory.setProviders(getJaxrsProviders());
-        factory.setAddress(getAddress());
-        finalizeFactorySetup(factory);
-        return factory.create();
-    }
-    
-    protected <A extends Annotation> boolean isAnnotationAvailable(String beanName,
Class<A> annClass) {
-        return isBeanSupported(beanName) 
-            && applicationContext.findAnnotationOnBean(beanName, annClass) != null;
-    }
-    
-    protected void finalizeFactorySetup(JAXRSServerFactoryBean factory) {
-        // complete
-    }
-    
-    protected boolean checkJaxrsProviders() {
-        return true;    
-    }
-    
-    protected boolean checkJaxrsRoots() {
-        return true;    
-    }
-
-    protected List<ResourceProvider> getResourceProviders() {
-        return resourceProviders;
-    }
-    
-    protected List<Object> getJaxrsProviders() {
-        return jaxrsProviders;
+        return super.createJaxRsServer();
     }
     
-    public String getAddress() {
-        return address;
-    }
-
-    public void setAddress(String address) {
-        this.address = address;
-    }
-
-    public Set<String> getSupportedBeanNames() {
-        return supportedBeanNames;
-    }
-
-    public void setSupportedBeanNames(Set<String> supportedBeanNames) {
-        this.supportedBeanNames = supportedBeanNames;
-    }
-    
-    protected boolean isBeanSupported(String beanName) {
-        return supportedBeanNames == null || supportedBeanNames.contains(beanName);
-    }
 }



Mime
View raw message