Author: eglynn
Date: Tue May 22 08:56:24 2007
New Revision: 540619
URL: http://svn.apache.org/viewvc?view=rev&rev=540619
Log:
Propagating active features to endpoint created upfront in
ReflectionServiceFactoryBean.create()
Modified:
incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/AbstractEndpointFactory.java
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/clustering/Server.java
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/lifecycle/LifeCycleTest.java
Modified:
incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/AbstractEndpointFactory.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/AbstractEndpointFactory.java?view=diff&rev=540619&r1=540618&r2=540619
==============================================================================
---
incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/AbstractEndpointFactory.java
(original)
+++
incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/AbstractEndpointFactory.java
Tue May 22 08:56:24 2007
@@ -116,6 +116,10 @@
if (ep == null) {
ep = serviceFactory.createEndpoint(ei);
((EndpointImpl)ep).initializeActiveFeatures(getFeatures());
+ } else {
+ if (ep.getActiveFeatures() == null) {
+ ((EndpointImpl)ep).initializeActiveFeatures(getFeatures());
+ }
}
if (properties != null) {
Modified:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/clustering/Server.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/clustering/Server.java?view=diff&rev=540619&r1=540618&r2=540619
==============================================================================
---
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/clustering/Server.java
(original)
+++
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/clustering/Server.java
Tue May 22 08:56:24 2007
@@ -20,20 +20,12 @@
package org.apache.cxf.systest.clustering;
-import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
import javax.xml.ws.Endpoint;
import org.apache.cxf.Bus;
import org.apache.cxf.BusFactory;
import org.apache.cxf.bus.spring.SpringBusFactory;
-import org.apache.cxf.endpoint.ServerLifeCycleListener;
-import org.apache.cxf.endpoint.ServerLifeCycleManager;
-import org.apache.cxf.feature.AbstractFeature;
import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
-import org.apache.cxf.ws.addressing.WSAddressingFeature;
public class Server extends AbstractBusTestServerBase {
@@ -42,9 +34,6 @@
private static final String TARGETS_CONFIG =
"org/apache/cxf/systest/clustering/targets.xml";
-
- private String verified;
-
protected void run() {
SpringBusFactory factory = new SpringBusFactory();
@@ -52,43 +41,6 @@
BusFactory.setDefaultBus(bus);
setBus(bus);
- ServerLifeCycleManager manager =
- bus.getExtension(ServerLifeCycleManager.class);
- if (manager != null) {
- manager.registerListener(new ServerLifeCycleListener() {
- public void startServer(org.apache.cxf.endpoint.Server server)
{
- org.apache.cxf.endpoint.Endpoint endpoint
- = server.getEndpoint();
- String portName =
- endpoint.getEndpointInfo().getName().getLocalPart();
- if ("ReplicatedPortA".equals(portName)) {
-
- List<AbstractFeature> active =
endpoint.getActiveFeatures();
- if (!(active.size() == 1
- && active.get(0) instanceof WSAddressingFeature)
- && AbstractFeature.getActive(active,
-
WSAddressingFeature.class)
- == active.get(0)) {
- verified = "unexpected active features: " + active;
- }
- } else {
- List<AbstractFeature> active =
endpoint.getActiveFeatures();
- if (!(active == null
- || active.size() == 0
- || AbstractFeature.getActive(active,
-
WSAddressingFeature.class)
- == null)) {
- verified = "unexpected active features: " + active;
- }
- }
- }
- public void stopServer(org.apache.cxf.endpoint.Server server) {
- }
- });
- } else {
- verified = "cannot access ServerLifeCycleManager";
- }
-
ControlImpl implementor = new ControlImpl();
Endpoint.publish(ADDRESS, implementor);
}
@@ -103,20 +55,5 @@
} finally {
System.out.println("done!");
}
- }
-
- /**
- * Used to facilitate assertions on server-side behaviour.
- *
- * @param log logger to use for diagnostics if assertions fail
- * @return true if assertions hold
- */
- protected boolean verify(Logger log) {
- if (verified != null) {
- log.log(Level.WARNING,
- "Active Feature verification failed: {0}",
- verified);
- }
- return verified == null;
}
}
Modified:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/lifecycle/LifeCycleTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/lifecycle/LifeCycleTest.java?view=diff&rev=540619&r1=540618&r2=540619
==============================================================================
---
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/lifecycle/LifeCycleTest.java
(original)
+++
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/lifecycle/LifeCycleTest.java
Tue May 22 08:56:24 2007
@@ -20,16 +20,21 @@
package org.apache.cxf.systest.lifecycle;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import javax.xml.ws.Endpoint;
import org.apache.cxf.Bus;
import org.apache.cxf.BusFactory;
+import org.apache.cxf.bus.spring.SpringBusFactory;
import org.apache.cxf.endpoint.Server;
import org.apache.cxf.endpoint.ServerLifeCycleListener;
import org.apache.cxf.endpoint.ServerLifeCycleManager;
+import org.apache.cxf.feature.AbstractFeature;
+import org.apache.cxf.greeter_control.ControlImpl;
import org.apache.cxf.systest.ws.addressing.GreeterImpl;
+import org.apache.cxf.ws.addressing.WSAddressingFeature;
import org.junit.After;
import org.junit.Assert;
@@ -43,6 +48,8 @@
"http://localhost:9057/SoapContext/SoapPort",
"http://localhost:9058/SoapContext/SoapPort",
"http://localhost:9059/SoapContext/SoapPort"};
+ private static final String CONFIG =
+ "org/apache/cxf/systest/lifecycle/cxf.xml";
private Bus bus;
private ServerLifeCycleManager manager;
@@ -53,7 +60,9 @@
@Before
public void setUp() throws Exception {
- bus = BusFactory.getDefaultBus();
+ SpringBusFactory bf = new SpringBusFactory();
+ bus = bf.createBus(CONFIG);
+ BusFactory.setDefaultBus(bus);
manager = bus.getExtension(ServerLifeCycleManager.class);
recursiveCount = 0;
recursiveEndpoints = new Endpoint[RECURSIVE_LIMIT];
@@ -72,8 +81,10 @@
manager.registerListener(new ServerLifeCycleListener() {
public void startServer(Server server) {
- verifyNoPrior(startNotificationMap,
-
server.getEndpoint().getEndpointInfo().getAddress());
+ String address =
+ server.getEndpoint().getEndpointInfo().getAddress();
+ verifyNotification(startNotificationMap, address, 0);
+ updateMap(startNotificationMap, address);
if (recursiveCount < RECURSIVE_LIMIT) {
recursiveEndpoints[recursiveCount++] =
Endpoint.publish(ADDRESSES[recursiveCount],
@@ -81,8 +92,10 @@
}
}
public void stopServer(Server server) {
- verifyNoPrior(stopNotificationMap,
-
server.getEndpoint().getEndpointInfo().getAddress());
+ String address =
+ server.getEndpoint().getEndpointInfo().getAddress();
+ verifyNotification(stopNotificationMap, address, 0);
+ updateMap(stopNotificationMap, address);
if (recursiveCount > 0) {
recursiveEndpoints[--recursiveCount].stop();
}
@@ -90,12 +103,82 @@
});
Endpoint.publish(ADDRESSES[0], new GreeterImpl()).stop();
+ for (int i = 0; i < ADDRESSES.length; i++) {
+ verifyNotification(startNotificationMap, ADDRESSES[i], 1);
+ verifyNotification(stopNotificationMap, ADDRESSES[i], 1);
+ }
}
- private void verifyNoPrior(Map<String, Integer> notificationMap, String
address) {
+ @Test
+ public void testGetActiveFeatures() {
+ assertNotNull("unexpected non-null ServerLifeCycleManager", manager);
+
+ manager.registerListener(new ServerLifeCycleListener() {
+ public void startServer(Server server) {
+ org.apache.cxf.endpoint.Endpoint endpoint
+ = server.getEndpoint();
+ updateMap(startNotificationMap,
+ endpoint.getEndpointInfo().getAddress());
+ String portName =
+ endpoint.getEndpointInfo().getName().getLocalPart();
+ if ("SoapPort".equals(portName)) {
+
+ List<AbstractFeature> active =
endpoint.getActiveFeatures();
+ assertNotNull(active);
+ assertEquals(1, active.size());
+ assertTrue(active.get(0) instanceof WSAddressingFeature);
+ assertSame(active.get(0),
+ AbstractFeature.getActive(active,
+
WSAddressingFeature.class));
+ } else {
+ List<AbstractFeature> active =
endpoint.getActiveFeatures();
+ assertNotNull(active);
+ assertEquals(0, active.size());
+ assertNull(AbstractFeature.getActive(active,
+
WSAddressingFeature.class));
+ }
+ }
+ public void stopServer(Server server) {
+ updateMap(stopNotificationMap,
+ server.getEndpoint().getEndpointInfo().getAddress());
+ }
+ });
+
+ Endpoint greeter = Endpoint.publish(ADDRESSES[0], new GreeterImpl());
+ Endpoint control = Endpoint.publish(ADDRESSES[1], new ControlImpl());
+ greeter.stop();
+ control.stop();
+ for (int i = 0; i < 2; i++) {
+ verifyNotification(startNotificationMap, ADDRESSES[0], 1);
+ verifyNotification(stopNotificationMap, ADDRESSES[0], 1);
+ }
+ }
+
+ private void verifyNotification(Map<String, Integer> notificationMap,
+ String address,
+ int expected) {
synchronized (notificationMap) {
- assertFalse("unexpected prior notification for: " + address,
- notificationMap.containsKey(address));
+ Integer count = notificationMap.get(address);
+ if (expected == 0) {
+ assertNull("unexpected prior notification for: " + address,
count);
+ } else {
+ assertEquals("unexpected prior notification for: " + address,
+ expected,
+ count.intValue());
+ }
+ }
+ }
+
+ private void updateMap(Map<String, Integer> notificationMap, String
address) {
+ synchronized (notificationMap) {
+ Integer count = notificationMap.get(address);
+ if (count != null) {
+ notificationMap.put(address,
+ new Integer(count.intValue() + 1));
+ } else {
+ notificationMap.put(address,
+ new Integer(1));
+ }
}
}