Coverage Report - org.mule.module.cxf.support.MuleHeadersInInterceptor
 
Classes in this File Line Coverage Branch Coverage Complexity
MuleHeadersInInterceptor
0%
0/47
0%
0/30
0
 
 1  
 /*
 2  
  * $Id: MuleHeadersInInterceptor.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.api.MuleMessage;
 15  
 import org.mule.api.config.MuleProperties;
 16  
 import org.mule.module.cxf.CxfConstants;
 17  
 
 18  
 import java.util.Set;
 19  
 
 20  
 import javax.xml.namespace.QName;
 21  
 
 22  
 import org.apache.cxf.binding.soap.SoapMessage;
 23  
 import org.apache.cxf.headers.Header;
 24  
 import org.apache.cxf.interceptor.Fault;
 25  
 import org.apache.cxf.message.Message;
 26  
 import org.apache.cxf.phase.Phase;
 27  
 import org.w3c.dom.Element;
 28  
 import org.w3c.dom.Node;
 29  
 import org.w3c.dom.NodeList;
 30  
 import org.w3c.dom.Text;
 31  
 
 32  
 /**
 33  
  * Reads the Mule Soap Header and sets the various header properties on the message.
 34  
  */
 35  
 public class MuleHeadersInInterceptor extends AbstractMuleHeaderInterceptor
 36  
 {
 37  
 
 38  
     public MuleHeadersInInterceptor()
 39  
     {
 40  0
         super(Phase.PRE_PROTOCOL);
 41  0
     }
 42  
 
 43  
     public void handleMessage(Message m) throws Fault
 44  
     {
 45  0
         if (!(m instanceof SoapMessage))
 46  
         {
 47  0
             return;
 48  
         }
 49  
 
 50  0
         SoapMessage message = (SoapMessage) m;
 51  0
         if (!message.hasHeaders())
 52  
         {
 53  0
             return;
 54  
         }
 55  0
         Header mule_header = message.getHeader(MULE_HEADER_Q);
 56  0
         if (mule_header == null)
 57  
         {
 58  0
             return;
 59  
         }
 60  0
         Object obj = mule_header.getObject();
 61  0
         if (!(obj instanceof Element))
 62  
         {
 63  
             // Error? We can't work with it at any rate.
 64  0
             return;
 65  
         }
 66  
 
 67  0
         Element header_element = (Element) obj;
 68  0
         NodeList mule_headers = header_element.getChildNodes();
 69  0
         int idx = 0;
 70  
         Node child;
 71  0
         while ((child = mule_headers.item(idx++)) != null)
 72  
         {
 73  0
             if (child.getNodeType() != Node.ELEMENT_NODE)
 74  
             {
 75  0
                 continue;
 76  
             }
 77  0
             Element child_el = (Element) child;
 78  0
             if (child_el.getNamespaceURI() == null || !child_el.getNamespaceURI().equals(MULE_NS_URI))
 79  
             {
 80  0
                 continue;
 81  
             }
 82  
             
 83  0
             if (SUPPORTED_HEADERS.contains(child_el.getLocalName()))
 84  
             {
 85  0
                 message.put(child_el.getLocalName(), collectTextFrom(child_el));
 86  
             }
 87  0
         }
 88  
         
 89  
 
 90  0
         MuleMessage reqMsg = ((MuleEvent) message.get(CxfConstants.MULE_EVENT)).getMessage();
 91  
         
 92  
         // Copy correlation headers nto message
 93  0
         String replyTo = (String) message.get(MuleProperties.MULE_REPLY_TO_PROPERTY);
 94  0
         if (replyTo != null)
 95  
         {
 96  0
             reqMsg.setReplyTo(replyTo);
 97  
         }
 98  
         
 99  0
         String corId = (String) message.get(MuleProperties.MULE_CORRELATION_ID_PROPERTY);
 100  0
         if (corId != null)
 101  
         {
 102  0
             reqMsg.setCorrelationId(corId);
 103  
         }
 104  
 
 105  0
         String corGroupSize = (String) message.get(MuleProperties.MULE_CORRELATION_GROUP_SIZE_PROPERTY);
 106  0
         if (corGroupSize != null)
 107  
         {
 108  0
             reqMsg.setCorrelationGroupSize(Integer.valueOf(corGroupSize));
 109  
         }
 110  
 
 111  0
         String corSeq = (String) message.get(MuleProperties.MULE_CORRELATION_SEQUENCE_PROPERTY);
 112  0
         if (corSeq != null)
 113  
         {
 114  0
             reqMsg.setCorrelationSequence(Integer.valueOf(corSeq));
 115  
         }
 116  0
     }
 117  
 
 118  
     public Set<QName> getUnderstoodHeaders()
 119  
     {
 120  0
         return UNDERSTOOD_HEADERS;
 121  
     }
 122  
 
 123  
     private String collectTextFrom(Element e)
 124  
     {
 125  0
         NodeList children = e.getChildNodes();
 126  0
         StringBuilder sb = new StringBuilder();
 127  0
         int idx = 0;
 128  
         Node n;
 129  0
         while ((n = children.item(idx++)) != null)
 130  
         {
 131  0
             if (n.getNodeType() == Node.TEXT_NODE)
 132  
             {
 133  0
                 sb.append(((Text) n).getTextContent());
 134  
             }
 135  
         }
 136  0
         return sb.toString();
 137  
     }
 138  
 
 139  
 }