Coverage Report - org.mule.transport.cxf.support.MuleHeadersInInterceptor
 
Classes in this File Line Coverage Branch Coverage Complexity
MuleHeadersInInterceptor
82%
28/34
64%
14/22
0
 
 1  
 /*
 2  
  * $Id: MuleHeadersInInterceptor.java 11405 2008-03-18 00:13:00Z 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 java.util.Set;
 14  
 
 15  
 import javax.xml.namespace.QName;
 16  
 
 17  
 import org.apache.cxf.binding.soap.SoapMessage;
 18  
 import org.apache.cxf.headers.Header;
 19  
 import org.apache.cxf.interceptor.Fault;
 20  
 import org.apache.cxf.message.Message;
 21  
 import org.apache.cxf.phase.Phase;
 22  
 import org.w3c.dom.Element;
 23  
 import org.w3c.dom.Node;
 24  
 import org.w3c.dom.NodeList;
 25  
 import org.w3c.dom.Text;
 26  
 
 27  
 /**
 28  
  * Reads the Mule Soap Header and sets the various header properties on the message.
 29  
  */
 30  
 public class MuleHeadersInInterceptor extends BaseMuleHeaderInterceptor
 31  
 {
 32  
 
 33  
     public MuleHeadersInInterceptor()
 34  
     {
 35  442
         super(Phase.PRE_PROTOCOL);
 36  442
     }
 37  
 
 38  
     public void handleMessage(Message m) throws Fault
 39  
     {
 40  186
         if (!(m instanceof SoapMessage))
 41  
         {
 42  0
             return;
 43  
         }
 44  
 
 45  186
         SoapMessage message = (SoapMessage) m;
 46  186
         if (!message.hasHeaders())
 47  
         {
 48  174
             return;
 49  
         }
 50  12
         Header mule_header = message.getHeader(MULE_HEADER_Q);
 51  12
         if (mule_header == null)
 52  
         {
 53  0
             return;
 54  
         }
 55  12
         Object obj = mule_header.getObject();
 56  12
         if (!(obj instanceof Element))
 57  
         {
 58  
             // Error? We can't work with it at any rate.
 59  0
             return;
 60  
         }
 61  
 
 62  12
         Element header_element = (Element) obj;
 63  12
         NodeList mule_headers = header_element.getChildNodes();
 64  12
         int idx = 0;
 65  
         Node child;
 66  48
         while ((child = mule_headers.item(idx++)) != null)
 67  
         {
 68  36
             if (child.getNodeType() != Node.ELEMENT_NODE)
 69  
             {
 70  0
                 continue;
 71  
             }
 72  36
             Element child_el = (Element) child;
 73  36
             if (child_el.getNamespaceURI() == null || !child_el.getNamespaceURI().equals(MULE_NS_URI))
 74  
             {
 75  0
                 continue;
 76  
             }
 77  
             
 78  36
             if (SUPPORTED_HEADERS.contains(child_el.getLocalName()))
 79  
             {
 80  36
                 message.put(child_el.getLocalName(), collectTextFrom(child_el));
 81  
             }
 82  36
         }
 83  12
     }
 84  
 
 85  
     public Set<QName> getUnderstoodHeaders()
 86  
     {
 87  0
         return UNDERSTOOD_HEADERS;
 88  
     }
 89  
 
 90  
     private String collectTextFrom(Element e)
 91  
     {
 92  36
         NodeList children = e.getChildNodes();
 93  36
         StringBuilder sb = new StringBuilder();
 94  36
         int idx = 0;
 95  
         Node n;
 96  72
         while ((n = children.item(idx++)) != null)
 97  
         {
 98  36
             if (n.getNodeType() == Node.TEXT_NODE)
 99  
             {
 100  36
                 sb.append(((Text) n).getTextContent());
 101  
             }
 102  
         }
 103  36
         return sb.toString();
 104  
     }
 105  
 
 106  
 }