Solved

Java/Web Services Question Convert SOAP response to String

Posted on 2011-02-11
5
1,185 Views
Last Modified: 2012-05-11
Here is what I am looking to do. I have some java code that calls a web service. I know the response, at some point, is a SOAP message. Is there some way to extract this soap message as a string. Something like

WebServiceResponse res  = ws.getWebServiceInfo()
String targetString = res.SOAPString()

Where targetString would be a string containing the SOAP message.

Thanks in advance for the help,
Matt




0
Comment
Question by:mattjankowski
  • 3
5 Comments
 
LVL 17

Expert Comment

by:Dejan Pažin
ID: 34877242
0
 
LVL 47

Expert Comment

by:for_yan
ID: 34883632

Well, if above links work for you, then it is fine, though it does not look
that they give all the eaxct instructions.

Below is the inforamtion about what seems to be much more painful way to do it
using mule. It looks like it is a big deal, but
there seem to be enough instructions.
Don't know maybe someone would suggest a much simpler solution.
If not, maybe it is worth playing with mule, if there is a real need to do it.

It looks like this mule software could help you with this.

This is where you get the library - click on .jars to download - it
is only about  4 MB
http://www.mulesoft.org/download-mule-esb-community-edition

And this is the post which describes it more or less
and points to particular code example:
(from http://mule.1045714.n5.nabble.com/Extracting-a-SOAP-Body-from-a-FILE-td2678533.html)

-------------------------
In reply to this post by tha
Hey Thomas,

This might help you out:

http://www.mulesource.org/display/SAAJ/Home

It provides a pair of transformers to extract the contents of and populate SOAP messages.  I'm still working on putting a proper release together, but  you should be able to checkout trunk from here:

http://svn.muleforge.org/saaj/trunk/

and use "mvn clean package" to get a JAR file to drop in $MULE_HOME/lib/user.

I added an example that illustrates how to extract the payload from SOAP messages in a directory here:

http://www.mulesource.org/display/SAAJ/Extracting+XML+from+SOAP+Messages

This will pull the SOAP headers out of your messages, set them as message properties and set the message payload as the SOAP body's XML.

I hope to have the release ready in the next few days..

Cheers,
-jd
---------------------------------




0
 

Author Comment

by:mattjankowski
ID: 34888387
Ok,

Specific instructions are always better, but I am looking into both of the previous posts as possible solutions. Hopefully I can get back to EE later today with which one works out the easiest.

Thanks,
Matt
0
 

Accepted Solution

by:
mattjankowski earned 0 total points
ID: 34897861
A colleague pointed out this solution to me:

System.out.println(res.getOMElement(null,null).toString());

The entire soap message is not printed out, but all the elements and their associated tags are.  
0
 

Author Closing Comment

by:mattjankowski
ID: 34936410
Thank you both for your help with the comments. The solution wound up to be the cleanest and easiest way to do it.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to implement Singleton Design Pattern in Java.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now