I'm trying to pass an xml in the body of a Soap request.
my problem is that i can't get the exact structure i need.
i need the body to be in the structure of: <soap:Body> xmlString </soap:Body>.
I know of 2 ways to set the SOAP request body:
1 . body.addBodyElement(envelope.createName(xmlString));
this create a structure of <soap:Body> < xmlString > </soap:Body> which isn't what i want. (surrounds the string's content with <> )
2 . SOAPBody sb = sm.getSOAPBody();
sb.addTextNode(xmlString);
this creates the desired structure but completely mess up the xml characters, replacing spaces and <> in things such <.
my code is :
SOAPConnectionFactory sfc = SOAPConnectionFactory.newInstance();
SOAPConnection connection = sfc.createConnection();
MessageFactory mf = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
SOAPMessage sm = mf.createMessage();
sm.getSOAPPart().getEnvelope().setPrefix("soap");
sm.getSOAPPart().getEnvelope().removeNamespaceDeclaration("env");
sm.getSOAPHeader().setPrefix("soap");
sm.getSOAPBody().setPrefix("soap");
SOAPBody sb = sm.getSOAPBody();
sb.addTextNode(xml);
System.out.println("\n Soap Request:\n");
sm.writeTo(System.out);
System.out.println();
is there any way to get it to be in the format i need? thanks
No comments:
Post a Comment