cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r1357455 - in /cxf/trunk: api/src/main/java/org/apache/cxf/endpoint/ systests/transports/src/test/java/org/apache/cxf/systest/servlet/
Date Thu, 05 Jul 2012 03:30:33 GMT
Author: ningjiang
Date: Thu Jul  5 03:30:32 2012
New Revision: 1357455

URL: http://svn.apache.org/viewvc?rev=1357455&view=rev
Log:
CXF-4407 Fix the issue of Server.start()

Modified:
    cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/ServerImpl.java
    cxf/trunk/systests/transports/src/test/java/org/apache/cxf/systest/servlet/NoSpringServletClientTest.java
    cxf/trunk/systests/transports/src/test/java/org/apache/cxf/systest/servlet/NoSpringServletServer.java

Modified: cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/ServerImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/ServerImpl.java?rev=1357455&r1=1357454&r2=1357455&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/ServerImpl.java (original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/ServerImpl.java Thu Jul  5 03:30:32
2012
@@ -173,13 +173,14 @@ public class ServerImpl implements Serve
                 return;
             }
         }
-        getDestination().shutdown();
         getDestination().setMessageObserver(null);
         stopped = true;
     }
     
     public void destroy() {
         stop();
+        // we should shutdown the destination here
+        getDestination().shutdown();
 
         if (null != serverRegistry) {
             LOG.fine("unregister the server to serverRegistry ");

Modified: cxf/trunk/systests/transports/src/test/java/org/apache/cxf/systest/servlet/NoSpringServletClientTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/transports/src/test/java/org/apache/cxf/systest/servlet/NoSpringServletClientTest.java?rev=1357455&r1=1357454&r2=1357455&view=diff
==============================================================================
--- cxf/trunk/systests/transports/src/test/java/org/apache/cxf/systest/servlet/NoSpringServletClientTest.java
(original)
+++ cxf/trunk/systests/transports/src/test/java/org/apache/cxf/systest/servlet/NoSpringServletClientTest.java
Thu Jul  5 03:30:32 2012
@@ -21,6 +21,7 @@ package org.apache.cxf.systest.servlet;
 import java.lang.reflect.UndeclaredThrowableException;
 import java.net.URL;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
 
 import javax.xml.namespace.QName;
@@ -29,10 +30,15 @@ import com.meterware.httpunit.WebConvers
 import com.meterware.httpunit.WebLink;
 import com.meterware.httpunit.WebResponse;
 
+import org.apache.cxf.Bus;
+import org.apache.cxf.endpoint.Server;
+import org.apache.cxf.endpoint.ServerRegistry;
 import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
 import org.apache.hello_world_soap_http.Greeter;
 import org.apache.hello_world_soap_http.SOAPService;
+
+import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
@@ -40,14 +46,24 @@ import org.junit.Test;
 
 public class NoSpringServletClientTest extends AbstractBusClientServerTestBase {
     private static final String PORT = NoSpringServletServer.PORT;
-    
+    private static Bus serverBus;
+    private static NoSpringServletServer server;
     private final QName portName = new QName("http://apache.org/hello_world_soap_http", "SoapPort");
     private final String serviceURL = "http://localhost:" + PORT + "/soap/";
     @BeforeClass
     public static void startServers() throws Exception {
-        assertTrue("server did not launch correctly", launchServer(NoSpringServletServer.class));
+        server = new NoSpringServletServer();
+        server.run();
+        serverBus = server.getBus();
         createStaticBus();
     }
+    
+    @AfterClass
+    public static void shutdownServer() throws Exception {
+        if (server != null) {
+            server.tearDown();
+        }
+    }
 
     @Test
     public void testBasicConnection() throws Exception {
@@ -75,6 +91,37 @@ public class NoSpringServletClientTest e
         String reply = hello.sayHi(" Willem");
         assertEquals("Get the wrongreply ", reply, "get Willem");
     }
+    
+    @Test
+    public void testStartAndStopServer() throws Exception {
+        stopServer();
+        // we should not invoke the server this time
+        try {
+            testHelloService();
+            fail("Expect Exception here.");
+        } catch (Exception ex) {
+            // do nothing here
+        }
+        startServer();
+        testHelloService();
+    }
+    
+    private void stopServer() {
+        ServerRegistry reg = serverBus.getExtension(ServerRegistry.class);
+        List<Server> servers = reg.getServers();
+        for (Server serv : servers) {
+            System.out.println("expect to get a server here!");
+            serv.stop();
+        }
+    }
+    
+    private void startServer() {
+        ServerRegistry reg = serverBus.getExtension(ServerRegistry.class);
+        List<Server> servers = reg.getServers();
+        for (Server serv : servers) {
+            serv.start();
+        }
+    }
 
     @Test
     public void testGetServiceList() throws Exception {

Modified: cxf/trunk/systests/transports/src/test/java/org/apache/cxf/systest/servlet/NoSpringServletServer.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/transports/src/test/java/org/apache/cxf/systest/servlet/NoSpringServletServer.java?rev=1357455&r1=1357454&r2=1357455&view=diff
==============================================================================
--- cxf/trunk/systests/transports/src/test/java/org/apache/cxf/systest/servlet/NoSpringServletServer.java
(original)
+++ cxf/trunk/systests/transports/src/test/java/org/apache/cxf/systest/servlet/NoSpringServletServer.java
Thu Jul  5 03:30:32 2012
@@ -33,9 +33,8 @@ import org.eclipse.jetty.servlet.Servlet
 
 public class NoSpringServletServer extends AbstractBusTestServerBase {
     public static final String PORT = allocatePort(NoSpringServletServer.class);
-
-    
     Server httpServer;
+    Bus bus;
     @Override
     protected void run() {
         // setup the system properties
@@ -48,7 +47,7 @@ public class NoSpringServletServer exten
 
             ServletContextHandler root = new ServletContextHandler(contexts, "/",
                                                                    ServletContextHandler.SESSIONS);
-            Bus bus = BusFactory.getDefaultBus(true);
+            bus = BusFactory.getDefaultBus(true);
             CXFServlet cxf = new CXFServlet();
             cxf.setBus(bus);
             ServletHolder servlet = new ServletHolder(cxf);
@@ -83,6 +82,11 @@ public class NoSpringServletServer exten
             httpServer.stop();
         }
     }
+    
+    public Bus getBus() {
+        return bus;
+    }
+    
 
     public static void main(String[] args) {
         try {



Mime
View raw message