• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
  • Tim Holloway
  • Piet Souris
  • Frits Walraven


Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,
I'm using the Soap w/ Attachments API to construct and send SOAP messages. Using SAAJ, I have to constuct individual elements and messages. But, If I have a SOAP request already constructed as a String object, is there way to wrap this String as a SOAPMessage and send it as it is?
Any help is greatly appreciated.
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 =
SOAPConnection sc =
// Create an empty SOAP message
MessageFactory mf =
SOAPMessage message =
// 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 =
DocumentBuilder b =
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...
new DOMSource(
// 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 !!!
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow! That wasy very helpful. I just spent an hour this morning searching the Internet for just such an example.
Thanks, Shiva!
Seriously? That's what you're going with? I prefer this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!