This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Web Services and the fly likes Generate SOAP message from Java class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Generate SOAP message from Java class" Watch "Generate SOAP message from Java class" New topic
Author

Generate SOAP message from Java class

Atul Mishra
Ranch Hand

Joined: Jun 08, 2006
Posts: 140
Hi All,

In my requirement I have to generate SOAP message from a java class.
The sending portion will be handled by a framework [ our firm has a framework built over JMS], so I just need to create a message only.

I tried to use these methods

MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage message = messageFactory.createMessage();

//Create objects for the message parts
SOAPPart soapPart = message.getSOAPPart();

in a simple program but while running it throws the following exception

xception in thread "main" java.lang.NoClassDefFoundError: com/ibm/ws/ffdc/FFDCFilter
at javax.xml.soap.MessageFactory.newInstance(MessageFactory.java:197)

So, I am thinking I somehow am not proceeding correct.

Can anyone please provide suggestions ?

Thanks
Gaurav Purandare
Greenhorn

Joined: Apr 06, 2009
Posts: 19
No Class Def Found Exeption usually means that the class path was not set properly,
Have you checked that all the libraries are included in classpath.


Gaurav
Atul Mishra
Ranch Hand

Joined: Jun 08, 2006
Posts: 140
Gaurav,

First thanks for the reply.

I have the j2ee.jar added. But the complaint is about an IBM file.

My enironment is eclipse and I dont have [I dont need to have any IBM dependancy]

So thats why I am confused when it threw an IBM related exception

I want to use javax.xml.soap package.

Thanks
Atul Mishra
Ranch Hand

Joined: Jun 08, 2006
Posts: 140
Could anyone please mention on how to generate SOAP message from a Java class.

Thanks
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

Moving to the Web Services forum.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
shivendra tripathi
Ranch Hand

Joined: Aug 26, 2008
Posts: 263
use AXIOM soap api to generate soap envelope. AXIOM is provided by apache and quite handy. following link is useful as well.
http://www.nabble.com/How-to-create-a-soap-envelope-using-AXIOM--to13848521.html
dont forget to keep axiom related jar in class path, otherwise you will get classNotFound exception


SCJP 1.5(97%) My Blog
Atul Mishra
Ranch Hand

Joined: Jun 08, 2006
Posts: 140
use AXIOM soap api to generate soap envelope. AXIOM is provided by apache and quite handy. following link is useful as well.
http://www.nabble.com/How-to-create-a-soap-envelope-using-AXIOM--to13848521.html
dont forget to keep axiom related jar in class path, otherwise you will get classNotFound exception



Thanks for the suggestion, but unfortunately we wont be able to use any external APIs.

Can I achieve this by using SAAJ ?

Thanks
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
You can use SAAJ to create and populate SOAP messages. To make life a little easier, you can use JAXB to marshal and unmarshal the contents of the SOAP body, if you want to. Both these APIs are part of the JRE 6.
The following code shows how to create SOAP messages using SAAJ:

Best wishes!
Atul Mishra
Ranch Hand

Joined: Jun 08, 2006
Posts: 140
Thanks for the code Ivan..

Unfortunately have a 1.5 limitation..

Trying your code now.

Please suggest on additional jars needed if using 1.5

Thanks
Atul
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41144
    
  45
Isn't this kind of the same discussion as this one: http://www.coderanch.com/t/452113/Web-Services/java/SOAP-body-Java-client ? Maybe it should be continued in just one topic?


Ping & DNS - my free Android networking tools app
Summer liki
Greenhorn

Joined: Jul 22, 2009
Posts: 4
in java5, you could add two more jar files: saaj.jar, saaj-api.jar. Then use the code like below:
DocumentBuilder oBuilder = oDocFactory.newDocumentBuilder();
Document oDoc = oBuilder.parse(new File("xxx"));

MessageFactory oMsgFac = MessageFactory
.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
SOAPMessage oMessage = oMsgFac.createMessage();
SOAPBody oBody = oMessage.getSOAPBody();
oBody.addDocument(oDoc);
Atul Mishra
Ranch Hand

Joined: Jun 08, 2006
Posts: 140
The problem I am facing is the company standards
Have anyone use Artix lite to generate SOAP messages ?
 
wood burning stoves
 
subject: Generate SOAP message from Java class
 
Similar Threads
SOAP Request object is null
sending xml file works but converting to SOAP message
Binding XML to Java from SOAP message
How to access byte array web method
SOAP request error