1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.transport.tcp.protocols; |
12 | |
|
13 | |
import java.io.IOException; |
14 | |
import java.io.InputStream; |
15 | |
|
16 | |
import org.apache.commons.io.input.ClassLoaderObjectInputStream; |
17 | |
import org.apache.log4j.Logger; |
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | 0 | public class CustomClassLoadingLengthProtocol extends LengthProtocol |
25 | |
{ |
26 | 0 | private final Logger logger = Logger.getLogger(this.getClass()); |
27 | |
|
28 | |
private ClassLoader classLoader; |
29 | |
|
30 | |
@Override |
31 | |
public Object read(InputStream is) throws IOException |
32 | |
{ |
33 | 0 | byte[] bytes = (byte[]) super.read(is); |
34 | |
|
35 | 0 | if (bytes == null) |
36 | |
{ |
37 | 0 | return null; |
38 | |
} |
39 | |
else |
40 | |
{ |
41 | 0 | ClassLoaderObjectInputStream classLoaderIS = new ClassLoaderObjectInputStream(this.getClassLoader(), |
42 | |
is); |
43 | |
try |
44 | |
{ |
45 | 0 | return classLoaderIS.readObject(); |
46 | |
} |
47 | 0 | catch (ClassNotFoundException e) |
48 | |
{ |
49 | 0 | logger.warn(e.getMessage()); |
50 | 0 | IOException iox = new IOException(); |
51 | 0 | iox.initCause(e); |
52 | 0 | throw iox; |
53 | |
} |
54 | |
finally |
55 | |
{ |
56 | 0 | classLoaderIS.close(); |
57 | |
} |
58 | |
} |
59 | |
} |
60 | |
|
61 | |
public ClassLoader getClassLoader() |
62 | |
{ |
63 | 0 | if (this.classLoader == null) |
64 | |
{ |
65 | 0 | this.classLoader = this.getClass().getClassLoader(); |
66 | |
} |
67 | 0 | return classLoader; |
68 | |
} |
69 | |
|
70 | |
public void setClassLoader(ClassLoader classLoader) |
71 | |
{ |
72 | 0 | this.classLoader = classLoader; |
73 | 0 | } |
74 | |
} |