Coverage Report - org.mule.providers.soap.axis.extensions.MuleSoapHeadersHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
MuleSoapHeadersHandler
49%
30/61
38%
13/34
6
 
 1  
 /*
 2  
  * $Id: MuleSoapHeadersHandler.java 7963 2007-08-21 08:53:15Z dirk.olmes $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.providers.soap.axis.extensions;
 12  
 
 13  
 import org.mule.config.MuleProperties;
 14  
 import org.mule.providers.soap.MuleSoapHeaders;
 15  
 import org.mule.umo.UMOEvent;
 16  
 
 17  
 import javax.xml.soap.SOAPEnvelope;
 18  
 import javax.xml.soap.SOAPMessage;
 19  
 
 20  
 import org.apache.axis.AxisFault;
 21  
 import org.apache.axis.MessageContext;
 22  
 import org.apache.axis.handlers.BasicHandler;
 23  
 import org.apache.commons.logging.Log;
 24  
 import org.apache.commons.logging.LogFactory;
 25  
 
 26  
 /**
 27  
  * <code>MuleSoapHeadersHandler</code> is an Axis handler that can read and write
 28  
  * Mule header properties to a SOAP message.
 29  
  */
 30  176
 public class MuleSoapHeadersHandler extends BasicHandler
 31  
 {
 32  
     /**
 33  
      * Serial version
 34  
      */
 35  
     private static final long serialVersionUID = 1813393257662701953L;
 36  
 
 37  
     /**
 38  
      * logger used by this class
 39  
      */
 40  4
     protected static final Log logger = LogFactory.getLog(MuleSoapHeadersHandler.class);
 41  
 
 42  
     public void invoke(MessageContext msgContext) throws AxisFault
 43  
     {
 44  274
         boolean setMustUnderstand = msgContext.isPropertyTrue("MULE_HEADER_MUST_UNDERSTAND");
 45  
 
 46  
         try
 47  
         {
 48  274
             if (msgContext.isClient())
 49  
             {
 50  274
                 if (!msgContext.getPastPivot())
 51  
                 {
 52  142
                     processClientRequest(msgContext, setMustUnderstand);
 53  142
                     if (logger.isDebugEnabled())
 54  
                     {
 55  0
                         logger.debug("After Client Request, Message is:\n"
 56  
                                         + msgContext.getRequestMessage().getSOAPPartAsString());
 57  
                     }
 58  
                 }
 59  
                 else
 60  
                 {
 61  132
                     processClientResponse(msgContext);
 62  132
                     if (logger.isDebugEnabled())
 63  
                     {
 64  0
                         logger.debug("After Client Response, Message is:\n"
 65  
                                         + msgContext.getRequestMessage().getSOAPPartAsString());
 66  
                     }
 67  
                 }
 68  
             }
 69  
             else
 70  
             {
 71  0
                 if (!msgContext.getPastPivot())
 72  
                 {
 73  0
                     processServerRequest(msgContext);
 74  0
                     if (logger.isDebugEnabled())
 75  
                     {
 76  0
                         logger.debug("After Server Request, Message is:\n"
 77  
                                         + msgContext.getRequestMessage().getSOAPPartAsString());
 78  
                     }
 79  
                 }
 80  
                 else
 81  
                 {
 82  0
                     processServerResponse(msgContext, setMustUnderstand);
 83  0
                     if (logger.isDebugEnabled())
 84  
                     {
 85  0
                         logger.debug("After Server Response, Message is:\n"
 86  
                                         + msgContext.getRequestMessage().getSOAPPartAsString());
 87  
                     }
 88  
                 }
 89  
             }
 90  
         }
 91  0
         catch (Exception e)
 92  
         {
 93  0
             throw AxisFault.makeFault(e);
 94  274
         }
 95  274
     }
 96  
 
 97  
     /**
 98  
      * Method processClientRequest
 99  
      * 
 100  
      * @param msgContext
 101  
      */
 102  
     protected synchronized void processClientRequest(MessageContext msgContext, boolean setMustUnderstand)
 103  
         throws Exception
 104  
     {
 105  142
         SOAPMessage msg = msgContext.getMessage();
 106  142
         if (msg == null)
 107  
         {
 108  0
             return;
 109  
         }
 110  142
         UMOEvent event = (UMOEvent)msgContext.getProperty(MuleProperties.MULE_EVENT_PROPERTY);
 111  
 
 112  142
         if (event == null)
 113  
         {
 114  48
             return;
 115  
         }
 116  
         else
 117  
         {
 118  94
             synchronized (msgContext)
 119  
             {
 120  94
                 MuleSoapHeaders headers = new MuleSoapHeaders(event);
 121  94
                 headers.addHeaders(msgContext.getMessage().getSOAPPart().getEnvelope());
 122  94
             }
 123  
         }
 124  94
     }
 125  
 
 126  
     /**
 127  
      * Method processClientResponse
 128  
      * 
 129  
      * @param msgContext
 130  
      */
 131  
     protected void processClientResponse(MessageContext msgContext) throws Exception
 132  
     {
 133  132
         SOAPMessage msg = msgContext.getMessage();
 134  132
         if (msg == null)
 135  
         {
 136  0
             return;
 137  
         }
 138  132
         SOAPEnvelope env = msg.getSOAPPart().getEnvelope();
 139  132
         MuleSoapHeaders headers = new MuleSoapHeaders(env.getHeader());
 140  
 
 141  132
         if (headers.getCorrelationId() != null)
 142  
         {
 143  0
             msgContext.setProperty(MuleProperties.MULE_CORRELATION_ID_PROPERTY, headers.getCorrelationId());
 144  
         }
 145  132
         if (headers.getCorrelationGroup() != null)
 146  
         {
 147  0
             msgContext.setProperty(MuleProperties.MULE_CORRELATION_GROUP_SIZE_PROPERTY, headers
 148  
                 .getCorrelationGroup());
 149  
         }
 150  132
         if (headers.getCorrelationSequence() != null)
 151  
         {
 152  0
             msgContext.setProperty(MuleProperties.MULE_CORRELATION_SEQUENCE_PROPERTY, headers
 153  
                 .getCorrelationSequence());
 154  
         }
 155  
 
 156  132
         if (headers.getReplyTo() != null)
 157  
         {
 158  0
             msgContext.setProperty(MuleProperties.MULE_REPLY_TO_PROPERTY, headers.getReplyTo());
 159  
         }
 160  132
     }
 161  
 
 162  
     /**
 163  
      * Method processServerRequest
 164  
      * 
 165  
      * @param msgContext
 166  
      * @throws Exception
 167  
      */
 168  
     protected void processServerRequest(MessageContext msgContext) throws Exception
 169  
     {
 170  0
         SOAPMessage msg = msgContext.getMessage();
 171  0
         if (msg == null)
 172  
         {
 173  0
             return;
 174  
         }
 175  0
         MuleSoapHeaders headers = new MuleSoapHeaders(msg.getSOAPPart().getEnvelope().getHeader());
 176  0
         msgContext.setProperty(MuleSoapHeaders.ENV_REQUEST_HEADERS, headers);
 177  0
     }
 178  
 
 179  
     /**
 180  
      * Method processServerResponse
 181  
      * 
 182  
      * @param msgContext
 183  
      */
 184  
     protected void processServerResponse(MessageContext msgContext, boolean setMustUnderstand)
 185  
         throws Exception
 186  
     {
 187  0
         SOAPMessage msg = msgContext.getMessage();
 188  0
         if (msg == null)
 189  
         {
 190  0
             return;
 191  
         }
 192  0
         MuleSoapHeaders headers = (MuleSoapHeaders)msgContext
 193  
             .getProperty(MuleSoapHeaders.ENV_REQUEST_HEADERS);
 194  
 
 195  0
         if (headers == null)
 196  
         {
 197  0
             return;
 198  
         }
 199  
         else
 200  
         {
 201  0
             headers.addHeaders(msgContext.getMessage().getSOAPPart().getEnvelope());
 202  
         }
 203  0
     }
 204  
 
 205  
 }