Hi
The SpringServletTest failed on the Linux may caused by the bus was not init
correctly, as the test can run successed in single test , but failed with
multi tests running.
So I went through the Bus creation in the SpringServletTest.
There are two BusFactory in CXF, one is CXFBusFactory, the other is
SpringBusFactory. To get the defaultBus for CXF, they both use the static
member defaultBus which is setted by BusFacotry.getDefaultBus() to store the
created Bus. The BusFactoryHelper.newInstance() now just get the
SpringBusFactory for us.
I just debugged the SpringServletTest and CXFTest and found out the
SpringBusFactory will create the default bus first in the CXFServlet.java
initialization, and register the http related namespace for
ServletTransportFactory.
The CC's error looks like we can't setup the default bus which is initialized
by the CXFServlet in the SpringServletTest for using. So we need to override
the createBus() and getBus() in AbstractServletTest to use the CXFServlet
inited bus, and clean up the bus when the test teardown.
We just get the bus when we need with
BusFactoryHelper.newInstance().getDefaultBus(). This is the common scenario
when we call the Jax-ws API to create service. IMO, we need to think about the
BusFactory getDefaultBus() API, to make our life easy with the Bus creatation
and Bus using. Basicly we need to be careful with using the static member.
public synchronized Bus getDefaultBus() {
if (null == defaultBus) {
defaultBus = new CXFBusImpl();
}
return defaultBus;
}
I have not idea to make the getDefaultBus() better now , but I just want to
reminder the API's side effect of the static member, if the default bus is not
null, we just get the bus which we created before.
What's your throughts for getting better getDefaultBus()?
BTW: This issue is not appared on Windows box , it may cause by the surefire
fork mode. I am not sure about it. Please point me out, if I am wrong.
Cheers,
Willem
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: 12/21/2006 16:58
To: [email protected]
Subject: svn commit: r489290 - in /incubator/cxf/trunk/rt:
core/src/main/java/org/apache/cxf/test/
frontend/jaxws/src/test/java/org/apache/cxf/jaxws/servlet/
Author: ningjiang
Date: Thu Dec 21 00:58:21 2006
New Revision: 489290
URL: http://svn.apache.org/viewvc?view=rev&rev=489290
Log:
Try to get SpringservletTest work again
Modified:
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/test/AbstractCXFTest.java
incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/servlet/AbstractServletTest.java
incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/servlet/SpringServletTest.java
Modified:
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/test/AbstractCXFTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/test/AbstractCXFTest.java?view=diff&rev=489290&r1=489289&r2=489290
==============================================================================
---
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/test/AbstractCXFTest.java
(original)
+++
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/test/AbstractCXFTest.java
Thu Dec 21 00:58:21 2006
@@ -39,7 +39,7 @@
import org.apache.cxf.Bus;
import org.apache.cxf.BusException;
-import org.apache.cxf.bus.cxf.CXFBusFactory;
+import org.apache.cxf.BusFactoryHelper;
import org.apache.cxf.helpers.DOMUtils;
import org.apache.cxf.helpers.IOUtils;
import org.apache.cxf.message.Message;
@@ -57,12 +57,13 @@
private static String basedirPath;
+ protected Bus bus;
/**
* Namespaces for the XPath expressions.
*/
private Map<String, String> namespaces = new HashMap<String, String>();
- private Bus bus;
+
public void setUp() throws Exception {
bus = createBus();
@@ -79,9 +80,17 @@
public Bus getBus() {
return bus;
}
+
+ public void tearDown() {
+ if (bus != null) {
+ bus.shutdown(false);
+ }
+ BusFactoryHelper.newInstance().setDefaultBus(null);
+ }
+
protected Bus createBus() throws BusException {
- return new CXFBusFactory().createBus();
+ return BusFactoryHelper.newInstance().createBus();
}
protected byte[] invokeBytes(String address,
Modified:
incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/servlet/AbstractServletTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/servlet/AbstractServletTest.java?view=diff&rev=489290&r1=489289&r2=489290
==============================================================================
---
incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/servlet/AbstractServletTest.java
(original)
+++
incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/servlet/AbstractServletTest.java
Thu Dec 21 00:58:21 2006
@@ -30,9 +30,12 @@
import com.meterware.servletunit.ServletRunner;
import com.meterware.servletunit.ServletUnitClient;
+//import org.apache.cxf.Bus;
+//import org.apache.cxf.BusException;
import org.apache.cxf.Bus;
import org.apache.cxf.BusFactoryHelper;
import org.apache.cxf.test.AbstractCXFTest;
+//import org.apache.cxf.transport.DestinationFactoryManager;
public abstract class AbstractServletTest extends AbstractCXFTest {
@@ -47,20 +50,25 @@
// ignore, we just want to boot up the servlet
}
super.setUp();
-
+
HttpUnitOptions.setExceptionsThrownOnErrorStatus(true);
- }
+ }
public void tearDown() {
- // clean up the BusFactory defualt bus
- BusFactoryHelper.newInstance().setDefaultBus(null);
+ bus.shutdown(false);
+ BusFactoryHelper.newInstance().setDefaultBus(null);
}
-
+
+ //CXFservlet has create the bus, so we need to use this bus for service
init
@Override
public Bus getBus() {
return BusFactoryHelper.newInstance().getDefaultBus();
}
-
+
+ @Override
+ public Bus createBus() {
+ return BusFactoryHelper.newInstance().getDefaultBus();
+ }
/**
* @return The web.xml to use for testing.
*/
Modified:
incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/servlet/SpringServletTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/servlet/SpringServletTest.java?view=diff&rev=489290&r1=489289&r2=489290
==============================================================================
---
incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/servlet/SpringServletTest.java
(original)
+++
incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/servlet/SpringServletTest.java
Thu Dec 21 00:58:21 2006
@@ -18,13 +18,13 @@
*/
package org.apache.cxf.jaxws.servlet;
-/*import org.w3c.dom.Document;
+import org.w3c.dom.Document;
import com.meterware.httpunit.PostMethodWebRequest;
import com.meterware.httpunit.WebRequest;
import com.meterware.httpunit.WebResponse;
-import org.apache.cxf.helpers.DOMUtils;*/
+import org.apache.cxf.helpers.DOMUtils;
public class SpringServletTest extends AbstractServletTest {
@Override
@@ -33,7 +33,7 @@
}
public void testInvokingSpringBeans() throws Exception {
-/*
+
WebRequest req = new
PostMethodWebRequest("http://localhost/services/Greeter",
getClass().getResourceAsStream("/org/apache/cxf/jaxws/GreeterMessage.xml"),
"text/xml; charset=utf-8");
@@ -49,6 +49,6 @@
addNamespace("h", "http://apache.org/hello_world_soap_http/types");
assertValid("/s:Envelope/s:Body", doc);
- assertValid("//h:sayHiResponse", doc);*/
+ assertValid("//h:sayHiResponse", doc);
}
}