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 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();
Quick response will be useful.
Environment
Oracle 10g application server