wood burning stoves 2.0*
The moose likes Web Services and the fly likes How to capture SoapRequest.xml and SoapResponse.xml 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 capture SoapRequest.xml and SoapResponse.xml" Watch "How to capture SoapRequest.xml and SoapResponse.xml" New topic
Author

How to capture SoapRequest.xml and SoapResponse.xml

Murali Sridhar
Ranch Hand

Joined: Feb 16, 2009
Posts: 44

Hello,

I have created a Java Webservice(first .WSDL file,then wsdl2Java)using Axis2 stack sucessfully.As I'm using Axis2 stack,it'll creates all the Java beans stuff.

I have written a Webservice Client using Stubs generated from the WSDL in pure Java by creating Request Object ( in Java)then invoking the service, in the Response I got a java object as a bean.
But my requirement is that,I need to get the .XML format for the both SoapRequest and SoapResponse.
Please show me ray to capture the actual SoapRequest.xml and the SoapResponse.xml.

Appreciate your help,


Regards,
Murali
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
As I recall, the AXIS toolkit downloads always come with the TCPMON utility which is designed for this purpose.

Another popular free tool is SOAPui - a google search will find the download location.

Bill
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
Correct me if I am wrong, but as far as I understand your question you want to capture the raw XML SOAP request and response.
If that is the case, then here is what you can do (provided that you are developing in a JAX-WS compliant web service stack):
- On the server side, implement your endpoint implementation class as implementing the javax.xml.ws.Provider<T> interface, using Source, SOAPMessage or DataSource as the type parameter.
Also note that the @ServiceMode annotation will help you choose whether you want to work with the entire message or just the payload (the message in the SOAP body element of a SOAP message).
- On the client side, use javax.xml.ws.Dispatch<T> to send messages that you build yourself in your code.
Best wishes!
Murali Sridhar
Ranch Hand

Joined: Feb 16, 2009
Posts: 44

Thanks for the quick response Bill and Ivan,

I have successfully created the server side endpoint implementation by overriding the interface javax.xml.ws.Provider<SOAPMessage>'s invoke(SOAPMessage request) method,
to get the complete SoapResponse(Complete SoapEnvelope).

At the client side I could not able to create the javax.xml.ws.Dispatch<SoapMessage> object from the wsdl:service class.
Providing the development enviorment as bellow
--------------------------------------------------------------------------------------------
At server side:

@ServiceMode(value= javax.xml.ws.Service.Mode.MESSAGE)

@WebServiceProvider(portName="UpdateServicePortType",serviceName="UpdateService",
targetNamespace="http://service.techc.com/spendingservice/2007/12",
wsdlLocation="/src/schemas/com/techc/spendingservice")

@BindingType(value="http://java.sun.com/xml/ns/javaws/2003/05/soap/binding/HTTP/")

at the client side:
QName serviceName = new QName("http://service.techc.com/spendingservice/", "DataService");
QName portName =new QName("http://service.techc.com/spendingservice/", "spendingservice");
String endpointAddress = "http://localhost:7001/spendingservice";
Service service = Service.create(serviceName);Dispatch<SOAPMessage> dispatchMsg;
public void doInvoke() {
System.out.println("doInvoke");
try {
dispatchMsg = service.createDispatch(portName, SOAPMessage.class, Service.Mode.MESSAGE);
SOAPMessage reqMsg = makeSOAPMessage(alertReq);
System.out.println("SOAPMessage request: " + getSOAPMessageAsString(reqMsg));
SOAPMessage resMsg = dispatchMsg.invoke(reqMsg);
System.out.println("SOAPPMessage response: " + getSOAPMessageAsString(resMsg));
} catch (Exception e) {
e.printStackTrace();
}
}

Providing the wsdl:service
<wsdl:service name="DataService">
<wsdl:port name="spendingservice" binding="DataServiceSoapBinding">
<soap:address location="http://localhost:7001/spendingservice"/>
</wsdl:port>
</wsdl:service>
-------------------------------------------------------------------------------------------------------------------------
Your inputs will help me a lot.

Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
What result/error do you get on the client side?
Murali Sridhar
Ranch Hand

Joined: Feb 16, 2009
Posts: 44

Hi Ivan and Bill,

