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