I'm trying to create soapMessage so I can move on to the following code snippet later:
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance(); SOAPConnection connection = soapConnectionFactory.createConnection(); SOAPMessage response = connection.call(message, url);
However, I get an empty (null) response: [SOAP-ENV: Body: null].
When I do the following (before calling the connection):
System.out.println(message.getSOAPBody()); message.writeTo(System.out);
I get two different answers when they should be the same, right?
The first system print ln gives me [SOAP-ENV: Body: null], and the other actually gives me a message about the soap that I created (writeTo).
Any ideas why?
Full code:
MessageFactory factory = MessageFactory.newInstance(); SOAPMessage message = factory.createMessage(); SOAPEnvelope envelope = message.getSOAPPart().getEnvelope(); SOAPElement tvl = envelope.addAttribute(new QName("xmlns:tvl"), "http://some.url.com/"); SOAPBody body = message.getSOAPBody(); QName bodyText = new QName("tvl:searchAirings"); SOAPBodyElement bodyElement = body.addBodyElement(bodyText); QName fromTag = new QName("from"); SOAPElement from = bodyElement.addChildElement(fromTag); from.setValue("2012-11-02T14:00:00-4:00"); QName toTag = new QName("to"); SOAPElement to = bodyElement.addChildElement(toTag); to.setValue("2012-11-02T18:00:00-4:00"); QName networkTag = new QName("network"); SOAPElement network = bodyElement.addChildElement(networkTag); network.setAttribute("id", "n501"); network.setAttribute("language", "es"); System.out.println(message.getSOAPBody()); message.writeTo(System.out);
source share