Author: dkulp
Date: Thu Feb 14 14:50:22 2008
New Revision: 627902
URL: http://svn.apache.org/viewvc?rev=627902&view=rev
Log:
[CXF-1417] Fix for SOAPFaultException from handlers not being mapped correctly
Modified:
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientProxy.java
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/HandlerChainInvoker.java
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationTest.java
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/TestSOAPHandler.java
Modified:
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientProxy.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientProxy.java?rev=627902&r1=627901&r2=627902&view=diff
==============================================================================
---
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientProxy.java
(original)
+++
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientProxy.java
Thu Feb 14 14:50:22 2008
@@ -167,8 +167,9 @@
nd = nd.getFirstChild();
soapFault.addDetail();
while (nd != null) {
+ Node next = nd.getNextSibling();
soapFault.getDetail().appendChild(nd);
- nd = nd.getNextSibling();
+ nd = next;
}
} else {
Modified:
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/HandlerChainInvoker.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/HandlerChainInvoker.java?rev=627902&r1=627901&r2=627902&view=diff
==============================================================================
---
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/HandlerChainInvoker.java
(original)
+++
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/HandlerChainInvoker.java
Thu Feb 14 14:50:22 2008
@@ -371,11 +371,17 @@
}
continueProcessing = false;
setFault(e);
+ if (e instanceof SOAPFaultException) {
+ throw mapSoapFault((SOAPFaultException)e);
+ }
throw e;
} else {
continueProcessing = false;
if (responseExpected || outbound) {
setFault(e);
+ if (e instanceof SOAPFaultException) {
+ throw mapSoapFault((SOAPFaultException)e);
+ }
throw e;
}
invokeReversedClose();
@@ -405,6 +411,16 @@
}
}
return continueProcessing;
+ }
+
+ private SoapFault mapSoapFault(SOAPFaultException sfe) {
+ SoapFault sf = new SoapFault(sfe.getFault().getFaultString(),
+ sfe,
+ sfe.getFault().getFaultCodeAsQName());
+ sf.setRole(sfe.getFault().getFaultActor());
+ sf.setDetail(sfe.getFault().getDetail());
+
+ return sf;
}
/*
Modified:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationTest.java?rev=627902&r1=627901&r2=627902&view=diff
==============================================================================
---
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationTest.java
(original)
+++
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationTest.java
Thu Feb 14 14:50:22 2008
@@ -27,7 +27,10 @@
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
import javax.xml.namespace.QName;
+import javax.xml.soap.Detail;
import javax.xml.soap.MessageFactory;
+import javax.xml.soap.SOAPConstants;
+import javax.xml.soap.SOAPFault;
import javax.xml.soap.SOAPMessage;
import javax.xml.transform.Source;
import javax.xml.ws.Binding;
@@ -45,11 +48,13 @@
import javax.xml.ws.handler.soap.SOAPMessageContext;
import javax.xml.ws.soap.SOAPFaultException;
+import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.apache.cxf.BusException;
import org.apache.cxf.common.util.PackageUtils;
+import org.apache.cxf.helpers.CastUtils;
import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
import org.apache.handler_test.HandlerTest;
import org.apache.handler_test.HandlerTestService;
@@ -726,25 +731,13 @@
< handler1.getInvokeOrderOfClose());
}
- //REVISIT: following tests only works when start the server alone(i.e, not
within HandlerInvocationTest)
- //otherwise, there is no response received from the server. But I have run
similar test scenarios with
- //standalone CXF client and Tomcat deployed CXF server, they all works.
Can not figure out the problem,
- //so just comment out these tests for the time being.
-
@Test
public void
testSOAPHandlerHandleMessageThrowsRuntimeExceptionServerInbound() throws
PingException {
try {
handlerTest.pingWithArgs("soapHandler3 inbound throw
RuntimeException");
fail("did not get expected exception");
- } catch (RuntimeException e) {
-/* e.printStackTrace();
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- PrintStream ps = new PrintStream(baos, true);
- e.printStackTrace(ps);
- assertTrue("Did not get expected exception message",
baos.toString()
- .indexOf("HandleMessage throws exception") > -1);
- assertTrue("Did not get expected
javax.xml.ws.soap.SOAPFaultException", baos.toString()
- .indexOf("javax.xml.ws.soap.SOAPFaultException") > -1);*/
+ } catch (SOAPFaultException e) {
+ assertEquals("HandleMessage throws exception", e.getMessage());
}
}
@@ -753,15 +746,8 @@
try {
handlerTest.pingWithArgs("soapHandler3 outbound throw
RuntimeException");
fail("did not get expected exception");
- } catch (RuntimeException e) {
- //e.printStackTrace();
-/* ByteArrayOutputStream baos = new ByteArrayOutputStream();
- PrintStream ps = new PrintStream(baos, true);
- e.printStackTrace(ps);
- assertTrue("Did not get expected exception message",
baos.toString()
- .indexOf("HandleMessage throws exception") > -1);
- assertTrue("Did not get expected
javax.xml.ws.soap.SOAPFaultException", baos.toString()
- .indexOf("javax.xml.ws.soap.SOAPFaultException") > -1);*/
+ } catch (SOAPFaultException e) {
+ assertEquals("HandleMessage throws exception", e.getMessage());
}
}
@@ -771,14 +757,34 @@
handlerTest.pingWithArgs("soapHandler3 inbound throw
ProtocolException");
fail("did not get expected WebServiceException");
} catch (WebServiceException e) {
-/* e.printStackTrace();
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- PrintStream ps = new PrintStream(baos, true);
- e.printStackTrace(ps);
- assertTrue("Did not get expected exception message",
baos.toString()
- .indexOf("HandleMessage throws exception") > -1);
- assertTrue("Did not get expected
javax.xml.ws.soap.SOAPFaultException", baos.toString()
- .indexOf("javax.xml.ws.soap.SOAPFaultException") > -1);*/
+ assertEquals("HandleMessage throws exception", e.getMessage());
+ }
+ }
+ @Test
+ public void
testSOAPHandlerHandleMessageThrowsSOAPFaultExceptionServerInbound() throws
PingException {
+ try {
+ handlerTest.pingWithArgs("soapHandler3 inbound throw
SOAPFaultExceptionWDetail");
+ fail("did not get expected SOAPFaultException");
+ } catch (SOAPFaultException e) {
+ assertEquals("HandleMessage throws exception", e.getMessage());
+ SOAPFault fault = e.getFault();
+ assertNotNull(fault);
+ assertEquals(new QName(SOAPConstants.URI_NS_SOAP_ENVELOPE,
"Server"),
+ fault.getFaultCodeAsQName());
+ assertEquals("http://gizmos.com/orders", fault.getFaultActor());
+
+ Detail detail = fault.getDetail();
+ assertNotNull(detail);
+
+ QName nn = new QName("http://gizmos.com/orders/", "order");
+ Iterator<Element> it = CastUtils.cast(detail.getChildElements(nn));
+ assertTrue(it.hasNext());
+ Element el = it.next();
+ el.normalize();
+ assertEquals("Quantity element does not have a value",
el.getFirstChild().getNodeValue());
+ el = it.next();
+ el.normalize();
+ assertEquals("Incomplete address: no zip code",
el.getFirstChild().getNodeValue());
}
}
@@ -800,14 +806,8 @@
+
"soapHandler4HandleFaultThrowsRunException");
fail("did not get expected WebServiceException");
} catch (WebServiceException e) {
- //e.printStackTrace();
-/* ByteArrayOutputStream baos = new ByteArrayOutputStream();
- PrintStream ps = new PrintStream(baos, true);
- e.printStackTrace(ps);
- assertTrue("Did not get expected exception message",
baos.toString()
- .indexOf("soapHandler4 HandleFault throws RuntimeException") >
-1);
- assertTrue("Did not get expected
javax.xml.ws.soap.SOAPFaultException", baos.toString()
- .indexOf("javax.xml.ws.soap.SOAPFaultException") > -1);*/
+ assertEquals("soapHandler4 HandleFault throws RuntimeException",
+ e.getMessage());
}
}
@@ -818,14 +818,8 @@
+
"soapHandler4HandleFaultThrowsSOAPFaultException");
fail("did not get expected SOAPFaultException");
} catch (SOAPFaultException e) {
-/* e.printStackTrace();
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- PrintStream ps = new PrintStream(baos, true);
- e.printStackTrace(ps);
- assertTrue("Did not get expected exception message",
baos.toString()
- .indexOf("soapHandler4 HandleFault throws SOAPFaultException")
> -1);
- assertTrue("Did not get expected
javax.xml.ws.soap.SOAPFaultException", baos.toString()
- .indexOf("javax.xml.ws.soap.SOAPFaultException") > -1);*/
+ assertEquals("soapHandler4 HandleFault throws SOAPFaultException",
+ e.getMessage());
}
}
@@ -835,14 +829,7 @@
handlerTest.pingWithArgs("soapHandler3 outbound throw
ProtocolException");
fail("did not get expected WebServiceException");
} catch (WebServiceException e) {
-/* e.printStackTrace();
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- PrintStream ps = new PrintStream(baos, true);
- e.printStackTrace(ps);
- assertTrue("Did not get expected exception message",
baos.toString()
- .indexOf("HandleMessage throws exception") > -1);
- assertTrue("Did not get expected
javax.xml.ws.soap.SOAPFaultException", baos.toString()
- .indexOf("javax.xml.ws.soap.SOAPFaultException") > -1);*/
+ assertEquals("HandleMessage throws exception", e.getMessage());
}
}
Modified:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/TestSOAPHandler.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/TestSOAPHandler.java?rev=627902&r1=627901&r2=627902&view=diff
==============================================================================
---
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/TestSOAPHandler.java
(original)
+++
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/TestSOAPHandler.java
Thu Feb 14 14:50:22 2008
@@ -26,7 +26,10 @@
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.xml.namespace.QName;
+import javax.xml.soap.Detail;
+import javax.xml.soap.DetailEntry;
import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPConstants;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPFactory;
import javax.xml.soap.SOAPFault;
@@ -258,6 +261,8 @@
throw new ProtocolException(exceptionText);
} else if ("SOAPFaultException".equals(exceptionType)) {
throw createSOAPFaultException(exceptionText);
+ } else if
("SOAPFaultExceptionWDetail".equals(exceptionType)) {
+ throw
createSOAPFaultExceptionWithDetail(exceptionText);
}
} else if (exceptionType != null && outbound &&
"outbound".equals(direction)) {
if ("RuntimeException".equals(exceptionType)) {
@@ -266,6 +271,8 @@
throw new ProtocolException(exceptionText);
} else if ("SOAPFaultException".equals(exceptionType)) {
throw createSOAPFaultException(exceptionText);
+ } else if
("SOAPFaultExceptionWDetail".equals(exceptionType)) {
+ throw
createSOAPFaultExceptionWithDetail(exceptionText);
}
}
@@ -282,6 +289,31 @@
SOAPFault fault = SOAPFactory.newInstance().createFault();
fault.setFaultString(faultString);
fault.setFaultCode(new QName("http://cxf.apache.org/faultcode",
"Server"));
+ return new SOAPFaultException(fault);
+ }
+ private SOAPFaultException createSOAPFaultExceptionWithDetail(String
faultString)
+ throws SOAPException {
+
+ SOAPFault fault = SOAPFactory.newInstance().createFault();
+
+ QName faultName = new QName(SOAPConstants.URI_NS_SOAP_ENVELOPE,
+ "Server");
+ fault.setFaultCode(faultName);
+ fault.setFaultActor("http://gizmos.com/orders");
+ fault.setFaultString(faultString);
+
+ Detail detail = fault.addDetail();
+
+ QName entryName = new QName("http://gizmos.com/orders/",
+ "order", "PO");
+ DetailEntry entry = detail.addDetailEntry(entryName);
+ entry.addTextNode("Quantity element does not have a value");
+
+ QName entryName2 = new QName("http://gizmos.com/orders/",
+ "order", "PO");
+ DetailEntry entry2 = detail.addDetailEntry(entryName2);
+ entry2.addTextNode("Incomplete address: no zip code");
+
return new SOAPFaultException(fault);
}