Coverage Report - org.mule.transport.udp.UdpMuleMessageFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
UdpMuleMessageFactory
0%
0/15
0%
0/2
0
 
 1  
 /*
 2  
  * $Id: UdpMuleMessageFactory.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.transport.udp;
 12  
 
 13  
 import org.mule.DefaultMuleMessage;
 14  
 import org.mule.api.MuleContext;
 15  
 import org.mule.transport.AbstractMuleMessageFactory;
 16  
 
 17  
 import java.net.DatagramPacket;
 18  
 import java.net.InetAddress;
 19  
 
 20  
 public class UdpMuleMessageFactory extends AbstractMuleMessageFactory
 21  
 {
 22  
     public UdpMuleMessageFactory(MuleContext context)
 23  
     {
 24  0
         super(context);
 25  0
     }
 26  
 
 27  
     @Override
 28  
     protected Class<?>[] getSupportedTransportMessageTypes()
 29  
     {
 30  0
         return new Class[] { DatagramPacket.class };
 31  
     }
 32  
 
 33  
     @Override
 34  
     protected Object extractPayload(Object transportMessage, String encoding) throws Exception
 35  
     {
 36  0
         DatagramPacket packet = (DatagramPacket) transportMessage;
 37  
         
 38  0
         int length = packet.getLength();
 39  0
         byte[] payload = new byte[length];
 40  0
         System.arraycopy(packet.getData(), 0, payload, 0, length);
 41  
 
 42  0
         return payload;
 43  
     }
 44  
 
 45  
     @Override
 46  
     protected void addProperties(DefaultMuleMessage message, Object transportMessage) throws Exception
 47  
     {
 48  0
         super.addProperties(message, transportMessage);
 49  
 
 50  0
         DatagramPacket packet = (DatagramPacket) transportMessage;
 51  
         
 52  0
         InetAddress address = packet.getAddress();
 53  0
         if (address != null)
 54  
         {
 55  0
             message.setOutboundProperty(UdpConnector.ADDRESS_PROPERTY, address);
 56  
         }
 57  
 
 58  0
         message.setOutboundProperty(UdpConnector.PORT_PROPERTY, Integer.valueOf(packet.getPort()));
 59  0
     }
 60  
 }