Coverage Report - org.mule.transport.cxf.support.MuleHeadersOutInterceptor
 
Classes in this File Line Coverage Branch Coverage Complexity
MuleHeadersOutInterceptor
93%
26/28
64%
9/14
0
 
 1  
 /*
 2  
  * $Id: MuleHeadersOutInterceptor.java 11433 2008-03-20 03:43:57Z 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.transport.cxf.support;
 12  
 
 13  
 import static org.mule.api.config.MuleProperties.MULE_CORRELATION_GROUP_SIZE_PROPERTY;
 14  
 import static org.mule.api.config.MuleProperties.MULE_CORRELATION_ID_PROPERTY;
 15  
 import static org.mule.api.config.MuleProperties.MULE_CORRELATION_SEQUENCE_PROPERTY;
 16  
 import static org.mule.api.config.MuleProperties.MULE_EVENT_PROPERTY;
 17  
 import static org.mule.api.config.MuleProperties.MULE_REPLY_TO_PROPERTY;
 18  
 import static org.mule.transport.soap.MuleSoapHeaders.MULE_HEADER;
 19  
 
 20  
 import org.mule.api.MuleEvent;
 21  
 import org.mule.transport.soap.MuleSoapHeaders;
 22  
 
 23  
 import javax.xml.namespace.QName;
 24  
 
 25  
 import org.apache.cxf.binding.soap.SoapHeader;
 26  
 import org.apache.cxf.binding.soap.SoapMessage;
 27  
 import org.apache.cxf.helpers.DOMUtils;
 28  
 import org.apache.cxf.interceptor.Fault;
 29  
 import org.apache.cxf.message.Message;
 30  
 import org.apache.cxf.phase.Phase;
 31  
 import org.w3c.dom.Document;
 32  
 import org.w3c.dom.Element;
 33  
 import org.w3c.dom.Text;
 34  
 
 35  
 /**
 36  
  * Writes the Mule Soap Header to the outgoing request.
 37  
  */
 38  
 public class MuleHeadersOutInterceptor extends BaseMuleHeaderInterceptor
 39  
 {
 40  
 
 41  
     public MuleHeadersOutInterceptor()
 42  
     {
 43  152
         super(Phase.PRE_PROTOCOL);
 44  152
     }
 45  
 
 46  
     public void handleMessage(Message m) throws Fault
 47  
     {
 48  80
         if (!(m instanceof SoapMessage))
 49  
         {
 50  0
             return;
 51  
         }
 52  
 
 53  80
         SoapMessage message = (SoapMessage) m;
 54  80
         MuleEvent event = (MuleEvent) message.getExchange().get(MULE_EVENT_PROPERTY);
 55  
 
 56  80
         if (event == null)
 57  
         {
 58  22
             return;
 59  
         }
 60  
 
 61  58
         MuleSoapHeaders muleHeaders = new MuleSoapHeaders(event);
 62  
 
 63  58
         if (muleHeaders.getCorrelationId() == null && muleHeaders.getReplyTo() == null)
 64  
         {
 65  46
             return;
 66  
         }
 67  
 
 68  12
         Document owner_doc = DOMUtils.createDocument();
 69  
 
 70  12
         Element mule_header = owner_doc.createElementNS(MULE_NS_URI, QUALIFIED_MULE_HEADER);
 71  
         // setup mule: namespace prefix declaration so that we can use it.
 72  12
         mule_header.setAttribute("xmlns:mule", MULE_NS_URI);
 73  
 
 74  12
         if (muleHeaders.getCorrelationId() != null)
 75  
         {
 76  12
             mule_header.appendChild(buildMuleHeader(owner_doc, MULE_CORRELATION_ID_PROPERTY,
 77  
                 muleHeaders.getCorrelationId()));
 78  12
             mule_header.appendChild(buildMuleHeader(owner_doc, MULE_CORRELATION_GROUP_SIZE_PROPERTY,
 79  
                 muleHeaders.getCorrelationGroup()));
 80  12
             mule_header.appendChild(buildMuleHeader(owner_doc, MULE_CORRELATION_SEQUENCE_PROPERTY,
 81  
                 muleHeaders.getCorrelationSequence()));
 82  
         }
 83  12
         if (muleHeaders.getReplyTo() != null)
 84  
         {
 85  0
             mule_header.appendChild(buildMuleHeader(owner_doc, MULE_REPLY_TO_PROPERTY,
 86  
                 muleHeaders.getReplyTo()));
 87  
         }
 88  
 
 89  12
         SoapHeader sh = new SoapHeader(new QName(MULE_NS_URI, MULE_HEADER), mule_header);
 90  12
         message.getHeaders().add(sh);
 91  12
     }
 92  
 
 93  
     Element buildMuleHeader(Document owner_doc, String localName, String value)
 94  
     {
 95  36
         Element out = owner_doc.createElementNS(MULE_NS_URI, "mule:" + localName);
 96  36
         if (value != null)
 97  
         {
 98  36
             Text text = owner_doc.createTextNode(value);
 99  36
             out.appendChild(text);
 100  
         }
 101  36
         return out;
 102  
     }
 103  
 
 104  
 }