Repository: cxf Updated Branches: refs/heads/split-spring fc2cbb290 -> a2d74c9ad
Move SpringBeanFactory Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/a2d74c9a Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/a2d74c9a Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/a2d74c9a Branch: refs/heads/split-spring Commit: a2d74c9ad15dbaa0ed0a192d8b80b35e92473dce Parents: fc2cbb2 Author: Daniel Kulp <[email protected]> Authored: Thu May 1 12:57:53 2014 -0400 Committer: Daniel Kulp <[email protected]> Committed: Thu May 1 12:57:53 2014 -0400 ---------------------------------------------------------------------- core/pom.xml | 5 -- .../org/apache/cxf/annotations/FactoryType.java | 14 ++++- .../factory/AnnotationsFactoryBeanListener.java | 6 +- .../cxf/service/invoker/SpringBeanFactory.java | 61 ------------------ .../invoker/spring/SpringBeanFactory.java | 65 ++++++++++++++++++++ .../http/SpringAnnotationGreeterImpl.java | 4 +- 6 files changed, 79 insertions(+), 76 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/a2d74c9a/core/pom.xml ---------------------------------------------------------------------- diff --git a/core/pom.xml b/core/pom.xml index 566b240..61a1231 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -135,11 +135,6 @@ </dependency> <dependency> <groupId>org.springframework</groupId> - <artifactId>spring-context</artifactId> - <optional>true</optional> - </dependency> - <dependency> - <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> <scope>provided</scope> <optional>true</optional> http://git-wip-us.apache.org/repos/asf/cxf/blob/a2d74c9a/core/src/main/java/org/apache/cxf/annotations/FactoryType.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/cxf/annotations/FactoryType.java b/core/src/main/java/org/apache/cxf/annotations/FactoryType.java index e9a83b7..50e4436 100644 --- a/core/src/main/java/org/apache/cxf/annotations/FactoryType.java +++ b/core/src/main/java/org/apache/cxf/annotations/FactoryType.java @@ -24,6 +24,9 @@ import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; + +import org.apache.cxf.message.Exchange; +import org.apache.cxf.service.invoker.Factory; /** * Defines the factory used for the service. * @@ -45,16 +48,21 @@ public @interface FactoryType { * 1) The Class for the service * 2) String[] of the args from above */ - Class<?> factoryClass() default DEFAULT.class; + Class<? extends Factory> factoryClass() default DEFAULT.class; enum Type { Singleton, Session, Pooled, //args[0] is the size of the pool PerRequest, - Spring, //args[0] is the Spring bean name }; - static final class DEFAULT { } + static final class DEFAULT implements Factory { + public Object create(Exchange e) throws Throwable { + return null; + } + public void release(Exchange e, Object o) { + } + } } http://git-wip-us.apache.org/repos/asf/cxf/blob/a2d74c9a/core/src/main/java/org/apache/cxf/service/factory/AnnotationsFactoryBeanListener.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/cxf/service/factory/AnnotationsFactoryBeanListener.java b/core/src/main/java/org/apache/cxf/service/factory/AnnotationsFactoryBeanListener.java index 655eb68..05ee510 100644 --- a/core/src/main/java/org/apache/cxf/service/factory/AnnotationsFactoryBeanListener.java +++ b/core/src/main/java/org/apache/cxf/service/factory/AnnotationsFactoryBeanListener.java @@ -53,7 +53,6 @@ import org.apache.cxf.service.invoker.PerRequestFactory; import org.apache.cxf.service.invoker.PooledFactory; import org.apache.cxf.service.invoker.SessionFactory; import org.apache.cxf.service.invoker.SingletonFactory; -import org.apache.cxf.service.invoker.SpringBeanFactory; import org.apache.cxf.service.model.BindingFaultInfo; import org.apache.cxf.service.model.BindingOperationInfo; import org.apache.cxf.service.model.FaultInfo; @@ -190,16 +189,13 @@ public class AnnotationsFactoryBeanListener implements FactoryBeanListener { case Pooled: f = new PooledFactory(cls, Integer.parseInt(scope.args()[0])); break; - case Spring: - f = new SpringBeanFactory(scope.args()[0]); - break; default: f = new SingletonFactory(cls); break; } } else { try { - f = (Factory)scope.factoryClass().getConstructor(Class.class, String[].class) + f = scope.factoryClass().getConstructor(Class.class, String[].class) .newInstance(cls, scope.args()); } catch (Throwable t) { throw new ServiceConstructionException(t); http://git-wip-us.apache.org/repos/asf/cxf/blob/a2d74c9a/core/src/main/java/org/apache/cxf/service/invoker/SpringBeanFactory.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/cxf/service/invoker/SpringBeanFactory.java b/core/src/main/java/org/apache/cxf/service/invoker/SpringBeanFactory.java deleted file mode 100644 index f942019..0000000 --- a/core/src/main/java/org/apache/cxf/service/invoker/SpringBeanFactory.java +++ /dev/null @@ -1,61 +0,0 @@ -/** - * 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.service.invoker; - -import org.apache.cxf.message.Exchange; -import org.springframework.beans.BeansException; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationContextAware; - -/** - * Factory that will query the Spring ApplicationContext for the - * appropriate bean for each request. - * - * This can be expensive. If the bean is "prototype" or similar such that a - * new instance is created each time, this could slow things down. In that - * case, it's recommended to use this in conjunction with the PooledFactory - * to pool the beans or the SessionFactory or similar. - */ -public class SpringBeanFactory implements Factory, ApplicationContextAware { - ApplicationContext ctx; - String beanName; - - public SpringBeanFactory(String name) { - beanName = name; - } - - /** {@inheritDoc}*/ - public Object create(Exchange e) throws Throwable { - if (ctx == null) { - ctx = e.getBus().getExtension(ApplicationContext.class); - } - return ctx.getBean(beanName); - } - - /** {@inheritDoc}*/ - public void release(Exchange e, Object o) { - //nothing - } - - public void setApplicationContext(ApplicationContext arg0) throws BeansException { - ctx = arg0; - } - -} http://git-wip-us.apache.org/repos/asf/cxf/blob/a2d74c9a/rt/spring/src/main/java/org/apache/cxf/service/invoker/spring/SpringBeanFactory.java ---------------------------------------------------------------------- diff --git a/rt/spring/src/main/java/org/apache/cxf/service/invoker/spring/SpringBeanFactory.java b/rt/spring/src/main/java/org/apache/cxf/service/invoker/spring/SpringBeanFactory.java new file mode 100644 index 0000000..74e7182 --- /dev/null +++ b/rt/spring/src/main/java/org/apache/cxf/service/invoker/spring/SpringBeanFactory.java @@ -0,0 +1,65 @@ +/** + * 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.service.invoker.spring; + +import org.apache.cxf.message.Exchange; +import org.apache.cxf.service.invoker.Factory; +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; + +/** + * Factory that will query the Spring ApplicationContext for the + * appropriate bean for each request. + * + * This can be expensive. If the bean is "prototype" or similar such that a + * new instance is created each time, this could slow things down. In that + * case, it's recommended to use this in conjunction with the PooledFactory + * to pool the beans or the SessionFactory or similar. + */ +public class SpringBeanFactory implements Factory, ApplicationContextAware { + volatile ApplicationContext ctx; + final String beanName; + + public SpringBeanFactory(String name) { + beanName = name; + } + public SpringBeanFactory(Class<?> cls, String args[]) { + beanName = args[0]; + } + + /** {@inheritDoc}*/ + public Object create(Exchange e) throws Throwable { + if (ctx == null) { + ctx = e.getBus().getExtension(ApplicationContext.class); + } + return ctx.getBean(beanName); + } + + /** {@inheritDoc}*/ + public void release(Exchange e, Object o) { + //nothing + } + + public void setApplicationContext(ApplicationContext arg0) throws BeansException { + ctx = arg0; + } + +} http://git-wip-us.apache.org/repos/asf/cxf/blob/a2d74c9a/systests/transports/src/test/java/org/apache/cxf/systest/http/SpringAnnotationGreeterImpl.java ---------------------------------------------------------------------- diff --git a/systests/transports/src/test/java/org/apache/cxf/systest/http/SpringAnnotationGreeterImpl.java b/systests/transports/src/test/java/org/apache/cxf/systest/http/SpringAnnotationGreeterImpl.java index c9a9b8b..c7265e7 100644 --- a/systests/transports/src/test/java/org/apache/cxf/systest/http/SpringAnnotationGreeterImpl.java +++ b/systests/transports/src/test/java/org/apache/cxf/systest/http/SpringAnnotationGreeterImpl.java @@ -24,18 +24,18 @@ import javax.jws.WebService; import javax.xml.ws.AsyncHandler; import javax.xml.ws.Response; - import org.apache.cxf.annotations.FactoryType; import org.apache.cxf.greeter_control.Greeter; import org.apache.cxf.greeter_control.types.GreetMeResponse; import org.apache.cxf.greeter_control.types.PingMeResponse; import org.apache.cxf.greeter_control.types.SayHiResponse; +import org.apache.cxf.service.invoker.spring.SpringBeanFactory; @WebService(serviceName = "GreeterService", portName = "GreeterPort", endpointInterface = "org.apache.cxf.greeter_control.Greeter", targetNamespace = "http://cxf.apache.org/greeter_control") -@FactoryType(value = FactoryType.Type.Spring, args = { "SpringBean" }) +@FactoryType(factoryClass = SpringBeanFactory.class, args = { "SpringBean" }) public class SpringAnnotationGreeterImpl implements Greeter { String name;
