You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2013/12/06 14:02:58 UTC

svn commit: r1548504 - /cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/SpringResourceServer.java

Author: sergeyb
Date: Fri Dec  6 13:02:57 2013
New Revision: 1548504

URL: http://svn.apache.org/r1548504
Log:
[CXF-3725] Adding utility SpringResourceServer based on the code fragment provided by Vladimir Kulev

Added:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/SpringResourceServer.java   (with props)

Added: 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/SpringResourceServer.java?rev=1548504&view=auto
==============================================================================
--- 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/SpringResourceServer.java Fri Dec  6 13:02:57 2013
@@ -0,0 +1,81 @@
+/**
+ * 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.LinkedList;
+import java.util.List;
+
+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.Configuration;
+import org.springframework.context.annotation.ImportResource;
+
+@Configuration
+@ComponentScan
+@ImportResource({"classpath:META-INF/cxf/cxf.xml" })
+public class SpringResourceServer {
+    @Autowired
+    private ApplicationContext ctx;
+
+    private String address = "/";
+    
+    @Bean
+    public Server create() {
+        List<ResourceProvider> resourceProviders = new LinkedList<ResourceProvider>();
+        List<Object> jaxrsProviders = new LinkedList<Object>();
+        
+        for (String beanName : ctx.getBeanDefinitionNames()) {
+            if (ctx.findAnnotationOnBean(beanName, Path.class) != null) {
+                SpringResourceFactory factory = new SpringResourceFactory(beanName);
+                factory.setApplicationContext(ctx);
+                resourceProviders.add(factory);
+            } else if (checkJaxrsProviders() && ctx.findAnnotationOnBean(beanName, Provider.class) != null) {
+                jaxrsProviders.add(ctx.getBean(beanName));
+            }
+        }
+
+        JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean();
+        factory.setBus(ctx.getBean(SpringBus.class));
+        factory.setResourceProviders(resourceProviders);
+        factory.setProviders(jaxrsProviders);
+        factory.setAddress(getAddress());
+        return factory.create();
+    }
+    
+    protected boolean checkJaxrsProviders() {
+        return true;    
+    }
+
+    public String getAddress() {
+        return address;
+    }
+
+    public void setAddress(String address) {
+        this.address = address;
+    }
+}

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

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