You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by ay...@apache.org on 2012/11/23 13:06:58 UTC
svn commit: r1412851 - in /cxf/trunk/rt/ws/addr/src:
main/java/org/apache/cxf/ws/addressing/impl/InternalContextUtils.java
test/java/org/apache/cxf/ws/addressing/impl/ContextUtilsTest.java
Author: ay
Date: Fri Nov 23 12:06:57 2012
New Revision: 1412851
URL: http://svn.apache.org/viewvc?rev=1412851&view=rev
Log:
[CXF-4647] A wrong soap action when using ws-addressing may lead to an empty response or the wrong fault
Modified:
cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/impl/InternalContextUtils.java
cxf/trunk/rt/ws/addr/src/test/java/org/apache/cxf/ws/addressing/impl/ContextUtilsTest.java
Modified: cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/impl/InternalContextUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/impl/InternalContextUtils.java?rev=1412851&r1=1412850&r2=1412851&view=diff
==============================================================================
--- cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/impl/InternalContextUtils.java (original)
+++ cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/impl/InternalContextUtils.java Fri Nov 23 12:06:57 2012
@@ -365,11 +365,17 @@ final class InternalContextUtils {
LOG.fine("Determining action");
Exception fault = message.getContent(Exception.class);
+ if (fault instanceof Fault
+ && Names.WSA_NAMESPACE_NAME.equals(((Fault)fault).getFaultCode().getNamespaceURI())) {
+ // wsa relevant faults should use the wsa-fault action value
+ action = Names.WSA_DEFAULT_FAULT_ACTION;
+ } else {
+ action = getActionFromServiceModel(message, fault);
+ }
// REVISIT: add support for @{Fault}Action annotation (generated
// from the wsaw:Action WSDL element). For the moment we just
// pick up the wsaw:Action attribute by walking the WSDL model
// directly
- action = getActionFromServiceModel(message, fault);
LOG.fine("action: " + action);
return action != null ? ContextUtils.getAttributedURI(action) : null;
}
@@ -418,6 +424,9 @@ final class InternalContextUtils {
// http://www.w3.org/2005/02/addressing/wsdl schema
for (BindingFaultInfo bfi : bindingOpInfo.getFaults()) {
FaultInfo fi = bfi.getFaultInfo();
+ if (fi.size() == 0) {
+ continue;
+ }
Class<?> fiTypeClass = fi.getMessagePart(0).getTypeClass();
if (t != null
&& fiTypeClass != null
Modified: cxf/trunk/rt/ws/addr/src/test/java/org/apache/cxf/ws/addressing/impl/ContextUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/addr/src/test/java/org/apache/cxf/ws/addressing/impl/ContextUtilsTest.java?rev=1412851&r1=1412850&r2=1412851&view=diff
==============================================================================
--- cxf/trunk/rt/ws/addr/src/test/java/org/apache/cxf/ws/addressing/impl/ContextUtilsTest.java (original)
+++ cxf/trunk/rt/ws/addr/src/test/java/org/apache/cxf/ws/addressing/impl/ContextUtilsTest.java Fri Nov 23 12:06:57 2012
@@ -26,7 +26,19 @@ import javax.xml.namespace.QName;
import junit.framework.Assert;
+import org.apache.cxf.binding.soap.SoapBindingConstants;
+import org.apache.cxf.binding.soap.SoapFault;
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.service.model.BindingOperationInfo;
import org.apache.cxf.service.model.Extensible;
+import org.apache.cxf.service.model.FaultInfo;
+import org.apache.cxf.service.model.MessageInfo;
+import org.apache.cxf.service.model.MessageInfo.Type;
+import org.apache.cxf.service.model.MessagePartInfo;
+import org.apache.cxf.service.model.OperationInfo;
+import org.apache.cxf.ws.addressing.AttributedURIType;
+import org.apache.cxf.ws.addressing.ContextUtils;
import org.apache.cxf.ws.addressing.JAXWSAConstants;
import org.apache.cxf.ws.addressing.Names;
import org.easymock.EasyMock;
@@ -97,4 +109,92 @@ public class ContextUtilsTest extends As
action = InternalContextUtils.getAction(ext);
assertEquals(null, action);
}
+
+ @Test
+ public void testGetActionFromMessage() {
+ Message msg = control.createMock(Message.class);
+ Exchange exchange = control.createMock(Exchange.class);
+
+ QName mqname = new QName("http://foo.com", "bar");
+ QName fqname = new QName("urn:foo:test:4", "fault");
+ OperationInfo operationInfo = new OperationInfo();
+ MessageInfo messageInfo = new MessageInfo(operationInfo, Type.OUTPUT, mqname);
+ messageInfo.addMessagePart(new MessagePartInfo(new QName("http://foo.com", "partInfo"), null));
+ operationInfo.setOutput("outputName", messageInfo);
+ FaultInfo faultInfo = new FaultInfo(fqname, mqname, operationInfo);
+ operationInfo.addFault(faultInfo);
+ BindingOperationInfo boi = new BindingOperationInfo(null, operationInfo);
+
+ // test 1 : retrieving the normal action prop from the message
+ EasyMock.expect(msg.getExchange()).andReturn(exchange).anyTimes();
+ EasyMock.expect(exchange.get(BindingOperationInfo.class)).andReturn(boi);
+ EasyMock.expect(msg.get(ContextUtils.ACTION)).andReturn("urn:foo:test:1");
+ control.replay();
+
+ AttributedURIType action = InternalContextUtils.getAction(msg);
+ assertNotNull(action);
+ assertEquals("urn:foo:test:1", action.getValue());
+ control.reset();
+
+ // test 2 : retrieving the normal soap action prop from the message
+ EasyMock.expect(msg.getExchange()).andReturn(exchange).anyTimes();
+ EasyMock.expect(exchange.get(BindingOperationInfo.class)).andReturn(boi);
+ EasyMock.expect(msg.get(SoapBindingConstants.SOAP_ACTION)).andReturn("urn:foo:test:2");
+ control.replay();
+
+ action = InternalContextUtils.getAction(msg);
+ assertNotNull(action);
+ assertEquals("urn:foo:test:2", action.getValue());
+ control.reset();
+
+ // test 3 : retrieving the action prop from the message info
+ EasyMock.expect(msg.getExchange()).andReturn(exchange).anyTimes();
+ EasyMock.expect(exchange.get(BindingOperationInfo.class)).andReturn(boi);
+ messageInfo.setProperty(ContextUtils.ACTION, "urn:foo:test:3");
+ control.replay();
+
+ action = InternalContextUtils.getAction(msg);
+ assertNotNull(action);
+ assertEquals("urn:foo:test:3", action.getValue());
+ control.reset();
+
+ // test 4 : retrieving the action for a fault without message part
+ SoapFault fault = new SoapFault("faulty service", new RuntimeException(), fqname);
+ 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);
+ assertNull(action);
+ control.reset();
+
+ // test 5 : retrieving the action for a fault with matching message part
+ faultInfo.addMessagePart(new MessagePartInfo(new QName("http://foo.com", "faultInfo"), null));
+ faultInfo.getMessagePart(0).setTypeClass(RuntimeException.class);
+ faultInfo.addExtensionAttribute(Names.WSAW_ACTION_QNAME, "urn:foo:test:4");
+ 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:4", action.getValue());
+ control.reset();
+
+ // test 6 : retrieving the action for a ws-addr fault with matching message part
+ fault = new SoapFault("Action Mismatch",
+ new QName(Names.WSA_NAMESPACE_NAME,
+ Names.ACTION_MISMATCH_NAME));
+ 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(Names.WSA_DEFAULT_FAULT_ACTION, action.getValue());
+
+ }
}