1 Reply Latest reply on Jan 22, 2006 3:56 PM by Thomas Diesler

    JAXRPC Handler

    fss Newbie

      Hi,

      I have a problem with following jaxrpc-Handler.


      public class RequestLogHandler extends GenericHandler
      {
       private static final Logger logger = Logger.getLogger(RequestLogHandler.class);
      
       private SOAPMessage request;
      
       public RequestLogHandler()
       {
      
       }
      
      
       public QName[] getHeaders()
       {
       return new QName[0];
       }
      
       public boolean handleResponse(MessageContext msgContext)
       {
       ByteArrayOutputStream outRequest = null;
      
       try
       {
       SOAPMessageContext scontext = (SOAPMessageContext) msgContext;
       SOAPMessage response = scontext.getMessage();
      
       outRequest = new ByteArrayOutputStream();
      
       this.request.writeTo(outRequest);
       response.writeTo(outRequest);
      
       logger.info(outRequest);
       outRequest.close();
       }
       catch (Exception e)
       {
       System.out.println("...");
       }
      
       return true;
       }
      
       public boolean handleFault(MessageContext msgContext)
       {
       ByteArrayOutputStream outRequest = null;
      
       try
       {
       SOAPMessageContext scontext = (SOAPMessageContext) msgContext;
       SOAPMessage response = scontext.getMessage();
      
       outRequest = new ByteArrayOutputStream();
      
       this.request.writeTo(outRequest);
       response.writeTo(outRequest);
      
       logger.info(outRequest);
       outRequest.close();
       }
       catch (Exception e)
       {
       System.out.println("...");
       }
      
      
       return true;
       }
      
       public boolean handleRequest(MessageContext msgContext)
       {
       SOAPMessageContext scontext = (SOAPMessageContext) msgContext;
       this.request = scontext.getMessage();
      
       return true;
       }
      }
      


      This handler should log all "request-response"-pairs to a log4j-Logger. When response is not a fault, than everthing works fine.
      When the response is a fault-message then the logger doesn't log the fault response. It logs the request 2-times.

      In the function handleFault the call
      SOAPMessageContext scontext = (SOAPMessageContext) msgContext;
       SOAPMessage response = scontext.getMessage();

      seems to return the request not the fault Message.

      Is this OK?

      thanx Florian