• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Convert SOAP response to SOAP XmL string using JAX WS

 
Nikita Dutt
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13073
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
H Paul
Ranch Hand
Posts: 471
4
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 471
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 471
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic