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  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 3  
  * The software in this package is published under the terms of the CPAL v1.0
 4  
  * license, a copy of which has been included with this distribution in the
 5  
  * LICENSE.txt file.
 6  
  */
 7  
 package org.mule.transport.udp;
 8  
 
 9  
 import org.mule.DefaultMuleMessage;
 10  
 import org.mule.api.MuleContext;
 11  
 import org.mule.transport.AbstractMuleMessageFactory;
 12  
 
 13  
 import java.net.DatagramPacket;
 14  
 import java.net.InetAddress;
 15  
 
 16  
 public class UdpMuleMessageFactory extends AbstractMuleMessageFactory
 17  
 {
 18  
     public UdpMuleMessageFactory(MuleContext context)
 19  
     {
 20  0
         super(context);
 21  0
     }
 22  
 
 23  
     @Override
 24  
     protected Class<?>[] getSupportedTransportMessageTypes()
 25  
     {
 26  0
         return new Class[] { DatagramPacket.class };
 27  
     }
 28  
 
 29  
     @Override
 30  
     protected Object extractPayload(Object transportMessage, String encoding) throws Exception
 31  
     {
 32  0
         DatagramPacket packet = (DatagramPacket) transportMessage;
 33  
         
 34  0
         int length = packet.getLength();
 35  0
         byte[] payload = new byte[length];
 36  0
         System.arraycopy(packet.getData(), 0, payload, 0, length);
 37  
 
 38  0
         return payload;
 39  
     }
 40  
 
 41  
     @Override
 42  
     protected void addProperties(DefaultMuleMessage message, Object transportMessage) throws Exception
 43  
     {
 44  0
         super.addProperties(message, transportMessage);
 45  
 
 46  0
         DatagramPacket packet = (DatagramPacket) transportMessage;
 47  
         
 48  0
         InetAddress address = packet.getAddress();
 49  0
         if (address != null)
 50  
         {
 51  0
             message.setOutboundProperty(UdpConnector.ADDRESS_PROPERTY, address);
 52  
         }
 53  
 
 54  0
         message.setOutboundProperty(UdpConnector.PORT_PROPERTY, Integer.valueOf(packet.getPort()));
 55  0
     }
 56  
 }