wood burning stoves 2.0*
The moose likes Web Services and the fly likes How to get SOAP request XML for a web service call Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "How to get SOAP request XML for a web service call" Watch "How to get SOAP request XML for a web service call" New topic
Author

How to get SOAP request XML for a web service call

Jitesh Sinha
Ranch Hand

Joined: Jun 19, 2004
Posts: 146
I have a standalone Java application running on a remote machine that consumes a web service.The web service is developed by some other group of organization.The standalone java code that consumes web service was written by me and then put on a remote machine.For this post's purpose,let us assume,this standalone java code is executed by a background script periodically.

I need to know the SOAP request XML that is being sent by this standalone Java application.There is some issue with the way my standalone java code is calling web service and I need to debug this.
Somehow,my code is not able to get proper response from web service and I need to know why.I am ok with writing some Java code to achieve this.

I have done enough research on net and this is my last resort.I looked at tcpmon,soapui,fiddler - none of them can be used here since there is no client side URL or port!
This is really urgent.If some one can help me quickly,it will really be appreciated.
Thanks!!
Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1180
More efficient ways of debugging SOAP based Web Services from PHP ... might help...

William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12821
    
    5
there is no client side URL or port!


This is the client that you wrote we are talking about? How do you make a SOAP request without a URL or port?

If you can't get at the remote machine to use SOAPui or similar, and the web service is not under your control, what CAN you get at?

Bill
Jitesh Sinha
Ranch Hand

Joined: Jun 19, 2004
Posts: 146
William Brogden wrote:
there is no client side URL or port!


This is the client that you wrote we are talking about? How do you make a SOAP request without a URL or port?

If you can't get at the remote machine to use SOAPui or similar, and the web service is not under your control, what CAN you get at?

Bill

William,that is right.

How do you make a SOAP request without a URL or port?

My code is a standalone code that needs to read messages from a JMS queue.It reads the message and call the Web Service.Why does Client code need to have URL or port?

If you can't get at the remote machine to use SOAPui or similar, and the web service is not under your control, what CAN you get at?
That is where I need help - What do I do here?

William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12821
    
    5
Are you saying that the web service is not responding to HTTP SOAP requests but to JMS SOAP messages?

If so, can you get at the configuration of the JMS server or otherwise change the configuration so that the JMS message exchange is no longer point-to-point but publish-subscribe? That way you could run a separate process subscribing to all of the requests and responses.

My code is a standalone code that needs to read messages from a JMS queue.It reads the message and call the Web Service.Why does Client code need to have URL or port?


"Client code" - I am getting confused here - how many entities are we talking about? Which ones can you add debugging code to?

If the "web service" is responding to HTTP requests, there must, by definition, be a port and url involved.

Bill
Jitesh Sinha
Ranch Hand

Joined: Jun 19, 2004
Posts: 146
William Brogden wrote:Are you saying that the web service is not responding to HTTP SOAP requests but to JMS SOAP messages?

If so, can you get at the configuration of the JMS server or otherwise change the configuration so that the JMS message exchange is no longer point-to-point but publish-subscribe? That way you could run a separate process subscribing to all of the requests and responses.

My code is a standalone code that needs to read messages from a JMS queue.It reads the message and call the Web Service.Why does Client code need to have URL or port?


"Client code" - I am getting confused here - how many entities are we talking about? Which ones can you add debugging code to?

If the "web service" is responding to HTTP requests, there must, by definition, be a port and url involved.

Bill


Sorry if I got you confused.Web service that my code accesses does have URL and port.My code is client code (since it accesses web service) and it is a standalone Java program.This Java program cannot be accesses through a URL/port.Let me know if you have any more questions.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12821
    
    5
my code accesses does have URL and port.My code is client code (since it accesses web service) and it is a standalone Java program.This Java program cannot be accesses through a URL/port


This statement makes no sense. You wrote code that "does have URL and port" but "cannot be accesses through a URL/port"

Either it makes use of a URL or not!

It sounds to me like you could create a sort of proxy application - change the URL in your client to point to the proxy - proxy would record the entire SOAP request message and send it on to the web service - receive the response, log it, and send it on to your client.

Bill
Jitesh Sinha
Ranch Hand

