I wrote a web service client to generate a
soap request and make a soap call to server. I m getting the below error .
But when i use the same request that is generated using code and post in soapUI , I m getting response .
The error i get is :
com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection post
SEVERE: SAAJ0008: Bad Response; Bad request
Error occurred while sending SOAP Request to Server
com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Bad response: (400Bad request
at com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection.call(Unknown Source)
at SeibelClient.main(SeibelClient.java:58)
Caused by: com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Bad response: (400Bad request
at com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection.post(Unknown Source)
... 2 more
CAUSE:
com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Bad response: (400Bad request
at com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection.post(Unknown Source)
at com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection.call(Unknown Source)
at SeibelClient.main(SeibelClient.java:58)
CAUSE:
com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Bad response: (400Bad request
at com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection.post(Unknown Source)
at com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection.call(Unknown Source)
at SeibelClient.main(SeibelClient.java:58)
The program that i used is as below:
import javax.xml.namespace.QName;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.MimeHeaders;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPConnection;
import javax.xml.soap.SOAPConnectionFactory;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPHeader;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPPart;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.ws.WebServiceException;
public class SeibelClient {
public static void main(
String args[]){
try {
System.out.println("**********************************************************");
// Create SOAP Connection
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory
.newInstance();
SOAPConnection soapConnection = soapConnectionFactory
.createConnection();
String url ="http://hostname:8002/eai_enu/start.swe?SWEExtSource=WebService&SWEExtCmd=Execute&WSSOAP=1";
try{
SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(),
url);
printSOAPResponse(soapResponse);
}catch(WebServiceException e){
e.printStackTrace();
}
soapConnection.close();
} catch (Exception e) {
System.err
.println("Error occurred while sending SOAP Request to Server");
e.printStackTrace();
}
}
private static SOAPMessage createSOAPRequest() throws Exception {
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
soapMessage.setProperty(SOAPMessage.WRITE_XML_DECLARATION, "true");
soapMessage.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, "UTF-8");
//soapMessage.setProperty(SOAPMessage., arg1);
SOAPPart soapPart = soapMessage.getSOAPPart();
String serverURI = "http://xmlns.oracle.com/yyy";
// SOAP Envelope
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration("cus", "http://xxx.com/CustomUI");
envelope.addNamespaceDeclaration("cmit", "http://xmlns.oracle.com/yyy");
envelope.addNamespaceDeclaration("cus1", "http://xxx.com/webservices");
SOAPHeader header = envelope.getHeader();
//SOAPElement authElem = header.addChildElement("AuthenticationInfo",
//"urn");
QName name = new QName("xmlns");
QName user = new QName("UsernameToken");
QName pwd = new QName("PasswordText");
// QName nillable = new QName("nillable");
//authElem.addAttribute(name, "AuthenticationInfo");
SOAPElement authEle1 = header.addChildElement("UsernameToken","cus1");
authEle1.addTextNode("zzz");
SOAPElement authEle2 = header.addChildElement("PasswordText","cus1");
authEle2.addTextNode("zzz$");
// SOAP Body
SOAPBody soapBody = envelope.getBody();
//soapBody.addNamespaceDeclaration("cus", serverURI);
SOAPElement soapBodyElem = soapBody.addChildElement(
"Process_Input", "cus");
SOAPElement elemOne = soapBodyElem.addChildElement(
"Process_spcInstance_spcId", "cus");
elemOne.addTextNode("");
SOAPElement elemTwo = soapBodyElem.addChildElement(
"Object_spcId", "cus");
elemTwo.addTextNode("");
SOAPElement elemThree = soapBodyElem.addChildElement(
"Siebel_spcOperation_spcObject_spcId", "cus");
elemThree.addTextNode("");
SOAPElement elemNext = soapBodyElem.addChildElement(
"CMITelematicsRequestMsg", "cmit");
SOAPElement elem1 = elemNext.addChildElement(
"Engine_Serial_Number", "cmit");
elem1.addTextNode("46452657");
SOAPElement elem2 = elemNext.addChildElement(
"VIN", "cmit");
elem2.addTextNode("TSV0037859389");
SOAPElement elem3 = elemNext.addChildElement(
"Fault_Code", "cmit");
elem3.addTextNode("EN202928808829");
SOAPElement elem4 = elemNext.addChildElement(
"Fault_Code_Description", "cmit");
elem4.addTextNode("TEST FAULT");
SOAPElement elem6 = elemNext.addChildElement(
"Customer_Email", "cmit");
elem6.addTextNode("aluu7834@yahoo.com");
SOAPElement elem7 = elemNext.addChildElement(
"Service_Model_Name", "cmit");
elem7.addTextNode("C8.3");
SOAPElement elem8 = elemNext.addChildElement(
"Customer_ID", "cmit");
elem8.addTextNode("33453933");
MimeHeaders headers = soapMessage.getMimeHeaders();
headers.addHeader("SOAPAction", serverURI + "yyy");
soapMessage.saveChanges();
// Print the request message
System.out.print("Request SOAP Message = ");
soapMessage.writeTo(System.out);
System.out.println();
return soapMessage;
}
/**
* Method used to print the SOAP Response
*/
private static void printSOAPResponse(SOAPMessage soapResponse)
throws Exception {
TransformerFactory transformerFactory = TransformerFactory
.newInstance();
Transformer transformer = transformerFactory.newTransformer();
Source sourceContent = soapResponse.getSOAPPart().getContent();
System.out.print("\nResponse SOAP Message = ");
StreamResult result = new StreamResult(System.out);
transformer.transform(sourceContent, result);
}
}
Please help me in solving the problem.