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