Coverage Report - org.mule.module.cxf.support.MuleHeadersOutInterceptor
 
Classes in this File Line Coverage Branch Coverage Complexity
MuleHeadersOutInterceptor
0%
0/28
0%
0/14
0
 
 1  
 /*
 2  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 3  
  * The software in this package is published under the terms of the CPAL v1.0
 4  
  * license, a copy of which has been included with this distribution in the
 5  
  * LICENSE.txt file.
 6  
  */
 7  
 package org.mule.module.cxf.support;
 8  
 
 9  
 import org.mule.api.MuleEvent;
 10  
 import org.mule.module.cxf.CxfConstants;
 11  
 import org.mule.module.cxf.MuleSoapHeaders;
 12  
 
 13  
 import javax.xml.namespace.QName;
 14  
 
 15  
 import org.apache.cxf.binding.soap.SoapHeader;
 16  
 import org.apache.cxf.binding.soap.SoapMessage;
 17  
 import org.apache.cxf.helpers.DOMUtils;
 18  
 import org.apache.cxf.interceptor.Fault;
 19  
 import org.apache.cxf.message.Message;
 20  
 import org.apache.cxf.phase.Phase;
 21  
 import org.w3c.dom.Document;
 22  
 import org.w3c.dom.Element;
 23  
 import org.w3c.dom.Text;
 24  
 
 25  
 import static org.mule.module.cxf.MuleSoapHeaders.MULE_HEADER;
 26  
 
 27  
 import static org.mule.api.config.MuleProperties.MULE_CORRELATION_GROUP_SIZE_PROPERTY;
 28  
 import static org.mule.api.config.MuleProperties.MULE_CORRELATION_ID_PROPERTY;
 29  
 import static org.mule.api.config.MuleProperties.MULE_CORRELATION_SEQUENCE_PROPERTY;
 30  
 import static org.mule.api.config.MuleProperties.MULE_EVENT_PROPERTY;
 31  
 import static org.mule.api.config.MuleProperties.MULE_REPLY_TO_PROPERTY;
 32  
 
 33  
 /**
 34  
  * Writes the Mule Soap Header to the outgoing request.
 35  
  */
 36  
 public class MuleHeadersOutInterceptor extends AbstractMuleHeaderInterceptor
 37  
 {
 38  
 
 39  
     public MuleHeadersOutInterceptor()
 40  
     {
 41  0
         super(Phase.PRE_PROTOCOL);
 42  0
     }
 43  
 
 44  
     public void handleMessage(Message m) throws Fault
 45  
     {
 46  0
         if (!(m instanceof SoapMessage))
 47  
         {
 48  0
             return;
 49  
         }
 50  
 
 51  0
         SoapMessage message = (SoapMessage) m;
 52  0
         MuleEvent event = (MuleEvent) message.getExchange().get(CxfConstants.MULE_EVENT);
 53  
 
 54  0
         if (event == null)
 55  
         {
 56  0
             return;
 57  
         }
 58  
 
 59  0
         MuleSoapHeaders muleHeaders = new MuleSoapHeaders(event);
 60  
 
 61  0
         if (muleHeaders.getCorrelationId() == null && muleHeaders.getReplyTo() == null)
 62  
         {
 63  0
             return;
 64  
         }
 65  
 
 66  0
         Document owner_doc = DOMUtils.createDocument();
 67  
 
 68  0
         Element mule_header = owner_doc.createElementNS(MULE_NS_URI, QUALIFIED_MULE_HEADER);
 69  
         // setup mule: namespace prefix declaration so that we can use it.
 70  0
         mule_header.setAttribute("xmlns:mule", MULE_NS_URI);
 71  
 
 72  0
         if (muleHeaders.getCorrelationId() != null)
 73  
         {
 74  0
             mule_header.appendChild(buildMuleHeader(owner_doc, MULE_CORRELATION_ID_PROPERTY,
 75  
                 muleHeaders.getCorrelationId()));
 76  0
             mule_header.appendChild(buildMuleHeader(owner_doc, MULE_CORRELATION_GROUP_SIZE_PROPERTY,
 77  
                 muleHeaders.getCorrelationGroup()));
 78  0
             mule_header.appendChild(buildMuleHeader(owner_doc, MULE_CORRELATION_SEQUENCE_PROPERTY,
 79  
                 muleHeaders.getCorrelationSequence()));
 80  
         }
 81  0
         if (muleHeaders.getReplyTo() != null)
 82  
         {
 83  0
             mule_header.appendChild(buildMuleHeader(owner_doc, MULE_REPLY_TO_PROPERTY,
 84  
                 muleHeaders.getReplyTo()));
 85  
         }
 86  
 
 87  0
         SoapHeader sh = new SoapHeader(new QName(MULE_NS_URI, MULE_HEADER), mule_header);
 88  0
         message.getHeaders().add(sh);
 89  0
     }
 90  
 
 91  
     Element buildMuleHeader(Document owner_doc, String localName, String value)
 92  
     {
 93  0
         Element out = owner_doc.createElementNS(MULE_NS_URI, "mule:" + localName);
 94  0
         if (value != null)
 95  
         {
 96  0
             Text text = owner_doc.createTextNode(value);
 97  0
             out.appendChild(text);
 98  
         }
 99  0
         return out;
 100  
     }
 101  
 
 102  
 }