File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Services and the fly likes Convert SOAP response to SOAP XmL string using JAX WS Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Convert SOAP response to SOAP XmL string using JAX WS " Watch "Convert SOAP response to SOAP XmL string using JAX WS " New topic
Author

Convert SOAP response to SOAP XmL string using JAX WS

Nikita Dutt
Greenhorn

Joined: Dec 24, 2010
Posts: 20
Hi All,


I have a requirement where in have to convert the JAX-WS SOAP response to a SOAP XML string. Have goggled but couldn't find any way . the client program-me who will invoke the web-service wants to convert the Java Object of response to SOAP XML string. I am using sun Java1.6


Please help


thanks in advance
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12823
    
    5
A valid SOAP response should already be a valid XML document - thats the whole idea.

If this was my problem the first thing I would do would be to use SOAPui or TCPMON to capture the SOAP response.

Bill
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
If the response is something that can be fed into a XSLT transformer, then all you need to do is apply a null transform according to the following example:

Best wishes!


My free books and tutorials: http://www.slideshare.net/krizsan
H Paul
Ranch Hand

Joined: Jul 26, 2011
Posts: 471
    
    4
1. Some one once said, "A medicine is vitamine for one man and a poison for another."
Well, it's a vitamine for me. I just picked it up. Thanks.
theXFormer.setOutputProperty(OutputKeys.INDENT, "yes");

2. Am a beginner. Here is my guess work:
If the web service client is implemented with JAX-WS, then code-wise you need a protocol handler by implementing the SOAPHandler<SOAPMessageContext>
where you can log out the whole soap message. (Monitoring-wise, this is already suggested by TCPMon or SOAP UI. )

import javax.xml.ws.handler.soap.SOAPHandler;
import javax.xml.ws.handler.soap.SOAPMessageContext;

This handler will intercept the incoming SOAP message from your service provider before it is become a Java objects via JAXB for you to manipulate.

3. If none of above help, then you just explain again. I'm sure there are many expert will help you.

Nikita Dutt
Greenhorn

Joined: Dec 24, 2010
Posts: 20
Thanks Paul,

As you said "need a Protocol Handler" ; which i was able to write , inline the source code of the same ; this logic will push the SOAP request / response to standard console.








Nikita Dutt
Greenhorn

Joined: Dec 24, 2010
Posts: 20
Thanks Paul,

As you said "need a Protocol Handler" ; which i was able to write , inline the source code of the same ; this logic will push the SOAP request / response to standard console.







That's all i needed , thanks to all of you
Yogesh Gandhi
Ranch Hand

Joined: Dec 05, 2008
Posts: 212
Dear All,
I had written the 2 classes given by Nikita above.
And I have associated the service class with the handler as follows

HandlerResolver myHandlerResolver = new MyHanlderResolver();
service.setHandlerResolver(myHanlderResolver);

But, no XML is being printed in System out logs. I am using websphere application server.

Can anyone please help me?
H Paul
Ranch Hand

Joined: Jul 26, 2011
Posts: 471
    
    4
I once played with and noticed below:

1. If you want to log the SOAP request or response:

A. Without using any code from you: do a configuration
-For GF31 SERVER
com.sun.xml.ws.transport.http.client.HttpTransportPipe.dump=true
-For Websphere, it also has it.
I don't remember, I once set it. Once I found it, I will put it.
You can ask Websphere Forum.
EDITED: here is http://www.ibm.com/developerworks/websphere/library/techarticles/0803_adams/0803_adams.html

-For Web logic, it also has it.

Just GOOGLE, you will have it because this is already by other people.

-Even JAX-WS CXF version, it has:



B. Using code: See August 21, 2011 11:39:25 PM
1. Then either programmatically like in August 21, 2011 11:39:25 PM
OR
2. Configure it.

=====================================================

So for your WebSphere, you have 2 choices as described above.
As usual, see Redbook for your app version and/or websphere forum or GOOGLE.
Yogesh Gandhi
Ranch Hand

Joined: Dec 05, 2008
Posts: 212
I tried the solution given by Nikita on a sample web service in net beans.
It works without any problem (both on client side and server side).

And this property

System.setProperty("com.sun.xml.ws.transport.http.client.HttpTransportPipe.dump", "true");

is already set in my case for websphere. But still I didnt' get anything in logs. I will again try this tomorrow.

Also, is there a way where I can store the XML in database. Presently it is sending it to System.out
H Paul
Ranch Hand

Joined: Jul 26, 2011
Posts: 471
    
    4
1. For WS: I just edited: http://www.ibm.com/developerworks/websphere/library/techarticles/0803_adams/0803_adams.html

2. (The answer is your Patience. :-D)
Yogesh Gandhi
Ranch Hand

Joined: Dec 05, 2008
Posts: 212
Yes, Thanks to Nikita who posted this code here.
I am able to make good use of it. Finally it worked for me.

Here is the detailed post of what I did.

http://javakafunda.blogspot.in/2012/04/how-to-log-soap-request-and-response.html

To convert SOAPMessage to a String you can use

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Convert SOAP response to SOAP XmL string using JAX WS