I am writing SOAP client using WSDL. I have similar code in PHP, which works fine. However, I have some problems in Java. Here is my code snippet:
Where should I define the path to my local WSDL file?
Any idea is welcome.
try
{
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection = soapConnectionFactory.createConnection();
SOAPMessage soapResponse = soapConnection.call(mySampleQuery(),
"https://www.webpagename.com");
// Process the SOAP Response
printSOAPResponse(soapResponse);
soapConnection.close();
}
catch (Exception e)
{
System.err.println("Error occurred while sending SOAP Request to Server");
e.printStackTrace();
}
private static SOAPMessage queryFlightsByAerodrome() throws Exception
{
MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
SOAPMessage soapMessage = messageFactory.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
String serverURI = "localfolder/wsdlfilename.wsdl";
// SOAP Envelope
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration("mydata", serverURI);
// SOAP Body
SOAPBody soapBody = envelope.getBody();
SOAPElement soapBodyElem = soapBody.addChildElement("mySampleRequest", "mydata");
SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("userId");
soapBodyElem1.addTextNode("testuser");
//...here I create soapBodyElem1
MimeHeaders headers = soapMessage.getMimeHeaders();
headers.addHeader("SOAPAction", serverURI + "queryTestData");
System.out.println("Content description: "+soapMessage.getContentDescription());
soapMessage.saveChanges();
/* Print the request message */
System.out.print("Request SOAP Message:");
soapMessage.writeTo(System.out);
System.out.println();
return soapMessage;
}
After running this code I get the following error at line SOAPMessage soapResponse = soapConnection.call(mySampleQuery(),"https://www.webpagename.com")
:
Nov 03, 2014 4:18:27 PM com.sun.xml.internal.messaging.saaj.soap.MessageImpl identifyContentType SEVERE: SAAJ0537: Invalid Content-Type. Could be an error message instead of a SOAP message Error occurred while sending SOAP Request to Server com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Invalid Content-Type:text/html. Is this an error message instead of a SOAP response? at com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection.call(Unknown Source) at com.aslogic.isagent.MyAgent.main(MyAgent.java:46) Caused by: com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Invalid Content-Type:text/html. Is this an error message instead of a SOAP response? at com.sun.xml.internal.messaging.saaj.soap.MessageImpl.identifyContentType(Unknown Source) at com.sun.xml.internal.messaging.saaj.soap.MessageFactoryImpl.createMessage(Unknown Source) at com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection.post(Unknown Source)