Results 1 to 3 of 3

Thread: Capturing Raw xml request/response with JAX-RPC

  1. #1
    Join Date
    Apr 2007
    Posts
    2

    Default Capturing Raw xml request/response with JAX-RPC

    I've set up an axis web service client by extending the Spring JaxRpcPortProxyFactoryBean. The web service calls work fine but I want to (for auditing) also capture the raw XML request/response for each call. It seems to me the only way to do this is to override the method:

    JaxRpcPortClientInterceptor.performJaxRpcCall(Meth odInvocation invocation, Service service), see below:


    Code:
    public class JaxRpcPortClientInterceptor extends LocalJaxRpcServiceFactory
    		implements MethodInterceptor, InitializingBean {
    		
       //From 
       protected Object performJaxRpcCall(MethodInvocation invocation, Service service) throws Throwable {
    		
    	.......
    			
    	// Perform actual invocation.
    	try {
    		return call.invoke(invocation.getArguments());
    	}
    			
    	.....
        }
                
                
       //To            
       protected Object performJaxRpcCall(MethodInvocation invocation, Service service) throws Throwable {
    		
    	.......
    			
    	// Perform actual invocation.
    	try {
    	           
    	            MyReturnType result;
    	            Object o = call.invoke(invocation.getArguments());
    	            result = (MyReturnType) o;
    	
    	            String xmlRequest = ((org.apache.axis.client.Call)call)
    	                                    .getMessageContext()
    	                                    .getRequestMessage()
    	                                    .getSOAPPart()
    	                                    .getEnvelope()
    	                                    .getBody()
    	                                    .toString();
    	
    	            String xmlResponse = ((org.apache.axis.client.Call)call)
    	                                    .getMessageContext()
    	                                    .getResponseMessage()
    	                                    .getSOAPPart()
    	                                    .getEnvelope()
    	                                    .getBody()
    	                                    .toString();
    	
    	            result.setXmlRequest(xmlRequest);
    	            result.setXmlResponse(xmlResponse);
    	
    	            return result;
    			
    	    .....
    	}
    I'm going to have to copy a chunk of code to do this though and it doesn't feel right. Is there a more sensible extension point/hook/intercepter that I can use to use to capture the request/response ?

    Thanks

  2. #2
    Join Date
    Apr 2007
    Posts
    2

    Default

    I've seen from the spring docs section:
    17.5.4. Registering our own Handler

    That I can register a handler to grab the xml request and response. It's quite detached from the returned result but I guess its the direction to look in.

  3. #3
    Join Date
    Nov 2006
    Location
    Germany
    Posts
    452

    Default

    Hello,

    if you want to see the XML Conent that is send an recevied with JAX-RPC i recommedn using a handler.

    http://java.sun.com/j2ee/1.4/docs/ap...icHandler.html

    There you can override the methods handleRequest,handleResponse,handleFault.

    You have to cast the MessageContet into a SOAPMesageContext, from there you can get the SOAPMessage.

    After that you can write the SOAPMessage through writeTo into an OutputStream of your choice.

    The Handler must be registered like here

    Code:
    List list = service.getHandlerRegistry().getHandlerChain(port);
            list.add(new HandlerInfo(CustomHandler.class, null, null));
    You can process the Service by extending JaxRpx...Bean, and override postProcessJaxRpcService.

    Regards
    lyserg

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •