Solved

Java/Web Services Question Convert SOAP response to String

Posted on 2011-02-11
5
1,246 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

828 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