View Javadoc

1   /*
2    * $Id: MuleMessageWorker.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.tcp.protocols;
12  
13  import org.mule.DefaultMuleMessage;
14  import org.mule.RequestContext;
15  
16  import java.io.IOException;
17  
18  import org.apache.commons.lang.SerializationUtils;
19  
20  /**
21   * Helper class for Mule message handling so that we can apply the same logic across all
22   * sub-protocols (default, EOF and length).
23   */
24  class MuleMessageWorker
25  {
26  
27      private MuleMessageWorker()
28      {
29          // no-op
30      }
31  
32      public static byte[] doWrite() throws IOException
33      {
34          DefaultMuleMessage msg = (DefaultMuleMessage) RequestContext.getEvent().getMessage();
35          return SerializationUtils.serialize(msg);
36      }
37  
38      public static Object doRead(Object message) throws IOException
39      {
40          byte[] tmp = (byte[]) message;
41  
42          if (tmp == null)
43          {
44              return null;
45          }
46          else
47          {
48              return SerializationUtils.deserialize(tmp);
49          }
50      }
51  
52  }