Solved

Java/Web Services Question Convert SOAP response to String

Posted on 2011-02-11
5
1,276 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Suggested Courses

740 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