01: /*
02: * $Id: MuleMessageWorker.java 10489 2008-01-23 17:53:38Z dfeist $
03: * --------------------------------------------------------------------------------------
04: * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
05: *
06: * The software in this package is published under the terms of the CPAL v1.0
07: * license, a copy of which has been included with this distribution in the
08: * LICENSE.txt file.
09: */
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: private MuleMessageWorker() {
27: // no-op
28: }
29:
30: public static byte[] doWrite() throws IOException {
31: DefaultMuleMessage msg = (DefaultMuleMessage) RequestContext
32: .getEvent().getMessage();
33: return SerializationUtils.serialize(msg);
34: }
35:
36: public static Object doRead(Object message) throws IOException {
37: byte[] tmp = (byte[]) message;
38:
39: if (tmp == null) {
40: return null;
41: } else {
42: return SerializationUtils.deserialize(tmp);
43: }
44: }
45:
46: }
|