Repository: cxf Updated Branches: refs/heads/3.0.x-fixes 6b38b193b -> 4c8580299
[CXF-6575] WS-A Action generation for fault fails Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/4c858029 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/4c858029 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/4c858029 Branch: refs/heads/3.0.x-fixes Commit: 4c85802999006f828a5682f58f53191d4636aba9 Parents: 6b38b19 Author: Akitoshi Yoshida <[email protected]> Authored: Wed Sep 2 17:10:17 2015 +0200 Committer: Akitoshi Yoshida <[email protected]> Committed: Wed Sep 2 17:50:35 2015 +0200 ---------------------------------------------------------------------- .../addressing/impl/InternalContextUtils.java | 21 ++++++++++++++++---- .../ws/addressing/impl/ContextUtilsTest.java | 21 ++++++++++++++++++++ 2 files changed, 38 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/4c858029/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/impl/InternalContextUtils.java ---------------------------------------------------------------------- diff --git a/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/impl/InternalContextUtils.java b/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/impl/InternalContextUtils.java index 9d2aaaf..fd765a1 100644 --- a/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/impl/InternalContextUtils.java +++ b/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/impl/InternalContextUtils.java @@ -28,6 +28,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import javax.xml.namespace.QName; +import javax.xml.ws.WebFault; import org.apache.cxf.Bus; import org.apache.cxf.binding.soap.SoapBindingConstants; @@ -447,10 +448,7 @@ final class InternalContextUtils { if (fi.size() == 0) { continue; } - Class<?> fiTypeClass = fi.getFirstMessagePart().getTypeClass(); - if (t != null - && fiTypeClass != null - && t.getClass().isAssignableFrom(fiTypeClass)) { + if (t != null && matchFault(t, fi)) { if (fi.getExtensionAttributes() == null) { continue; } @@ -476,6 +474,21 @@ final class InternalContextUtils { return action; } + private static boolean matchFault(Throwable t, FaultInfo fi) { + //REVISIT not sure if this class-based comparison works in general as the fault class defined + // in the service interface has no direct relationship to the message body's type. + Class<?> fiTypeClass = fi.getFirstMessagePart().getTypeClass(); + if (fiTypeClass != null && t.getClass().isAssignableFrom(fiTypeClass)) { + return true; + } + // CXF-6575 + QName fiName = fi.getFirstMessagePart().getConcreteName(); + WebFault wf = t.getClass().getAnnotation(WebFault.class); + return wf != null && fiName != null + && wf.targetNamespace() != null && wf.targetNamespace().equals(fiName.getNamespaceURI()) + && wf.name() != null && wf.name().equals(fiName.getLocalPart()); + } + public static SoapOperationInfo getSoapOperationInfo(BindingOperationInfo bindingOpInfo) { SoapOperationInfo soi = bindingOpInfo.getExtensor(SoapOperationInfo.class); if (soi == null && bindingOpInfo.isUnwrapped()) { http://git-wip-us.apache.org/repos/asf/cxf/blob/4c858029/rt/ws/addr/src/test/java/org/apache/cxf/ws/addressing/impl/ContextUtilsTest.java ---------------------------------------------------------------------- diff --git a/rt/ws/addr/src/test/java/org/apache/cxf/ws/addressing/impl/ContextUtilsTest.java b/rt/ws/addr/src/test/java/org/apache/cxf/ws/addressing/impl/ContextUtilsTest.java index 8931ef6..8fd638c 100755 --- a/rt/ws/addr/src/test/java/org/apache/cxf/ws/addressing/impl/ContextUtilsTest.java +++ b/rt/ws/addr/src/test/java/org/apache/cxf/ws/addressing/impl/ContextUtilsTest.java @@ -23,9 +23,11 @@ import java.util.HashMap; import java.util.Map; import javax.xml.namespace.QName; +import javax.xml.ws.WebFault; import org.apache.cxf.binding.soap.SoapBindingConstants; import org.apache.cxf.binding.soap.SoapFault; +import org.apache.cxf.interceptor.Fault; import org.apache.cxf.message.Exchange; import org.apache.cxf.message.Message; import org.apache.cxf.service.model.BindingOperationInfo; @@ -194,6 +196,25 @@ public class ContextUtilsTest extends Assert { action = InternalContextUtils.getAction(msg); assertNotNull(action); assertEquals(Names.WSA_DEFAULT_FAULT_ACTION, action.getValue()); + control.reset(); + // test 7 : retrieve the action for a fault matching the fault class with the WebFault annotation + fault = new SoapFault("faulty service", new TestFault(), Fault.FAULT_CODE_SERVER); + faultInfo.addMessagePart(new MessagePartInfo(new QName("http://foo.com:7", "faultInfo"), null)); + faultInfo.getMessagePart(0).setTypeClass(Object.class); + faultInfo.getMessagePart(0).setConcreteName(new QName("urn:foo:test:7", "testFault")); + faultInfo.addExtensionAttribute(Names.WSAW_ACTION_QNAME, "urn:foo:test:7"); + EasyMock.expect(msg.getExchange()).andReturn(exchange).anyTimes(); + EasyMock.expect(msg.getContent(Exception.class)).andReturn(fault).anyTimes(); + EasyMock.expect(exchange.get(BindingOperationInfo.class)).andReturn(boi); + control.replay(); + + action = InternalContextUtils.getAction(msg); + assertNotNull(action); + assertEquals("urn:foo:test:7", action.getValue()); + } + + @WebFault(name = "testFault", targetNamespace = "urn:foo:test:7") + public class TestFault extends Exception { } }
