I am trying to make a program which sends data to web service but I am getting an error. While compiling, I am not getting error but only at runtime, I am getting the error.
Error
Why this error is coming ?
Code:
import java.util.Iterator;
import javax.xml.soap.*;
import javax.xml.transform.*;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Node;
public class CallWebServiceAdd {
public static void main(String[] args) {
// TODO code application logic here
String a = "10";
String b = "20";
String op = "Addweb";
String urn = "WebService1";
String dest = "http://delecc01.india.jcb.local:8000/sap/bc/srt/wsdl/srvc_002655F3F9821EE5ACEC62338B931F00/wsdl11/allinone/ws_policy/document?sap-client=101";
try
{
SOAPConnectionFactory soapConnFact = SOAPConnectionFactory.newInstance();
SOAPConnection conn = soapConnFact.createConnection();
MessageFactory msgFact = MessageFactory.newInstance();
SOAPMessage msg = msgFact.createMessage();
String authorization = new sun.misc.BASE64Encoder().encode(("username:password").getBytes());
SOAPPart soapPart = msg.getSOAPPart();
SOAPEnvelope envelop = soapPart.getEnvelope();
envelop.addNamespaceDeclaration("xsd", "http://www.w3.org/2001/XMLSchema");
SOAPBody body = envelop.getBody();
SOAPElement bodyelement = body.addChildElement("Addition");
SOAPElement bodyelement1 = bodyelement.addChildElement("a").addTextNode(a);
SOAPElement bodyelement2 = bodyelement.addChildElement("b").addTextNode(b);
MimeHeaders headers = msg.getMimeHeaders();
headers.addHeader("SOAPAction", "#OP_IF_OP_ZTEST_ALL");
headers.addHeader("Authorization", "Basic " + authorization);
msg.writeTo(System.out);
msg.saveChanges();
SOAPMessage reply = conn.call(msg, dest);
soapPart = reply.getSOAPPart();
envelop = soapPart.getEnvelope();
body = envelop.getBody();
Iterator iter = body.getChildElements();
Node resultOuter = ((Node)iter.next()).getFirstChild();
Node result = resultOuter.getFirstChild();
System.out.println("add(" + a + ","+ b + ") = " + result.getNodeValue());
reply.writeTo(System.out);
conn.close();
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
}
Error
Code:
Jan 06, 2
016 3:27:07 PM com.sun.xml.internal.messaging.saaj.soap.SOAPPartImpl lookForEnve
lope
SEVERE: SAAJ0514: Unable to create envelope from given source because the root e
lement is not named Envelope
Jan 06, 2016 3:27:07 PM com.sun.xml.internal.messaging.saaj.soap.EnvelopeFactory
createEnvelope
SEVERE: SAAJ0511: Unable to create envelope from given source
Unable to create envelope from given source:
Why this error is coming ?