You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2010/10/18 22:19:25 UTC
svn commit: r1023983 - in /cxf/branches/2.3.x-fixes: ./
api/src/main/java/org/apache/cxf/annotations/
rt/core/src/main/java/org/apache/cxf/bus/spring/
rt/core/src/main/java/org/apache/cxf/service/factory/
rt/core/src/main/java/org/apache/cxf/service/in...
Author: dkulp
Date: Mon Oct 18 20:19:25 2010
New Revision: 1023983
URL: http://svn.apache.org/viewvc?rev=1023983&view=rev
Log:
Merged revisions 1023121 via svnmerge from
https://svn.apache.org/repos/asf/cxf/trunk
........
r1023121 | dkulp | 2010-10-15 17:43:05 -0400 (Fri, 15 Oct 2010) | 2 lines
Add a FactoryType annotation to control how the service object is
constructed
........
Added:
cxf/branches/2.3.x-fixes/api/src/main/java/org/apache/cxf/annotations/FactoryType.java
- copied unchanged from r1023121, cxf/trunk/api/src/main/java/org/apache/cxf/annotations/FactoryType.java
cxf/branches/2.3.x-fixes/systests/transports/src/test/java/org/apache/cxf/systest/http/PerRequestAnnotationGreeterImpl.java
- copied unchanged from r1023121, cxf/trunk/systests/transports/src/test/java/org/apache/cxf/systest/http/PerRequestAnnotationGreeterImpl.java
cxf/branches/2.3.x-fixes/systests/transports/src/test/java/org/apache/cxf/systest/http/SessionAnnotationGreeterImpl.java
- copied unchanged from r1023121, cxf/trunk/systests/transports/src/test/java/org/apache/cxf/systest/http/SessionAnnotationGreeterImpl.java
cxf/branches/2.3.x-fixes/systests/transports/src/test/java/org/apache/cxf/systest/http/SpringAnnotationGreeterImpl.java
- copied unchanged from r1023121, cxf/trunk/systests/transports/src/test/java/org/apache/cxf/systest/http/SpringAnnotationGreeterImpl.java
cxf/branches/2.3.x-fixes/systests/transports/src/test/java/org/apache/cxf/systest/http/StatefulGreeterImpl.java
- copied unchanged from r1023121, cxf/trunk/systests/transports/src/test/java/org/apache/cxf/systest/http/StatefulGreeterImpl.java
Removed:
cxf/branches/2.3.x-fixes/systests/transports/src/test/java/org/apache/cxf/systest/http/resources/SessionServer_Windows.xml
Modified:
cxf/branches/2.3.x-fixes/ (props changed)
cxf/branches/2.3.x-fixes/rt/core/src/main/java/org/apache/cxf/bus/spring/BusExtensionPostProcessor.java
cxf/branches/2.3.x-fixes/rt/core/src/main/java/org/apache/cxf/service/factory/AnnotationsFactoryBeanListener.java
cxf/branches/2.3.x-fixes/rt/core/src/main/java/org/apache/cxf/service/invoker/FactoryInvoker.java
cxf/branches/2.3.x-fixes/rt/core/src/main/java/org/apache/cxf/service/invoker/SessionFactory.java
cxf/branches/2.3.x-fixes/rt/core/src/main/java/org/apache/cxf/service/invoker/SpringBeanFactory.java
cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPSession.java
cxf/branches/2.3.x-fixes/systests/transports/src/test/java/org/apache/cxf/systest/http/ClientServerSessionTest.java
cxf/branches/2.3.x-fixes/systests/transports/src/test/java/org/apache/cxf/systest/http/SessionServer.java
cxf/branches/2.3.x-fixes/systests/transports/src/test/java/org/apache/cxf/systest/http/resources/SessionServer.xml
Propchange: cxf/branches/2.3.x-fixes/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Mon Oct 18 20:19:25 2010
@@ -1 +1 @@
-/cxf/trunk:1-1022129,1022154,1022194,1022401-1022402,1022911,1023068,1023804
+/cxf/trunk:1-1022129,1022154,1022194,1022401-1022402,1022911,1023068,1023121,1023804
Modified: cxf/branches/2.3.x-fixes/rt/core/src/main/java/org/apache/cxf/bus/spring/BusExtensionPostProcessor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/core/src/main/java/org/apache/cxf/bus/spring/BusExtensionPostProcessor.java?rev=1023983&r1=1023982&r2=1023983&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/core/src/main/java/org/apache/cxf/bus/spring/BusExtensionPostProcessor.java (original)
+++ cxf/branches/2.3.x-fixes/rt/core/src/main/java/org/apache/cxf/bus/spring/BusExtensionPostProcessor.java Mon Oct 18 20:19:25 2010
@@ -61,6 +61,7 @@ public class BusExtensionPostProcessor i
private Bus getBus() {
if (bus == null) {
bus = (Bus)context.getBean(Bus.DEFAULT_BUS_ID);
+ bus.setExtension(context, ApplicationContext.class);
bus.setExtension(new SpringBeanLocator(context), ConfiguredBeanLocator.class);
}
return bus;
Modified: cxf/branches/2.3.x-fixes/rt/core/src/main/java/org/apache/cxf/service/factory/AnnotationsFactoryBeanListener.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/core/src/main/java/org/apache/cxf/service/factory/AnnotationsFactoryBeanListener.java?rev=1023983&r1=1023982&r2=1023983&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/core/src/main/java/org/apache/cxf/service/factory/AnnotationsFactoryBeanListener.java (original)
+++ cxf/branches/2.3.x-fixes/rt/core/src/main/java/org/apache/cxf/service/factory/AnnotationsFactoryBeanListener.java Mon Oct 18 20:19:25 2010
@@ -27,6 +27,7 @@ import org.apache.cxf.Bus;
import org.apache.cxf.annotations.DataBinding;
import org.apache.cxf.annotations.EndpointProperties;
import org.apache.cxf.annotations.EndpointProperty;
+import org.apache.cxf.annotations.FactoryType;
import org.apache.cxf.annotations.FastInfoset;
import org.apache.cxf.annotations.GZIP;
import org.apache.cxf.annotations.Logging;
@@ -46,6 +47,14 @@ import org.apache.cxf.interceptor.FIStax
import org.apache.cxf.interceptor.InterceptorProvider;
import org.apache.cxf.message.Message;
import org.apache.cxf.resource.ResourceManager;
+import org.apache.cxf.service.invoker.Factory;
+import org.apache.cxf.service.invoker.FactoryInvoker;
+import org.apache.cxf.service.invoker.Invoker;
+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;
@@ -128,6 +137,7 @@ public class AnnotationsFactoryBeanListe
addEndpointProperties(server.getEndpoint(), bus, props.value());
}
addBindingOperationDocs(server);
+ setScope(factory, server, cls);
break;
}
case INTERFACE_OPERATION_BOUND: {
@@ -148,6 +158,44 @@ public class AnnotationsFactoryBeanListe
}
}
+ private void setScope(AbstractServiceFactoryBean factory, Server server, Class<?> cls) {
+ FactoryType scope = cls.getAnnotation(FactoryType.class);
+ if (scope != null) {
+ Invoker i = server.getEndpoint().getService().getInvoker();
+ if (i instanceof FactoryInvoker) {
+ Factory f;
+ if (scope.factoryClass() == FactoryType.DEFAULT.class) {
+ switch (scope.value()) {
+ case Session:
+ f = new SessionFactory(cls);
+ break;
+ case PerRequest:
+ f = new PerRequestFactory(cls);
+ break;
+ 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)
+ .newInstance(cls, scope.args());
+ } catch (Throwable t) {
+ throw new ServiceConstructionException(t);
+ }
+ }
+ ((FactoryInvoker)i).setFactory(f);
+ }
+
+ }
+ }
+
private void addEndpointProperties(Endpoint ep, Bus bus, EndpointProperty ... annotations) {
for (EndpointProperty prop : annotations) {
if (prop == null) {
Modified: cxf/branches/2.3.x-fixes/rt/core/src/main/java/org/apache/cxf/service/invoker/FactoryInvoker.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/core/src/main/java/org/apache/cxf/service/invoker/FactoryInvoker.java?rev=1023983&r1=1023982&r2=1023983&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/core/src/main/java/org/apache/cxf/service/invoker/FactoryInvoker.java (original)
+++ cxf/branches/2.3.x-fixes/rt/core/src/main/java/org/apache/cxf/service/invoker/FactoryInvoker.java Mon Oct 18 20:19:25 2010
@@ -33,7 +33,7 @@ import org.apache.cxf.message.Exchange;
public class FactoryInvoker extends AbstractInvoker {
private static final ResourceBundle BUNDLE = BundleUtils.getBundle(FactoryInvoker.class);
- private final Factory factory;
+ private Factory factory;
/**
* Create a FactoryInvoker object.
@@ -43,6 +43,11 @@ public class FactoryInvoker extends Abst
public FactoryInvoker(Factory factory) {
this.factory = factory;
}
+ public FactoryInvoker() {
+ }
+ public void setFactory(Factory f) {
+ this.factory = f;
+ }
public Object getServiceObject(Exchange ex) {
try {
Modified: cxf/branches/2.3.x-fixes/rt/core/src/main/java/org/apache/cxf/service/invoker/SessionFactory.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/core/src/main/java/org/apache/cxf/service/invoker/SessionFactory.java?rev=1023983&r1=1023982&r2=1023983&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/core/src/main/java/org/apache/cxf/service/invoker/SessionFactory.java (original)
+++ cxf/branches/2.3.x-fixes/rt/core/src/main/java/org/apache/cxf/service/invoker/SessionFactory.java Mon Oct 18 20:19:25 2010
@@ -42,10 +42,10 @@ public class SessionFactory implements F
Service serv = e.get(Service.class);
Object o = null;
synchronized (serv) {
- o = e.getSession().get(serv.getName());
+ o = e.getSession().get(serv.getName().toString());
if (o == null) {
o = factory.create(e);
- e.getSession().put(serv.getName(), o);
+ e.getSession().put(serv.getName().toString(), o);
}
}
return o;
Modified: cxf/branches/2.3.x-fixes/rt/core/src/main/java/org/apache/cxf/service/invoker/SpringBeanFactory.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/core/src/main/java/org/apache/cxf/service/invoker/SpringBeanFactory.java?rev=1023983&r1=1023982&r2=1023983&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/core/src/main/java/org/apache/cxf/service/invoker/SpringBeanFactory.java (original)
+++ cxf/branches/2.3.x-fixes/rt/core/src/main/java/org/apache/cxf/service/invoker/SpringBeanFactory.java Mon Oct 18 20:19:25 2010
@@ -43,6 +43,9 @@ public class SpringBeanFactory implement
/** {@inheritDoc}*/
public Object create(Exchange e) throws Throwable {
+ if (ctx == null) {
+ ctx = e.getBus().getExtension(ApplicationContext.class);
+ }
return ctx.getBean(beanName);
}
Modified: cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPSession.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPSession.java?rev=1023983&r1=1023982&r2=1023983&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPSession.java (original)
+++ cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPSession.java Mon Oct 18 20:19:25 2010
@@ -39,11 +39,11 @@ public class HTTPSession implements Sess
}
public Object get(Object key) {
- return getSession().getAttribute((String)key);
+ return getSession().getAttribute(key.toString());
}
public void put(Object key, Object value) {
- getSession().setAttribute((String)key, value);
+ getSession().setAttribute(key.toString(), value);
}
public HttpSession getSession() {
Modified: cxf/branches/2.3.x-fixes/systests/transports/src/test/java/org/apache/cxf/systest/http/ClientServerSessionTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/systests/transports/src/test/java/org/apache/cxf/systest/http/ClientServerSessionTest.java?rev=1023983&r1=1023982&r2=1023983&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/systests/transports/src/test/java/org/apache/cxf/systest/http/ClientServerSessionTest.java (original)
+++ cxf/branches/2.3.x-fixes/systests/transports/src/test/java/org/apache/cxf/systest/http/ClientServerSessionTest.java Mon Oct 18 20:19:25 2010
@@ -175,4 +175,69 @@ public class ClientServerSessionTest ext
}
+ @Test
+ public void testInvocationWithSessionFactory() throws Exception {
+ doSessionsTest("http://localhost:" + PORT + "/Stateful1");
+ }
+ @Test
+ public void testInvocationWithSessionAnnotation() throws Exception {
+ doSessionsTest("http://localhost:" + PORT + "/Stateful2");
+ }
+ @Test
+ public void testInvocationWithPerRequestAnnotation() throws Exception {
+ GreeterService service = new GreeterService();
+ assertNotNull(service);
+
+ Greeter greeter = service.getGreeterPort();
+ BindingProvider bp = (BindingProvider)greeter;
+ bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
+ "http://localhost:" + PORT + "/PerRequest");
+ bp.getRequestContext().put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);
+ String result = greeter.greetMe("World");
+ assertEquals("Hello World", result);
+ assertEquals("Bonjour default", greeter.sayHi());
+ }
+ @Test
+ public void testInvocationWithSpringBeanAnnotation() throws Exception {
+ GreeterService service = new GreeterService();
+ assertNotNull(service);
+
+ Greeter greeter = service.getGreeterPort();
+ BindingProvider bp = (BindingProvider)greeter;
+ bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
+ "http://localhost:" + PORT + "/SpringBean");
+ bp.getRequestContext().put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);
+ String result = greeter.greetMe("World");
+ assertEquals("Hello World", result);
+ assertEquals("Bonjour World", greeter.sayHi());
+ }
+
+ private void doSessionsTest(String url) {
+ GreeterService service = new GreeterService();
+ assertNotNull(service);
+
+ Greeter greeter = service.getGreeterPort();
+ Greeter greeter2 = service.getGreeterPort();
+
+ BindingProvider bp = (BindingProvider)greeter;
+
+ bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
+ bp.getRequestContext().put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);
+
+ bp = (BindingProvider)greeter2;
+
+ bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
+ bp.getRequestContext().put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);
+
+ String result = greeter.greetMe("World");
+ assertEquals("Hello World", result);
+ assertEquals("Bonjour World", greeter.sayHi());
+
+ result = greeter2.greetMe("Universe");
+ assertEquals("Hello Universe", result);
+ assertEquals("Bonjour Universe", greeter2.sayHi());
+
+ //make sure session 1 was maintained
+ assertEquals("Bonjour World", greeter.sayHi());
+ }
}
Modified: cxf/branches/2.3.x-fixes/systests/transports/src/test/java/org/apache/cxf/systest/http/SessionServer.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/systests/transports/src/test/java/org/apache/cxf/systest/http/SessionServer.java?rev=1023983&r1=1023982&r2=1023983&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/systests/transports/src/test/java/org/apache/cxf/systest/http/SessionServer.java (original)
+++ cxf/branches/2.3.x-fixes/systests/transports/src/test/java/org/apache/cxf/systest/http/SessionServer.java Mon Oct 18 20:19:25 2010
@@ -21,8 +21,6 @@ package org.apache.cxf.systest.http;
import java.net.URL;
-import javax.xml.ws.Endpoint;
-
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBusFactory;
import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
@@ -32,21 +30,12 @@ public class SessionServer extends Abstr
@Override
protected void run() {
- Object implementor;
- String address;
String configurationFile = "resources/SessionServer.xml";
- if (System.getProperty("os.name").startsWith("Windows")) {
- configurationFile = "resources/SessionServer_Windows.xml";
- }
URL configure =
SessionServer.class.getResource(configurationFile);
System.out.println("the configure is " + configure);
Bus bus = new SpringBusFactory().createBus(configure, true);
SpringBusFactory.setDefaultBus(bus);
- implementor = new GreeterSessionImpl();
- address = "http://localhost:" + PORT + "/SoapContext/GreeterPort";
- Endpoint.publish(address, implementor);
-
}
public static void main(String[] args) {
Modified: cxf/branches/2.3.x-fixes/systests/transports/src/test/java/org/apache/cxf/systest/http/resources/SessionServer.xml
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/systests/transports/src/test/java/org/apache/cxf/systest/http/resources/SessionServer.xml?rev=1023983&r1=1023982&r2=1023983&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/systests/transports/src/test/java/org/apache/cxf/systest/http/resources/SessionServer.xml (original)
+++ cxf/branches/2.3.x-fixes/systests/transports/src/test/java/org/apache/cxf/systest/http/resources/SessionServer.xml Mon Oct 18 20:19:25 2010
@@ -22,7 +22,7 @@
xmlns:sec="http://cxf.apache.org/configuration/security"
xmlns:http="http://cxf.apache.org/transports/http/configuration"
xmlns:httpj="http://cxf.apache.org/transports/http-jetty/configuration"
- xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
+ xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://cxf.apache.org/configuration/security
http://cxf.apache.org/schemas/configuration/security.xsd
@@ -30,6 +30,8 @@
http://cxf.apache.org/schemas/configuration/http-conf.xsd
http://cxf.apache.org/transports/http-jetty/configuration
http://cxf.apache.org/schemas/configuration/http-jetty.xsd
+ http://cxf.apache.org/jaxws
+ http://cxf.apache.org/schemas/jaxws.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
@@ -37,6 +39,37 @@
<httpj:engine-factory bus="cxf">
<httpj:engine port="${testutil.ports.SessionServer}">
<httpj:sessionSupport>true</httpj:sessionSupport>
+ <httpj:reuseAddress>false</httpj:reuseAddress>
</httpj:engine>
- </httpj:engine-factory>
+ </httpj:engine-factory>
+
+ <jaxws:endpoint
+ address="http://localhost:${testutil.ports.SessionServer}/SoapContext/GreeterPort"
+ implementor="org.apache.cxf.systest.http.GreeterSessionImpl"/>
+
+
+ <jaxws:endpoint address="http://localhost:${testutil.ports.SessionServer}/Stateful1"
+ implementorClass="org.apache.cxf.systest.http.StatefulGreeterImpl">
+ <jaxws:invoker>
+ <bean class="org.apache.cxf.jaxws.JAXWSMethodInvoker">
+ <constructor-arg>
+ <bean class="org.apache.cxf.service.invoker.SessionFactory">
+ <constructor-arg value="org.apache.cxf.systest.http.StatefulGreeterImpl"/>
+ </bean>
+ </constructor-arg>
+ </bean>
+ </jaxws:invoker>
+ </jaxws:endpoint>
+
+ <jaxws:endpoint address="http://localhost:${testutil.ports.SessionServer}/Stateful2"
+ implementorClass="org.apache.cxf.systest.http.SessionAnnotationGreeterImpl"/>
+
+ <jaxws:endpoint address="http://localhost:${testutil.ports.SessionServer}/PerRequest"
+ implementorClass="org.apache.cxf.systest.http.PerRequestAnnotationGreeterImpl"/>
+
+ <bean id="SpringBean" class="org.apache.cxf.systest.http.SpringAnnotationGreeterImpl"/>
+
+ <jaxws:endpoint address="http://localhost:${testutil.ports.SessionServer}/SpringBean"
+ implementorClass="org.apache.cxf.systest.http.SpringAnnotationGreeterImpl"/>
+
</beans>
\ No newline at end of file