whitlock 2002/10/09 04:52:11
Modified: java/test/org/apache/wsif/util/jms
NativeJMSRequestListener.java
java/test/jms JmsFault.wsdl JmsFaultTest.java
java/src/org/apache/wsif/providers/jms JMSFormatter.java
WSIFOperation_Jms.java
Log:
Fix NativeJms faults
Revision Changes Path
1.14 +24 -9
xml-axis-wsif/java/test/org/apache/wsif/util/jms/NativeJMSRequestListener.java
Index: NativeJMSRequestListener.java
===================================================================
RCS file:
/home/cvs/xml-axis-wsif/java/test/org/apache/wsif/util/jms/NativeJMSRequestListener.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- NativeJMSRequestListener.java 7 Oct 2002 15:25:52 -0000 1.13
+++ NativeJMSRequestListener.java 9 Oct 2002 11:52:10 -0000 1.14
@@ -263,8 +263,6 @@
} else if ( "whoami".equals( operationName ) ) {
reply = inoutWhoami( (ObjectMessage) msg );
sendReply( msg, reply );
- } else if ( "noFault".equals( operationName ) ) {
- noFault( (ObjectMessage) msg );
} else if ( "throwSimple".equals( operationName ) ) {
throwSimple( (ObjectMessage) msg );
} else {
@@ -348,19 +346,36 @@
return hmr;
}
- private void noFault(ObjectMessage msg) throws Exception {
- sendReply(msg,"No Fault");
- }
-
private void throwSimple(ObjectMessage msg) throws Exception {
Queue replyTo = (Queue) (msg.getJMSReplyTo());
if (replyTo == null)
return;
-
+
ObjectMessage faultMsg = (ObjectMessage) session.createObjectMessage();
- faultMsg.setObject((Serializable) "A Simple Fault");
+ int choice = ((Integer) msg.getObject()).intValue();
+ System.out.println("NativeJMSRequestListener throwSimple choice="+choice);
+ switch (choice) {
+ case 0 :
+ break;
+ case 1 :
+ faultMsg.setObject((Serializable) "A Simple Fault");
+ faultMsg.setStringProperty("faultIndicator", "simple");
+ break;
+ case 2 :
+ case 3 :
+ HashMap hm = new HashMap();
+ hm.put("faultInt1", new Integer(1));
+ hm.put("faultInt2", new Integer(2));
+ hm.put("faultInt3", new Integer(3));
+ faultMsg.setObject((Serializable) hm);
+ faultMsg.setStringProperty(
+ "faultIndicator",
+ choice == 2 ? "ints" : "twoints");
+ break;
+ default :
+ throw new RuntimeException("throwSimple: Bad choice");
+ }
- faultMsg.setStringProperty("faultIndicator","simple");
setReplyToQueue(replyTo);
String o = msg.getJMSMessageID();
try {
1.2 +22 -13 xml-axis-wsif/java/test/jms/JmsFault.wsdl
Index: JmsFault.wsdl
===================================================================
RCS file: /home/cvs/xml-axis-wsif/java/test/jms/JmsFault.wsdl,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- JmsFault.wsdl 7 Oct 2002 15:25:51 -0000 1.1
+++ JmsFault.wsdl 9 Oct 2002 11:52:11 -0000 1.2
@@ -8,29 +8,30 @@
xmlns="http://schemas.xmlsoap.org/wsdl/">
<!-- message declns -->
- <message name="NoFaultReq"/>
- <message name="NoFaultResp"/>
-
- <message name="SimpleReq"/>
+ <message name="SimpleReq">
+ <part name="choice" type="xsd:int"/>
+ </message>
+
<message name="SimpleResp"/>
+
<message name="SimpleFault">
<part name="faultText" type="xsd:string"/>
</message>
+
<message name="IntFault">
- <part name="faultInt" type="xsd:int"/>
+ <part name="faultInt1" type="xsd:int"/>
+ <part name="faultInt2" type="xsd:int"/>
+ <part name="faultInt3" type="xsd:int"/>
</message>
<!-- port type declns -->
<portType name="JmsFault">
- <operation name="noFault">
- <input message="tns:NoFaultReq"/>
- <output message="tns:NoFaultResp"/>
- </operation>
<operation name="throwSimple">
<input message="tns:SimpleReq"/>
<output message="tns:SimpleResp"/>
<fault name="SimpleFault" message="tns:SimpleFault"/>
<fault name="IntFault" message="tns:IntFault"/>
+ <fault name="TwoIntFault" message="tns:IntFault"/>
</operation>
</portType>
@@ -54,6 +55,7 @@
- bad parts="xxx" in the <jms:fault
- multiple parts="xxx" in the <jms:fault is an error
- multiple <jms:fault in the <fault is an error
+ - multiple faultProperties have the same value
A list of unanswered questions
@@ -73,10 +75,6 @@
<format:typeMapping encoding="Java" style="Java">
<format:typeMap typeName="xsd:string" formatType="java.lang.String" />
</format:typeMapping>
- <operation name="noFault">
- <input/>
- <output/>
- </operation>
<operation name="throwSimple">
<input/>
<output/>
@@ -84,6 +82,17 @@
<jms:faultIndicator type="property">
<jms:faultProperty name="faultIndicator" type="xsd:string"
value="simple"/>
</jms:faultIndicator>
+ </fault>
+ <fault name="IntFault">
+ <jms:faultIndicator type="property">
+ <jms:faultProperty name="faultIndicator" type="xsd:string" value="ints"/>
+ </jms:faultIndicator>
+ </fault>
+ <fault name="TwoIntFault">
+ <jms:faultIndicator type="property">
+ <jms:faultProperty name="faultIndicator" type="xsd:string"
value="twoints"/>
+ </jms:faultIndicator>
+ <jms:fault parts="faultInt1 faultInt2"/>
</fault>
</operation>
</binding>
1.2 +65 -10 xml-axis-wsif/java/test/jms/JmsFaultTest.java
Index: JmsFaultTest.java
===================================================================
RCS file: /home/cvs/xml-axis-wsif/java/test/jms/JmsFaultTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- JmsFaultTest.java 7 Oct 2002 15:25:51 -0000 1.1
+++ JmsFaultTest.java 9 Oct 2002 11:52:11 -0000 1.2
@@ -57,6 +57,8 @@
package jms;
+import java.util.Iterator;
+
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
@@ -94,11 +96,43 @@
TestUtilities.setUpExtensionsAndProviders();
}
- public void testSoapDefault() {
- doit("throwSimple", false);
+ public void testNoFault() {
+ doit("throwSimple", 0, false, null, null);
+ }
+
+ public void testSimple() {
+ doit(
+ "throwSimple",
+ 1,
+ false,
+ new String[] { "faultText" },
+ new Object[] { "A Simple Fault" });
+ }
+
+ public void testInts() {
+ doit(
+ "throwSimple",
+ 2,
+ false,
+ new String[] { "faultInt1", "faultInt2", "faultInt3" },
+ new Object[] { new Integer(1), new Integer(2), new Integer(3)});
+ }
+
+ public void testTwoInts() {
+ doit(
+ "throwSimple",
+ 3,
+ false,
+ new String[] { "faultInt1", "faultInt2" },
+ new Object[] { new Integer(1), new Integer(2) });
}
- private void doit(String method, boolean exceptionExpected) {
+ private void doit(
+ String method,
+ int choice,
+ boolean exceptionExpected,
+ String[] names,
+ Object[] parts) {
if (!TestUtilities.areWeTesting("jms"))
return;
@@ -117,6 +151,7 @@
WSIFOperation operation = port.createOperation(method);
WSIFMessage inputMessage = operation.createInputMessage();
+ inputMessage.setIntPart("choice",choice);
WSIFMessage outputMessage = operation.createOutputMessage();
WSIFMessage faultMessage = operation.createFaultMessage();
@@ -126,13 +161,33 @@
outputMessage,
faultMessage);
- if ("throwSimple".equals(method)) {
- String faultText =
- (String) faultMessage.getObjectPart("faultText");
- assertTrue("A Simple Fault".equals(faultText));
- } else
- assertTrue("noFault".equals(method));
-
+ System.out.println(
+ "JmsFaultTest "
+ + method
+ + " "
+ + operationSucceeded
+ + " "
+ + (names == null));
+
+ assertTrue(
+ (operationSucceeded && (names == null))
+ || (!operationSucceeded && (names != null)));
+
+ if (!operationSucceeded) {
+ Iterator it = faultMessage.getPartNames();
+ int i = 0;
+ while (it.hasNext()) {
+ it.next();
+ i++;
+ }
+ assertTrue(i == names.length);
+
+ for (i = 0; i < names.length; i++) {
+ Object o = faultMessage.getObjectPart(names[i]);
+ assertTrue(parts[i].equals(o));
+ }
+ }
+
assertTrue(!exceptionExpected);
} catch (Exception e) {
System.err.println("JmsFaultTest(" + method + ") caught exception " +
e);
1.9 +116 -60
xml-axis-wsif/java/src/org/apache/wsif/providers/jms/JMSFormatter.java
Index: JMSFormatter.java
===================================================================
RCS file:
/home/cvs/xml-axis-wsif/java/src/org/apache/wsif/providers/jms/JMSFormatter.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- JMSFormatter.java 7 Oct 2002 15:25:51 -0000 1.8
+++ JMSFormatter.java 9 Oct 2002 11:52:11 -0000 1.9
@@ -426,6 +426,7 @@
Trc.entry(this, resp, out, binding, bop);
+ // Iterate through the BindingOperation to find all the
<jms:faultIndicators.
Map bndFs = bop.getBindingFaults();
if (bndFs != null && !bndFs.isEmpty()) {
Iterator itBndFNames = bndFs.keySet().iterator();
@@ -440,74 +441,129 @@
Iterator itBndFElems = bndFElems.iterator();
while (itBndFElems.hasNext()) {
Object bndFElem = itBndFElems.next();
+
+ // Ignore anything that isn't a fault indicator, since
+ // those will be dealt with by unformatFaultMessage.
if (bndFElem instanceof JMSFaultIndicator) {
JMSFaultIndicator indic = (JMSFaultIndicator) bndFElem;
- String type = indic.getType();
- if (type==null || !"property".equals(type)) continue;
-
- List fProps = indic.getJMSFaultProperties();
- if (fProps==null || fProps.isEmpty()) continue;
-
- Iterator itFProps = fProps.iterator();
- while (itFProps.hasNext()) {
- JMSFaultProperty fProp = (JMSFaultProperty)
itFProps.next();
- String propName = fProp.getName();
- if (propName == null
- || fProp.getType() == null
- || fProp.getValue() == null)
- continue;
-
- String propValue = null;
- try {
- if (!out.propertyExists(propName))
- continue;
-
- // Need to sort out the type here ???
- // NativeJms propertyValues also ignore the type ???
- // We assume the type is a string. This is a HACK.
-
- propValue = out.getStringProperty(propName);
- } catch (JMSException je) {
- Trc.ignoredException(je);
- continue;
- }
-
- if (propValue != null
- && propValue.equals(fProp.getValue())) {
-
- Operation op = bop.getOperation();
- Fault fault = op.getFault(bndFName);
- if (fault != null) {
- javax.wsdl.Message faultMessage =
- fault.getMessage();
-
- JMSMessage fhMsg =
- new JMSMessage(
- fieldDefinition,
- binding,
- faultMessage,
- getFaultParts(bndF));
-
- fhMsg.read(out);
-
- resp.setOutgoingMessage(fhMsg);
- }
-
- resp.setIsFault(true);
- Trc.exit(true);
- return true;
- }
-
+
+ // Only the first fault indicator that matches is used.
+ // If others match, then this error is ignored.
+ if (matchesFaultIndicator(indic, out)) {
+ WSIFMessage msg =
+ unformatFaultMessage(
+ out,
+ binding,
+ bop,
+ bndFName,
+ bndF);
+
+ resp.setOutgoingMessage(msg);
+ resp.setIsFault(true);
+ Trc.exit(true);
+ return true;
}
-
- } else if (bndFElem instanceof JMSProperty) {
- JMSProperty prop = (JMSProperty) bndFElem;
- }
+ }
}
}
}
Trc.exit(false);
return false;
+ }
+
+ /**
+ * Look to see whether this JMSFaultIndicator matches this output JMS message
+ * by seeing whether the faultProperty exists on the message and has the
+ * same value.
+ *
+ * It would be good to first see if there are any properties on the message
+ * that might indicate a fault so this method could return false quickly.
+ * Unfortunately I assume all JMS messages will have a number of properties
+ * set so this performance enhancement is not available.
+ *
+ * @return true for a match, false for no match.
+ */
+ private boolean matchesFaultIndicator(
+ JMSFaultIndicator indic,
+ javax.jms.Message out) {
+ Trc.entry(this, indic, out);
+
+ // Fault indicators must have type=property. Other types are ignored.
+ String type = indic.getType();
+ if (type == null || !"property".equals(type)) {
+ Trc.exit(false);
+ return false;
+ }
+
+ List fProps = indic.getJMSFaultProperties();
+ if (fProps == null || fProps.isEmpty()) {
+ Trc.exit(false);
+ return false;
+ }
+
+ Iterator itFProps = fProps.iterator();
+ while (itFProps.hasNext()) {
+ JMSFaultProperty fProp = (JMSFaultProperty) itFProps.next();
+ String propName = fProp.getName();
+ if (propName == null
+ || fProp.getType() == null
+ || fProp.getValue() == null)
+ continue;
+
+ String propValue = null;
+ try {
+ if (!out.propertyExists(propName))
+ continue;
+
+ // Need to sort out the type here ???
+ // NativeJms propertyValues also ignore the type ???
+ // We assume the type is a string. This is a HACK.
+
+ propValue = out.getStringProperty(propName);
+ } catch (JMSException je) {
+ Trc.ignoredException(je);
+ continue;
+ }
+
+ if (propValue != null && propValue.equals(fProp.getValue())) {
+ Trc.exit(true);
+ return true;
+ }
+
+ }
+ Trc.exit(false);
+ return false;
+ }
+
+ private WSIFMessage unformatFaultMessage(
+ javax.jms.Message out,
+ Binding binding,
+ BindingOperation bop,
+ String bndFName,
+ BindingFault bndF)
+ throws WSIFException {
+ Trc.entry(this, out, binding, bop, bndFName, bndF);
+
+ Operation op = bop.getOperation();
+ Fault fault = op.getFault(bndFName);
+ if (fault == null)
+ throw new WSIFException(
+ "No fault "
+ + bndFName
+ + " found in operation "
+ + op.getName());
+
+ JMSMessage fhMsg =
+ new JMSMessage(
+ fieldDefinition,
+ binding,
+ fault.getMessage(),
+ getFaultParts(bndF));
+
+ fhMsg.read(out);
+ Trc.exit(fhMsg);
+ return fhMsg;
+
}
void copyTo(
1.30 +9 -6
xml-axis-wsif/java/src/org/apache/wsif/providers/jms/WSIFOperation_Jms.java
Index: WSIFOperation_Jms.java
===================================================================
RCS file:
/home/cvs/xml-axis-wsif/java/src/org/apache/wsif/providers/jms/WSIFOperation_Jms.java,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- WSIFOperation_Jms.java 7 Oct 2002 15:25:52 -0000 1.29
+++ WSIFOperation_Jms.java 9 Oct 2002 11:52:11 -0000 1.30
@@ -195,6 +195,7 @@
setAsyncOperation(false);
+ boolean operationSucceeded = true;
try {
getOperation();
@@ -202,7 +203,7 @@
String correlId = sendJmsMessage(input);
javax.jms.Message response = jmsDest.receive(correlId);
- receiveJmsMessage(response, output, fault);
+ operationSucceeded = receiveJmsMessage(response, output, fault);
} catch (Exception ex) {
Trc.exception(ex);
@@ -221,8 +222,8 @@
ex);
}
- Trc.exit(true);
- return true;
+ Trc.exit(operationSucceeded);
+ return operationSucceeded;
}
/**
@@ -473,7 +474,7 @@
/**
* receivesend jms message
*/
- private void receiveJmsMessage(
+ private boolean receiveJmsMessage(
Object responseObject,
WSIFMessage output,
WSIFMessage fault)
@@ -485,9 +486,10 @@
WSIFResponse resp =
formatter.unformatResponse((javax.jms.Message) responseObject);
- if (resp.getIsFault())
+ if (resp.getIsFault()) {
formatter.copyTo(resp.getOutgoingMessage(), fault);
- else {
+ return false;
+ } else {
// the output message contains all response parts
// even if not defined in the WSDL. Any parts
@@ -506,6 +508,7 @@
for (Iterator i = wsdlOutputParts.iterator(); i.hasNext();) {
output.setObjectPart((String) i.next(), null);
}
+ return true;
}
/**