• Post Reply Bookmark Topic Watch Topic
  • New Topic

Error while parsing SOAP response message

 
priyadarsini darsini
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We are getting error java.lang.ClassCastException: oracle.j2ee.ws.saaj.soap.TextImpl cannot be cast to javax.xml.soap.SOAPElement while parsing SOAP response message.

Below java code is for your reference.

<%@page import="javax.xml.soap.*,javax.xml.parsers.*"%>

SOAPConnectionFactory CF = SOAPConnectionFactory.newInstance();
SOAPConnection soapC = CF.createConnection();
MessageFactory MF = MessageFactory.newInstance();
SOAPMessage soapMsg = MF.createMessage();
SOAPPart soapP = soapMsg.getSOAPPart();
SOAPEnvelope soapE = soapP.getEnvelope();

try {

soapE.addNamespaceDeclaration("urn","urn:sap-com:document:sap:rfc:functions");
SOAPBody soapB = soapE.getBody();
SOAPElement soapEle = soapB.addChildElement("Z_RAP_BAPI_PO_GETDETAILS","urn");
SOAPElement soapEle1 = soapEle.addChildElement("PURCHASEORDER");
soapEle1.addTextNode("4100528320");

MimeHeaders MH = soapMsg.getMimeHeaders();
MH.addHeader("SOAPAction","http://sap.com/xi/WebService/soap1.1");

soapMsg.saveChanges();

System.out.println("Request SOAP message");
soapMsg.writeTo(System.out);

SOAPMessage soapResponse = soapC.call(soapMsg,"http://sappidev...");
System.out.println("Response SOAP message");
soapResponse.writeTo(System.out);

SOAPElement ele = (SOAPElement)(soapResponse.getSOAPBody().getChildElements().next());

out.println(ele.getValue());

}
catch(Exception e) { out.println("::::::::Exception::::::::::::::"+e); }

soapC.close();

thanks in advance.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

For starters, you should never blindly call "next()" on an Iterator. Always check whether there *is* a next object.

According to the javadocs of the getChildElements() method, the Iterator doesn't necessarily return javax.xml.soap.SOAPElement objects; it can also return javax.xml.soap.Text objects (and the error message indicates that this is the case here). So your code needs to handle both cases.
 
priyadarsini darsini
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your quick response.

soapMsg.writeTo(System.out);


Request SOAP message
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:sap-com:document:sap:rfc:functions">
<env:Header/>
<env:Body>
<urn:Z_RAP_BAPI_PO_GETDETAILS><PURCHASEORDER>4100528320</PURCHASEORDER></urn:Z_RAP_BAPI_PO_GETDETAILS>
</env:Body>
</env:Envelope>


SOAPMessage soapResponse = soapC.call(soapMsg,"http://sappidev...");
soapResponse.writeTo(System.out);
we are getting SOAP response in the below format.
Now we need to extract data like BUSINESSAREA,COMPANYCODE etc.. from the response and same should be displayed to the end user.

Response SOAP message
<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP:Body>
<ns0:Z_RAP_BAPI_PO_GETDETAILS.Response xmlns:ns0="urn:sap-com:document:sap:rfc:functions">
<BUSINESSAREA>1000</BUSINESSAREA>
<COMPANYCODE>1000</COMPANYCODE>
<CREATEDON>2012-11-01</CREATEDON>
<CREATERNAME>PARTNER-RLL</CREATERNAME>
<DIVISION>302</DIVISION>
<ERROR_DESC/>
<PAYTERMS>Z037</PAYTERMS>
<VENDOR>1100008870</VENDOR>
</ns0:Z_RAP_BAPI_PO_GETDETAILS.Response>
</SOAP:Body>
</SOAP:Envelope>
 
g tsuji
Ranch Hand
Posts: 697
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This gets you started. If you cannot read the meaning of each line nearly immediately, consider fall back to learn or to get familiarize with some dom code before you tackle these kinds of things.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!