How to print a soap message to a file?
694677Apr 14 2009 — edited Apr 15 2009Hi,
I need to print a soap message to a file. To make it simple, I wrote this code which has just one element. When I run it, nothing is written to the file. Is there anything I need to setup in the JDeveloper tool? Because the same code works when I run it from the command prompt.
import java.io.*;
import javax.xml.soap.*;
public class STest {
public static void main(String[] args) {
try {
File file = new File("output.txt");
OutputStream fos = new FileOutputStream(file);
MessageFactory messageFactory = MessageFactory.newInstance();
//Create a message
SOAPMessage message = messageFactory.createMessage();
SOAPBody body = message.getSOAPBody();
SOAPElement myElement = SOAPFactory.newInstance().createElement("MyElement");
myElement.addTextNode("This is my element");
body.addChildElement(myElement);
message.saveChanges();
message.writeTo(fos);
fos.close();
}
catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
Thanks.