Does it mean source and result should both be either DOM or Stream or SAX and not mixed?

M

moralbarometer

Hi all,
I intend to retrieve the fault node as a a string from the soap
message. When i used transform(DOMSource,StreamResult) i get just the
<?xml version="1.0" encoding="UTF-8"?>
as string. but when i use transform(StreamSource,StreamResult) i get
the expected String of fault Node.
where am i wrong?. transform(DOMSource,StreamResult) and
transform(StreamSource,StreamResult) are they different . Does it mean
source and result should both be either DOM or Stream or SAX and not
mixed?
See information below
public String doSerialization(Message soapMsg)
{
StreamSource sourceXSL=new
StreamSource(Thread.currentThread().getClass()
.getClassLoader().getResourceAsStream("de/
AxisFaultProcessor.xsl"));

DOMSource domSource=new
DOMSource(soapMsg.getSOAPEnvelope().getAsDocument());

ByteArrayOutputStream out=new ByteArrayOutputStream();

StreamResult streamResult=new StreamResult(out);

TransformerFactory transformerFactory
=TransformerFactory.newInstance();

Transformer transformer
=transformerFactory.newTransformer(sourceXSL);

transformer.setParameter("action",
"serializeAxisFaultFromSOAPEnvelope");
transformer.setOutputProperty("method", "xml");
transformer.transform(domSource, streamResult);

return out.toString();
}




/// XSL below

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
Transform" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" >
<xsl:param name="action" />
<xsl:template match="/">
<xsl:choose>
<xsl:when test="$action='serializeAxisFaultFromSOAPEnvelope'">
<xsl:copy-of select="soap:Envelope/soap:Body/soap:fault"/>
</xsl:when>
<xsl:eek:therwise>
</xsl:eek:therwise>
</xsl:choose>
</xsl:template>


</xsl:stylesheet>
 
J

Joe Kesselman

moralbarometer said:
When i used transform(DOMSource,StreamResult)

Mixing these should be no problem, so I'm presuming the error is
something else, such as a DOM that isn't providing information this XSLT
processor needs.

Are you absolutely sure soapMsg is a namespace-aware DOM Level 2 DOM
instance? (That is, do the elements have namespaces and localnames, or
only node names?)
 
M

moralbarometer

Hi Joe,
thx for the prompt reply. see below the
i have used for testing the xml below:

<?xml version='1.0' ?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:fault>
<soap:code>
<soap:value>X90</soap:value>
<soap:subcode>
<soap:value>Y90</soap:value>
</soap:subcode>
</soap:code>
<soap:reason>
<soap:text>remote exception occurred during this period</soap:text>
<soap:text>This reason has been logged in our system for further
references please consult with the number ID</soap:text>
</soap:reason>
<soap:detail>
<message>3-Piece luggage set. Black Polyester</message>
<id>100</id>
</soap:detail>
</soap:fault>
</soap:Body>
</soap:Envelope>
 
J

Joseph Kesselman

That isn't what I asked. Yes, your input document uses namespaces. Does
the DOM display them correctly? If not, whatever's building the DOM has
to be fixed.
 
M

moralbarometer

the code below shows how i created the DOMSource
Is there any error in it?
thx

InuputStream confiXML=StreamSource(Thread.currentThread().getClass()
.getClassLoader().getResourceAsStream("de/
SOAP.xml"));

DocumentBuilderFactory
documentBuilderFactory=DocumentBuilderFactory.newInstance();
DocumentBuilder
documentBuilder=documentBuilderFactory.newDocumentBuilder();
Document document=documentBuilder.parse(confiXML);
DOMSource domSource=new DOMSource(document);
 
J

Joseph Kesselman

moralbarometer said:
the code below shows how i created the DOMSource
Is there any error in it?
thx

InuputStream confiXML=StreamSource(Thread.currentThread().getClass()
.getClassLoader().getResourceAsStream("de/
SOAP.xml"));

DocumentBuilderFactory
documentBuilderFactory=DocumentBuilderFactory.newInstance();

// Add this line. (Arguably should be the default these days, but
// generally isn't for historical reasons of compatability with
// ancient code.)
documentBuilderFatory.setNamespaceAware(true);
 
J

Joseph Kesselman

Joseph said:
documentBuilderFatory.setNamespaceAware(true);

Should of course have been ...Factory.set...

(Sorry. Free, typo-free, useful; pick any two.)
 
M

moralbarometer

Hi all,
is namespace enabled when retreiving document from SOAPMessage.
AXIS is used in this case. As shown below
DOMSource domSource=new
DOMSource(soapMsg.getSOAPEnvelope().getAsDocument());
thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top