By Ramkumar Menon on September 21, 2007 2:14 PM
A few days back, I was struggling with running the RMI Client against the CreditRatingService with a fault scenario. [setting ssn=0].
I was receiving an UnmarshallException whose root cause was an "InvalidClassException" referring to the class javax.xml.namespace.QName.
On further analysis, I discovered that JDK 1.5 ships with a javax.xml.namespace.QName that carries a different serialVersionUID than the one that ships with JDK 1.4.
Since I was using JDK 1.5_06 to run my RMI Client, it kept on complaining.
By Ramkumar Menon on September 21, 2007 4:08 PM
Assume that you had an XML Document like the one illustrated below.
-
- <purchaseOrder xmlns="www.oracle.com/po">
- <id>100</id>
- <items>
- <item name="TV">
- <description>television</description>
- </item>
- <item name=VCR">
- <description>Video Cassette Recorder</description>
- </item>
- <item name="DVD">
- <description>Digital Video Disc</description>
- </item>
- </items>
- <comment>PO from Ramkumar Menon</comment>
- </purchaseOrder>
You had a piece of java code in which you wish to get the comments from the purchaseOrder. You choose to use the "selectNodes()" API to get the value.
-
-
- DOMParser parser = new DOMParser();
- StringReader reader = new StringReader(poXMLString);
- parser.parse(reader);;
- XMLDocument doc = parser.getDocument();
- XMLElement docElement = (XMLElement)doc.getDocumentElement();
- NodeList list = doc.selectNodes("/purchaseOrder/comment",docElement);
- System.err.println("number of items in the list = " + list.getLength());
DOMParser parser = new DOMParser(); StringReader reader = new StringReader(poXMLString); parser.parse(reader);; XMLDocument doc = parser.getDocument(); XMLElement docElement = (XMLElement)doc.getDocumentElement(); NodeList list = doc.selectNodes("/purchaseOrder/comment",docElement); System.err.println("number of items in the list = " + list.getLength()); Result - Guess what! It is zero. Why ? Here you go! The Location path expression that I just modeled contains a set of location steps "purchaseOrder"and "comment". Xpath expects each of the node names within the location steps to be a QName. [consisting of a namespace URI and a local name]
But, yes, but, if the namespace prefix on the node name is specified to be "empty", the nodes are assumed to come from null namespace, and not the default namespace.
That is exactly why you get zero nodes on the evaluation of the expression.
Whats the workaround?
- Ensure that the path elements have a namespace prefix, or
- You could use wildcard expressions . For instance,the above expression could be re-written as "/*[local-name()='purchaseOrder'][namespace-uri()='www.oracle.com/po'] /*[local-name()='comments'[namespace-uri()='www.oracle.com/po'] You could use either of these approaches, and you've got what you wished for!
By Ramkumar Menon on September 28, 2007 1:32 PM
Assume that you have a BPEL Process that returns a Fault may it be business or runtime.
Your RMI Client can receive the payload of the faults from the BPEL Processes by using the snippet below.
-
- import oracle.xml.parser.v2.XMLElement;
- import com.oracle.bpel.client.ServerException;
- import com.oracle.bpel.client.BPELFault;
- try {
-
-
-
- }catch(ServerException ex) {
-
- Throwable t = ex.getCause();
-
-
- if(t instanceof BPELFault) {
-
- BPELFault fault = (BPELFault)t;
-
-
-
-
-
-
- XMLElement faultPayload = (XMLElement)fault.getPart("payload");
-
-
-
-
- }
-
-
- }
import oracle.xml.parser.v2.XMLElement; import com.oracle.bpel.client.ServerException; import com.oracle.bpel.client.BPELFault; try { //invoke the BPEL process using the DeliveryService API. }catch(ServerException ex) { Throwable t = ex.getCause(); if(t instanceof BPELFault) { BPELFault fault = (BPELFault)t; //in the line below, "payload" is the name of the message part. //replace it with the part name that you have defined in the WSDL. //if its a runtime fault, refer to RuntimeFault.wsdl to obtain the //part name. In that case, the payload will be a string value. XMLElement faultPayload = (XMLElement)fault.getPart("payload"); //do processing with payload } }