Reputation: 1264
I am building Java
application for Online Web Services
and let's call it application A
. I got the WSDL
file form the second party so I can communicate with their application and let's call it application B
.
From the WSDL
file I generate the Java
classes needed which are Requests
and Responses
classes. Application A
will send some request
object after setting the needed parameters and excepting response
object from application B
.
The connection is established and both applications A and B
are communicating with each other.
Question:
From application A
how can I get the xml
data(file or text) for the request
object before sending it to application B
?
As described the connection is done by passing Java
object as request
and I know that in some point this request
will be converted to xml
file. How to get it?
--- EDIT ----
Important Information is missing that may cause confusion.
I am generated the Java
Classed have been generated using Axis
framework
Upvotes: 2
Views: 5955
Reputation: 1264
The problem is solved by adding the following statements in the bindingStub
class that has been auto generated from the WSDL
file for the web-services
you are trying to access.
String request = _call.getMessageContext().getRequestMessage().getSOAPPartAsString();
String response = _call.getMessageContext().getResponseMessage().getSOAPPartAsString();
These statements should be placed after the following method call _call.invoke
otherwise you will get NullPointerException
.
_call
is a variable of type org.apache.axis.client.Cal
and it is auto generated by Axis
Upvotes: 2
Reputation: 170
I don't have much reputation to post a comment, so here is my answer: If you aren't yet using some framework use Apache CXF, If you want to capture the request before sending it application , you can either use cxf interceptors there are some inbuilt interceptors which can do this or you can create a custom interceptor with correct phase ( e.g. post marshal)
Upvotes: 2