1
2
3
4
5
6
7
8
9
10
11 package org.mule.transport.tcp.integration;
12
13 import org.mule.transport.tcp.protocols.DirectProtocol;
14
15 import java.io.IOException;
16 import java.io.InputStream;
17 import java.io.OutputStream;
18
19 import org.apache.commons.lang.SerializationUtils;
20
21 public class CustomSerializationProtocol extends DirectProtocol
22 {
23
24
25 public void write(OutputStream os, Object data) throws IOException
26 {
27 if (data instanceof NonSerializableMessageObject)
28 {
29 NonSerializableMessageObject in = (NonSerializableMessageObject)data;
30
31
32 MessageObject serializableObject = new MessageObject(in.i, in.s, in.b);
33
34 write(os, SerializationUtils.serialize(serializableObject));
35 }
36 else
37 {
38 super.write(os, data);
39 }
40 }
41
42
43 public Object read(InputStream is) throws IOException
44 {
45 byte[] tmp = (byte[]) super.read(is);
46
47 if (tmp == null)
48 {
49 return null;
50 }
51 else
52 {
53 MessageObject serializableObject = (MessageObject)SerializationUtils.deserialize(tmp);
54 return new NonSerializableMessageObject(serializableObject.i, serializableObject.s,
55 serializableObject.b);
56 }
57 }
58
59 }