Please find the error message log:
----------------------------------------------------------------------------------------------------------------------------------------------------------
javax.xml.ws.WebServiceException: {http://service.techc.com/spendingservice/}spendingservice is not a valid port. Valid ports are:
at com.sun.xml.internal.ws.client.WSServiceDelegate.safeGetPort(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.createDispatch(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.createDispatch(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.createDispatch(Unknown Source)
at javax.xml.ws.Service.createDispatch(Unknown Source)
at com.techc.client.action.EditAction.doInvoke(EditAction.java:179)
at com.techc.client.action.EditAction.main(EditAction.java:219)
---------------------------------------------------------------------------------------------------------------------------------------------------------------
@ line:219,the main method invokes client.doInvoke();
@ line:179,as per my understanding,error getting while creating Dispatch object in doInvoke()
code snippet:
dispatchMsg = service.createDispatch(portName, SOAPMessage.class, Service.Mode.MESSAGE);




Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
Yes, the error occurs when you create Dispatch because it seems like there is no <port> element in the service with the name "spendingservice" in the namespace "http://service.techc.com/spendingservice/".
Check the name of the port and the namespace against the WSDL!
Best wishes!
Murali Sridhar
Ranch Hand

Joined: Feb 16, 2009
Posts: 44

Hi Ivan,

I have cross checked that the <port> exists with the name:"spendingservice".Please find the complete Logs:
----------------------------------------------------------------------------------------------------------------------------------------
doInvoke():start..............
javax.xml.ws.WebServiceException: Dispatch creation failed. The {http://service.techc.com/spendingservice/}spendingservice port cannot be found. Verify that the port has been added to the service.
at org.apache.axis2.jaxws.ExceptionFactory.createWebServiceException(ExceptionFactory.java:170)
at org.apache.axis2.jaxws.ExceptionFactory.makeWebServiceException(ExceptionFactory.java:67)
at org.apache.axis2.jaxws.ExceptionFactory.makeWebServiceException(ExceptionFactory.java:115)
at org.apache.axis2.jaxws.description.impl.ServiceDescriptionImpl.updateEndpointDescription(ServiceDescriptionImpl.java:316)
at org.apache.axis2.jaxws.description.impl.DescriptionFactoryImpl.updateEndpoint(DescriptionFactoryImpl.java:220)
at org.apache.axis2.jaxws.description.DescriptionFactory.updateEndpoint(DescriptionFactory.java:94)
at org.apache.axis2.jaxws.spi.ServiceDelegate.createDispatch(ServiceDelegate.java:139)
at javax.xml.ws.Service.createDispatch(Service.java:49)
at com.techc.client.EditAlertClient2.doInvoke(EditAlertClient2.java:86)
at com.techc.client.EditAlertClient2.main(EditAlertClient2.java:129)
doInvoke():end..............
---------------------------------------------------------------------------------------------------
find the spendingservice.WSDL :

<wsdl:service name="DataService">
<wsdl:documentation>
This service supports all the operations needed for the Data Access from the Teradata database.
</wsdl:documentation>
<wsdl:port name="spendingservice" binding="DataServiceSoapBinding">
<soap:address location="http://localhost:7001/spendingservice"/>
</wsdl:port>
</wsdl:service>
----------------------------------------------------------------------------------------------------------
code snippet:
Dispatch<SOAPMessage> dispatchMsg;

QName serviceName = new QName("http://service.techc.com/spendingservice/", "DataService");
QName portName =new QName("http://service.techc.com/spendingservice/", "spendingservice");
String endpointAddress = "http://localhost:7001/spendingservice";
Service service = Service.create(serviceName);

public void doInvoke() {
System.out.println("doInvoke():start..............");
try {
dispatchMsg = service.createDispatch(portName, SOAPMessage.class, Service.Mode.MESSAGE);
SOAPMessage reqMsg = makeSOAPMessage(editAlertRequest);
System.out.println("SOAPMessage request: " + getSOAPMessageAsString(reqMsg));
SOAPMessage resMsg = dispatchMsg.invoke(reqMsg);
System.out.println("SOAPPMessage response: " + getSOAPMessageAsString(resMsg));

} catch (Exception e) {
e.printStackTrace();
}
System.out.println("doInvoke():end..............");
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to capture SoapRequest.xml and SoapResponse.xml
 
Similar Threads
AXIS 1.4.1 compatability with Statefull Web Services
unable to create java client stub for .net webservice
Web Service Initialization Parameters
Axis2 contract first code
creating wsdl first and then webservice