Hi Vinu,
Yes it is possible. The following code demonstrates how you can create a
SOAP message from the contents of a file.
--
Shiva Jayaraman
/**
* creating soap
doc from contents of
* an xml file
*/
import javax.xml.soap.*;
import javax.xml.messaging.*;
import javax.xml.parsers.*;
import javax.xml.transform.dom.*;
import org.w3c.dom.*;
import java.net.*;
import java.io.*;
import java.util.*;
public class SOAPFromFile
{
public static void main(String [] args)
throws Exception
{
String url = "URL-Of-Your-Web-Service";
// Create a SOAP connection to the URL
SOAPConnectionFactory scf =
SOAPConnectionFactory.newInstance();
SOAPConnection sc =
scf.createConnection();
// Create an empty SOAP message
MessageFactory mf =
MessageFactory.newInstance();
SOAPMessage message =
mf.createMessage();
// Get its SOAP part
SOAPPart part = message.getSOAPPart();
// Parse the XML file.
// You can change this code segment to
// parse the xml from a string of
// whatever your source is
DocumentBuilderFactory dbf =
DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder b =
dbf.newDocumentBuilder();
Document d =
b.parse(new File("a.txt"));
// set the content of soap part of
// empty doc from a DOMSource created
// using the document read in...
part.setContent(
new DOMSource(
d.getDocumentElement()));
// To look at your message,
// you can print it.
// message.writeTo(System.out);
// Send the message out to the URL
SOAPMessage response =
sc.call(message, new URLEndpoint(url));
// Print out the response !!!
response.writeTo(System.out);
}
}