Repository: cxf Updated Branches: refs/heads/2.7.x-fixes 5ec0fd859 -> d66aec3ad
[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/d66aec3a Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/d66aec3a Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/d66aec3a Branch: refs/heads/2.7.x-fixes Commit: d66aec3aded4167836d0711d682cb8e75395b9aa Parents: 5ec0fd8 Author: Akitoshi Yoshida <[email protected]> Authored: Wed Sep 2 17:10:17 2015 +0200 Committer: Akitoshi Yoshida <[email protected]> Committed: Wed Sep 2 17:48:32 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/d66aec3a/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 71884c7..8e699b1 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; @@ -450,10 +451,7 @@ final class InternalContextUtils { if (fi.size() == 0) { continue; } - Class<?> fiTypeClass = fi.getMessagePart(0).getTypeClass(); - if (t != null - && fiTypeClass != null - && t.getClass().isAssignableFrom(fiTypeClass)) { + if (t != null && matchFault(t, fi)) { if (fi.getExtensionAttributes() == null) { continue; } @@ -477,6 +475,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.getMessagePart(0).getTypeClass(); + if (fiTypeClass != null && t.getClass().isAssignableFrom(fiTypeClass)) { + return true; + } + // CXF-6575 + QName fiName = fi.getMessagePart(0).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/d66aec3a/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 { } }
