I wrote the below code to send a SOAP request to an endpoint and get the response back. When I ran the code I am getting empty response. May I know what is wrong in my code. Thanks in advance. When I sent the same headers in SOAP UI , I am getting back the correct response. I feel some more logic needs to be added to it
package com.siebel.Webservice;
import java.io.IOException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.MimeHeaders;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPBodyElement;
import javax.xml.soap.SOAPConnection;
import javax.xml.soap.SOAPConnectionFactory;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPHeader;
import javax.xml.soap.SOAPHeaderElement;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPPart;
public class Main {
public static void main(String[] args) throws Exception {
SOAPConnectionFactory sfc = SOAPConnectionFactory.newInstance();
SOAPConnection connection = sfc.createConnection();
String endpoint = "https://mywebsite.org/eai_enu/start.swe?SWEExtSource=WebService&SWEExtCmd=Execute&WSSOAP=1";
SOAPMessage response = connection.call(createSoapEnvelope(), endpoint);
System.out.println(response.getContentDescription());
}
private static SOAPMessage createSoapEnvelope() throws SOAPException {
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
String myNamespace = "arm";
String myNamespaceURI = "http://siebel.com/Webservice";
// SOAP Envelope
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration(myNamespace, myNamespaceURI);
//SOAP Header
SOAPHeader soapheader = envelope.getHeader();
// Create a header block
QName username = new QName("http://siebel.com/webservices", "UsernameToken");
SOAPHeaderElement headerElement = soapheader.addHeaderElement(username);
headerElement.addTextNode("username");
QName password = new QName("http://siebel.com/webservices", "PasswordText");
SOAPHeaderElement headerElement2 = soapheader.addHeaderElement(password);
headerElement2.addTextNode("password");
QName session = new QName("http://siebel.com/webservices", "SessionType");
SOAPHeaderElement headerElement3 = soapheader.addHeaderElement(session);
headerElement3.addTextNode("Stateless");
// SOAP Body
SOAPBody soapBody = envelope.getBody();
SOAPElement soapBodyElem = soapBody.addChildElement("QueryList_Input", myNamespace);
SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("SRNum", myNamespace);
soapBodyElem1.addTextNode("");
try {
System.out.println("Soap message is ");
soapMessage.writeTo(System.out);
System.out.println();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return soapMessage;
}
}