Joined: Jun 19, 2004
Posts: 146
William Brogden wrote:
my code accesses does have URL and port.My code is client code (since it accesses web service) and it is a standalone Java program.This Java program cannot be accesses through a URL/port


This statement makes no sense. You wrote code that "does have URL and port" but "cannot be accesses through a URL/port"

Either it makes use of a URL or not!

It sounds to me like you could create a sort of proxy application - change the URL in your client to point to the proxy - proxy would record the entire SOAP request message and send it on to the web service - receive the response, log it, and send it on to your client.

Bill


Well,any web service is bound to have URL and port.My code consumes one of the web services.
Coming to your second part - you mean to say - I need to create a proxy application?How do I do that?
And this proxy application will call the actual web service?These are too many unknowns to me.But I think you are coming to the right point - because someone else in my office was talking something like that - but he won't help in figuring out minute details.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12821
    
    5
Right! The normal way to monitor the exact text sent and received by a SOAP client would be SOAPui or TCPMON, but as I understand it, you cant use them because your client is remote and both of those require user window input.

One possibility would be to set up the remote machine to work with Microsoft's Remote Desktop so you could run SOAPui or TCPMON as if you were looking at the remote machine's desktop. This works surprisingly well.

If not, you need to create the same functionality but with logging instead of a GUI interface.

Essentially the SOAP client would address a localhost port which your proxy would answer, capture the complete request, log it and then send it to the actual web service address. This is going to involve you in Java socket programming and multiple Threads.

You might want to download the TCPMON code for inspiration and study.

Bill
Jitesh Sinha
Ranch Hand

Joined: Jun 19, 2004
Posts: 146
Those are very high level details - I was looking for a code example that I can use for my case.
Jitesh Sinha
Ranch Hand

Joined: Jun 19, 2004
Posts: 146
Can I get help from someone?
Naren Mane
Greenhorn

Joined: Mar 02, 2011
Posts: 16

Hi Jitesh,

Let us see if this approach helps you.

You wrote that you are consuming a webservice in your code.
My question is : Are you consuming through a wsdl or it is a restful-ws ?
********************************************************************************************************
If you have a wsdl then one of the easiest way is to use wsdl2java tool in Apache Axis2.
Using this wsdl2java tool you can generate wsdl-mapped java classes(i.e. stub), which you can use in your client code.
One more important advantage with this approach is within this stub you can put sysouts to print the soap requests and responses.

Or you can obtain wsdl by appending "?wsdl" to your webservice URL. If you put this entire URL in IE or firefox you should see a wsdl doc. If you go successful then you can use same URL to generate java stubs.
********************************************************************************************************
And if you are using restful-ws then approach would be different one .
********************************************************************************************************
So first clarify on the things above then we can proceed further.
Jitesh Sinha
Ranch Hand

Joined: Jun 19, 2004
Posts: 146
I am using soap web service and I have generated Java classes using wsdl.Where and how do I put sysouts to get soap xml?
Naren Mane
Greenhorn

Joined: Mar 02, 2011
Posts: 16

Hi Jitesh,

OK as you told you are using a wsdl to generate java classes, then one approach to see soap request and response logs is to use APACHE AXIS2 to generate java stubs(i.e. use wsdl2java tool).
*******************************************************************************************************
This java stub will contain auto-generated methods that are mapped to wsdl you used to generate java stub. In each method you will find something like :


org.apache.axiom.soap.SOAPEnvelope env = null;
env = toEnvelope(.....some auto-generated signature here.....);
//Add sysout to print SOAP request log
System.out.println("SOAP Request: "+env.getBody());
.....
.....
.....
org.apache.axiom.soap.SOAPEnvelope _returnEnv = _returnMessageContext.getEnvelope();
//Add sysout to print SOAP response log
System.out.println("SOAP Response: "+_returnEnv.getBody());

*******************************************************************************************************
Remember this logic is feasible only if you have a java stub generated using wsdl2java tool from Apache Axis2.
Let me know if this approach helps you .
Jitesh Sinha
Ranch Hand

Joined: Jun 19, 2004
Posts: 146
Thanks Naren - it makes sense.I will see if it can be done.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get SOAP request XML for a web service call