It's not a secret anymore!*
The moose likes Web Services and the fly likes capture request and response to/from webservice Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "capture request and response to/from webservice" Watch "capture request and response to/from webservice" New topic
Author

capture request and response to/from webservice

aditi ray
Greenhorn

Joined: Nov 08, 2006
Posts: 13
How can we log request and response to/from a webservice.do i have to write the code in the webservice or do i need to implement another application for it.

I would prefer to do that in same webservice.Can someone help ?
gopinathang nathan
Ranch Hand

Joined: Oct 28, 2006
Posts: 41
you can use '-Dweblogic.webservice.verbose=true' in WLS 8.1. or you can use the tools like tcpmon to capture explicitly.
Paulo Salgado
Ranch Hand

Joined: Jan 18, 2002
Posts: 98
Hi Aditi.

Considering you will be using JAX-RPC (or the new JAX-WS) or even Apache Axis, one way of logging your requests and responses is by implementing a Message Handler for that purpose. A Message Handler acts like a Servlet Filter, i.e., it intercepts your request before it reaches its destination (the endpoint) and intercepts the response before it is returned to the caller (the WS client). Both are very good times to log what is going back and forth.

You can write your Message Handler to use your favorite logging API, get the XML contents and post them to a log file.

I personally would recommend you to create a JAX-RPC (or JAX-WS) compliant Message Handler because that would make it reusable to any JAX-RPC compliant SOAP engine. And that means you could potentially use the same logging Message Handler on the client, on the server and on other applications. All you have to do is deploy it to the desired Web Service once it's complete.

Regards.
aditi ray
Greenhorn

Joined: Nov 08, 2006
Posts: 13
import java.io.BufferedWriter;
import javax.xml.namespace.QName;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import javax.xml.rpc.handler.Handler;
import javax.xml.rpc.handler.HandlerInfo;
import javax.xml.rpc.handler.MessageContext;
import javax.xml.rpc.handler.soap.SOAPMessageContext;
import javax.xml.namespace.QName;
import java.util.Iterator;
import org.omg.CORBA.*;



public class messageHandler implements Handler
{



public void destroy()
{

}


public QName[] getHeaders()
{
//return null;
return handlerInfo.getHeaders();
}

public boolean handleFault(MessageContext arg0)
{

}

public boolean handleRequest(MessageContext arg0)
{

}

public boolean handleResponse(MessageContext arg0)
{

}

public void init(HandlerInfo arg0)
{
handlerInfo = arg0;
}
}

I have implemented the above class to get request and response but not sure how to invoke it through web service code.I am using weblogic 8.1.

Do i need to define in web.xml or there is any other way.Please help
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42946
    
  70
Not in web.xml - it has nothing to do with servlet. You need to consult your Weblogic documentation about where handlers are declared. (For Axis, there is a deployment descriptor where this stuff goes, but Weblogic may work differently.)
Paulo Salgado
Ranch Hand

Joined: Jan 18, 2002
Posts: 98
Hi Aditi.

I'm not a Weblogic guy, but I was looking over the 8.1 docs and it seems it implements J2EE 1.3 and JAX-RPC 1.0. Being that the case, the method of deployment of Message Handlers is not mandated by the spec. See JAX-RPC 1.0 12.3.2. That changes for J2EE 1.4 when webservices.xml is used.

There seems to be some good docs for Weblogic though. Take a ook at this one, which guides you specifically on designing, building and deploying Message Handlers with Weblogic 8.1: "Creating SOAP Message Handlers to Intercept the SOAP Message"

And this one is the parent doc. Lots of info.

Hope it helps and don't forget to share the results of your implementation.

Regards.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: capture request and response to/from webservice