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/10 15:37:35 UTC
svn commit: r1549849 - in
/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring:
JaxRsConfig.java SpringResourceServer.java
Author: sergeyb
Date: Tue Dec 10 14:37:35 2013
New Revision: 1549849
URL: http://svn.apache.org/r1549849
Log:
Externalizing Configuration resource as per example in CXF-5448, few other changes
Added:
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/JaxRsConfig.java (with props)
Modified:
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/JaxRsConfig.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/JaxRsConfig.java?rev=1549849&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/JaxRsConfig.java (added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/JaxRsConfig.java Tue Dec 10 14:37:35 2013
@@ -0,0 +1,27 @@
+/**
+ * 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 org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.ImportResource;
+
+@Configuration
+@ImportResource({"classpath:META-INF/cxf/cxf.xml" })
+public class JaxRsConfig {
+}
Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/JaxRsConfig.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/JaxRsConfig.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: 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=1549849&r1=1549848&r2=1549849&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/SpringResourceServer.java Tue Dec 10 14:37:35 2013
@@ -34,41 +34,38 @@ import org.springframework.beans.factory
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;
+import org.springframework.context.annotation.Import;
-@Configuration
+@Import(JaxRsConfig.class)
@ComponentScan
-@ImportResource({"classpath:META-INF/cxf/cxf.xml" })
public class SpringResourceServer {
@Autowired
- private ApplicationContext ctx;
+ protected ApplicationContext applicationContext;
private String address = "/";
private Set<String> supportedBeanNames;
+ private List<ResourceProvider> resourceProviders = new LinkedList<ResourceProvider>();
+ private List<Object> jaxrsProviders = new LinkedList<Object>();
@Bean
- public Server jaxrsServer() {
- List<ResourceProvider> resourceProviders = new LinkedList<ResourceProvider>();
- List<Object> jaxrsProviders = new LinkedList<Object>();
-
+ public Server jaxRsServer() {
boolean checkJaxrsRoots = checkJaxrsRoots();
boolean checkJaxrsProviders = checkJaxrsProviders();
- for (String beanName : ctx.getBeanDefinitionNames()) {
+ for (String beanName : applicationContext.getBeanDefinitionNames()) {
if (checkJaxrsRoots && isAnnotationAvailable(beanName, Path.class)) {
SpringResourceFactory factory = new SpringResourceFactory(beanName);
- factory.setApplicationContext(ctx);
+ factory.setApplicationContext(applicationContext);
resourceProviders.add(factory);
} else if (checkJaxrsProviders && isAnnotationAvailable(beanName, Provider.class)) {
- jaxrsProviders.add(ctx.getBean(beanName));
+ jaxrsProviders.add(applicationContext.getBean(beanName));
}
}
JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean();
- factory.setBus(ctx.getBean(SpringBus.class));
- factory.setResourceProviders(resourceProviders);
- factory.setProviders(jaxrsProviders);
+ factory.setBus(applicationContext.getBean(SpringBus.class));
+ factory.setResourceProviders(getResourceProviders());
+ factory.setProviders(getJaxrsProviders());
factory.setAddress(getAddress());
finalizeFactorySetup(factory);
return factory.create();
@@ -76,7 +73,7 @@ public class SpringResourceServer {
protected <A extends Annotation> boolean isAnnotationAvailable(String beanName, Class<A> annClass) {
return isBeanSupported(beanName)
- && ctx.findAnnotationOnBean(beanName, annClass) != null;
+ && applicationContext.findAnnotationOnBean(beanName, annClass) != null;
}
protected void finalizeFactorySetup(JAXRSServerFactoryBean factory) {
@@ -91,6 +88,14 @@ public class SpringResourceServer {
return true;
}
+ protected List<ResourceProvider> getResourceProviders() {
+ return resourceProviders;
+ }
+
+ protected List<Object> getJaxrsProviders() {
+ return jaxrsProviders;
+ }
+
public String getAddress() {
return address;
}