Coverage Report - org.mule.transport.soap.axis.AxisMessageAdapter
 
Classes in this File Line Coverage Branch Coverage Complexity
AxisMessageAdapter
68%
30/44
75%
12/16
2.714
 
 1  
 /*
 2  
  * $Id: AxisMessageAdapter.java 10489 2008-01-23 17:53:38Z dfeist $
 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.soap.axis;
 12  
 
 13  
 import org.mule.api.MessagingException;
 14  
 import org.mule.api.ThreadSafeAccess;
 15  
 import org.mule.api.transformer.Transformer;
 16  
 import org.mule.transformer.simple.SerializableToByteArray;
 17  
 import org.mule.transport.AbstractMessageAdapter;
 18  
 import org.mule.transport.soap.MuleSoapHeaders;
 19  
 import org.mule.transport.soap.i18n.SoapMessages;
 20  
 import org.mule.util.StringUtils;
 21  
 
 22  
 import java.util.Iterator;
 23  
 
 24  
 import javax.activation.DataHandler;
 25  
 import javax.xml.soap.SOAPException;
 26  
 import javax.xml.soap.SOAPMessage;
 27  
 
 28  
 import org.apache.axis.MessageContext;
 29  
 import org.apache.axis.attachments.AttachmentPart;
 30  
 
 31  
 /**
 32  
  * <code>AxisMessageAdapter</code> wraps a soap message. The payload of the adapter
 33  
  * is the raw message received from the transport, but you also have access to the
 34  
  * SOAPMessage object by using <code>adapter.getSOAPMessage()</code>
 35  
  */
 36  
 public class AxisMessageAdapter extends AbstractMessageAdapter
 37  
 {
 38  
     /**
 39  
      * Serial version
 40  
      */
 41  
     private static final long serialVersionUID = -923205879581370143L;
 42  
 
 43  
     private final Object payload;
 44  
     private final SOAPMessage soapMessage;
 45  170
     private Transformer trans = new SerializableToByteArray();
 46  
 
 47  
     public AxisMessageAdapter(Object message) throws MessagingException
 48  162
     {
 49  162
         this.payload = message;
 50  
         try
 51  
         {
 52  162
             MessageContext ctx = MessageContext.getCurrentContext();
 53  
 
 54  162
             if (ctx != null)
 55  
             {
 56  160
                 MuleSoapHeaders header = new MuleSoapHeaders(ctx.getMessage().getSOAPPart().getEnvelope()
 57  
                     .getHeader());
 58  
 
 59  160
                 if (StringUtils.isNotBlank(header.getReplyTo()))
 60  
                 {
 61  2
                     setReplyTo(header.getReplyTo());
 62  
                 }
 63  
 
 64  160
                 if (StringUtils.isNotBlank(header.getCorrelationGroup()))
 65  
                 {
 66  2
                     setCorrelationGroupSize(Integer.parseInt(header.getCorrelationGroup()));
 67  
                 }
 68  160
                 if (StringUtils.isNotBlank(header.getCorrelationSequence()))
 69  
                 {
 70  2
                     setCorrelationSequence(Integer.parseInt(header.getCorrelationSequence()));
 71  
                 }
 72  160
                 if (StringUtils.isNotBlank(header.getCorrelationId()))
 73  
                 {
 74  2
                     setCorrelationId(header.getCorrelationId());
 75  
                 }
 76  
 
 77  160
                 this.soapMessage = ctx.getMessage();
 78  160
                 int x = 1;
 79  
                 try
 80  
                 {
 81  180
                     for (Iterator i = this.soapMessage.getAttachments(); i.hasNext(); x++)
 82  
                     {
 83  20
                         super.addAttachment(String.valueOf(x), ((AttachmentPart)i.next())
 84  
                             .getActivationDataHandler());
 85  
                     }
 86  
                 }
 87  0
                 catch (Exception e)
 88  
                 {
 89  
                     // this will not happen
 90  0
                     logger.fatal("Failed to read attachments", e);
 91  160
                 }
 92  160
             }
 93  
             else
 94  
             {
 95  2
                 this.soapMessage = null;
 96  
             }
 97  
         }
 98  0
         catch (SOAPException e)
 99  
         {
 100  0
             throw new MessagingException(SoapMessages.failedToProcessSoapHeaders(), message, e);
 101  162
         }
 102  162
     }
 103  
 
 104  
     public AxisMessageAdapter(AxisMessageAdapter template)
 105  
     {
 106  8
         super(template);
 107  8
         soapMessage = template.soapMessage;
 108  8
         payload = template.payload;
 109  8
         trans = template.trans;
 110  8
     }
 111  
 
 112  
     /** @return the current message */
 113  
     public Object getPayload()
 114  
     {
 115  632
         return payload;
 116  
     }
 117  
 
 118  
     public SOAPMessage getSoapMessage()
 119  
     {
 120  0
         return soapMessage;
 121  
     }
 122  
 
 123  
     public void addAttachment(String name, DataHandler dataHandler) throws Exception
 124  
     {
 125  0
         if (null != soapMessage)
 126  
         {
 127  0
             soapMessage.addAttachmentPart(new AttachmentPart(dataHandler));
 128  
         }
 129  0
         super.addAttachment(name, dataHandler);
 130  0
     }
 131  
 
 132  
     public void removeAttachment(String name) throws Exception
 133  
     {
 134  0
         if ("all".equalsIgnoreCase(name))
 135  
         {
 136  0
             soapMessage.removeAllAttachments();
 137  0
             attachments.clear();
 138  
         }
 139  
         else
 140  
         {
 141  0
             throw new SOAPException(SoapMessages.cannotRemoveSingleAttachment().toString());
 142  
         }
 143  0
     }
 144  
 
 145  
     public ThreadSafeAccess newThreadCopy()
 146  
     {
 147  8
         return new AxisMessageAdapter(this);
 148  
     }
 149  
 
 150  
 }