[jbossws-commits] JBossWS SVN: r12760 - in stack/cxf/trunk/modules: testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf and 1 other directories.
jbossws-commits at lists.jboss.org
jbossws-commits at lists.jboss.org
Sat Aug 7 21:32:36 EDT 2010
Author: alessio.soldano at jboss.com
Date: 2010-08-07 21:32:36 -0400 (Sat, 07 Aug 2010)
New Revision: 12760
Added:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/jbws3098/
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/jbws3098/BusHolderLifeCycleTestCase.java
Modified:
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/configuration/BusHolder.java
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/configuration/NonSpringBusHolder.java
Log:
[JBWS-3098] Ensure bus shutdown at undeployment
Modified: stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/configuration/BusHolder.java
===================================================================
--- stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/configuration/BusHolder.java 2010-08-07 23:21:50 UTC (rev 12759)
+++ stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/configuration/BusHolder.java 2010-08-08 01:32:36 UTC (rev 12760)
@@ -25,6 +25,8 @@
import org.apache.cxf.Bus;
import org.apache.cxf.binding.soap.SoapTransportFactory;
+import org.apache.cxf.buslifecycle.BusLifeCycleListener;
+import org.apache.cxf.buslifecycle.BusLifeCycleManager;
import org.apache.cxf.configuration.Configurer;
import org.apache.cxf.resource.ResourceManager;
import org.apache.cxf.resource.ResourceResolver;
@@ -47,6 +49,7 @@
{
public static final String PARAM_CXF_BEANS_URL = "jbossws.cxf.beans.url";
protected Bus bus;
+ protected BusHolderLifeCycleListener busHolderListener;
public BusHolder()
{
@@ -68,6 +71,9 @@
*/
public void configure(SoapTransportFactory soapTransportFactory, ResourceResolver resolver, Configurer configurer)
{
+ busHolderListener = new BusHolderLifeCycleListener();
+ bus.getExtension(BusLifeCycleManager.class).registerLifeCycleListener(busHolderListener);
+
if (configurer != null)
{
bus.setExtension(configurer, Configurer.class);
@@ -84,7 +90,12 @@
*/
public void close()
{
-
+ //call bus shutdown unless the listener tells us shutdown has already been asked
+ if (busHolderListener != null && !busHolderListener.isPreShutdown())
+ {
+ bus.shutdown(true);
+ }
+ busHolderListener = null;
}
/**
@@ -143,4 +154,32 @@
{
this.bus = bus;
}
+
+ private class BusHolderLifeCycleListener implements BusLifeCycleListener
+ {
+ private volatile boolean preShutdown = false;
+
+ public boolean isPreShutdown()
+ {
+ return preShutdown;
+ }
+
+ @Override
+ public void initComplete()
+ {
+ //NOOP
+ }
+
+ @Override
+ public void preShutdown()
+ {
+ preShutdown = true;
+ }
+
+ @Override
+ public void postShutdown()
+ {
+ //NOOP
+ }
+ }
}
Modified: stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/configuration/NonSpringBusHolder.java
===================================================================
--- stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/configuration/NonSpringBusHolder.java 2010-08-07 23:21:50 UTC (rev 12759)
+++ stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/configuration/NonSpringBusHolder.java 2010-08-08 01:32:36 UTC (rev 12760)
@@ -122,10 +122,13 @@
for (EndpointImpl endpoint : endpoints)
{
- endpoint.stop();
+ if (endpoint.isPublished())
+ {
+ endpoint.stop();
+ }
}
endpoints.clear();
- bus.shutdown(true);
+
super.close();
}
Added: stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/jbws3098/BusHolderLifeCycleTestCase.java
===================================================================
--- stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/jbws3098/BusHolderLifeCycleTestCase.java (rev 0)
+++ stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/jbws3098/BusHolderLifeCycleTestCase.java 2010-08-08 01:32:36 UTC (rev 12760)
@@ -0,0 +1,123 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.ws.jaxws.cxf.jbws3098;
+
+import java.net.URL;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.buslifecycle.BusLifeCycleListener;
+import org.apache.cxf.buslifecycle.BusLifeCycleManager;
+import org.jboss.wsf.stack.cxf.client.util.SpringUtils;
+import org.jboss.wsf.stack.cxf.configuration.BusHolder;
+import org.jboss.wsf.stack.cxf.configuration.NonSpringBusHolder;
+import org.jboss.wsf.stack.cxf.configuration.SpringBusHolder;
+import org.jboss.wsf.stack.cxf.metadata.services.DDBeans;
+import org.jboss.wsf.test.JBossWSTest;
+
+/**
+ * Verifies the Bus is properly shutdown when created through the BusHolder
+ *
+ * @author alessio.soldano at jboss.com
+ * @since 08-Aug-2010
+ *
+ */
+public class BusHolderLifeCycleTestCase extends JBossWSTest
+{
+ public void testBusShutdown()
+ {
+ if (SpringUtils.isSpringAvailable(Thread.currentThread().getContextClassLoader()))
+ {
+ simpleShutdownTest(new SpringBusHolder(null, new URL[]{}));
+ shutdownTestWithInnerShutdown(new SpringBusHolder(null, new URL[]{}));
+ shutdownTestWithNoShutdown(new SpringBusHolder(null, new URL[]{}));
+ }
+ else
+ {
+ simpleShutdownTest(new NonSpringBusHolder(new DDBeans()));
+ shutdownTestWithInnerShutdown(new NonSpringBusHolder(new DDBeans()));
+ shutdownTestWithNoShutdown(new NonSpringBusHolder(new DDBeans()));
+ }
+ }
+
+ private static void simpleShutdownTest(BusHolder holder)
+ {
+ Bus bus = holder.getBus();
+ TestLifeCycleListener listener = new TestLifeCycleListener();
+ bus.getExtension(BusLifeCycleManager.class).registerLifeCycleListener(listener);
+ holder.configure(null, null, null);
+ holder.close();
+ assertEquals("preShutdown method on listener should be called exactly once; number of actual calls: "
+ + listener.getCount(), 1, listener.getCount());
+ }
+
+ private static void shutdownTestWithInnerShutdown(BusHolder holder)
+ {
+ Bus bus = holder.getBus();
+ TestLifeCycleListener listener = new TestLifeCycleListener();
+ bus.getExtension(BusLifeCycleManager.class).registerLifeCycleListener(listener);
+ holder.configure(null, null, null);
+ bus.shutdown(true);
+ holder.close();
+ assertEquals("preShutdown method on listener should be called exactly once; number of actual calls: "
+ + listener.getCount(), 1, listener.getCount());
+ }
+
+ private static void shutdownTestWithNoShutdown(BusHolder holder)
+ {
+ Bus bus = holder.getBus();
+ TestLifeCycleListener listener = new TestLifeCycleListener();
+ bus.getExtension(BusLifeCycleManager.class).registerLifeCycleListener(listener);
+ holder.configure(null, null, null);
+ assertEquals("preShutdown method on listener shouldn't be called before holder is closed: number of actual calls: "
+ + listener.getCount(), 0, listener.getCount());
+ holder.close();
+ }
+
+ private static class TestLifeCycleListener implements BusLifeCycleListener
+ {
+ private volatile int count = 0;
+
+ public int getCount()
+ {
+ return count;
+ }
+
+ @Override
+ public void initComplete()
+ {
+ //NOOP
+ }
+
+ @Override
+ public void preShutdown()
+ {
+ count++;
+ }
+
+ @Override
+ public void postShutdown()
+ {
+ //NOOP
+ }
+
+ }
+}
More information about the jbossws-commits
mailing list