Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to print a soap message to a file?

694677Apr 14 2009 — edited Apr 15 2009
Hi,

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.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 13 2009
Added on Apr 14 2009
13 comments
1,579 views