1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| package jtr.remote.cl.impl; |
8 |
| |
9 |
| import java.io.BufferedInputStream; |
10 |
| import java.io.IOException; |
11 |
| import java.io.InputStream; |
12 |
| import java.rmi.RemoteException; |
13 |
| import java.rmi.server.UnicastRemoteObject; |
14 |
| import java.util.ArrayList; |
15 |
| import java.util.Collection; |
16 |
| import jtr.remote.cl.*; |
17 |
| import jtr.test.SystemProperties; |
18 |
| import org.apache.log4j.Logger; |
19 |
| |
20 |
| |
21 |
| |
22 |
| |
23 |
| |
24 |
| |
25 |
| |
26 |
| public class JtrRmiClassLoaderServerImpl extends UnicastRemoteObject implements JtrRmiClassLoaderServer { |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
1
| public JtrRmiClassLoaderServerImpl() throws RemoteException {
|
33 |
1
| super(new Integer(System.getProperty(SystemProperties.TEST_CLASS_LOADER_SERVICE_PORT_PROPERTY,SystemProperties.TEST_CLASS_LOADER_SERVICE_PORT.toString())).intValue());
|
34 |
1
| logger.debug("Using "+System.getProperty(SystemProperties.TEST_CLASS_LOADER_SERVICE_PORT_PROPERTY)+"="
|
35 |
| +System.getProperty(SystemProperties.TEST_CLASS_LOADER_SERVICE_PORT_PROPERTY,SystemProperties.TEST_CLASS_LOADER_SERVICE_PORT.toString())); |
36 |
| } |
37 |
| |
38 |
| |
39 |
| |
40 |
| |
41 |
| |
42 |
| |
43 |
| |
44 |
| |
45 |
| |
46 |
| |
47 |
1716
| public Byte[] getBytecode(String fqn) throws RemoteException {
|
48 |
1716
| return _load( fqn.replace(".","/")+".class" );
|
49 |
| } |
50 |
| |
51 |
| |
52 |
| |
53 |
| |
54 |
| |
55 |
| |
56 |
| |
57 |
39
| public Byte[] getResource(String name) throws RemoteException {
|
58 |
39
| return _load(name);
|
59 |
| } |
60 |
| |
61 |
| |
62 |
| |
63 |
| |
64 |
1756
| private Byte[] _load(String name) throws RemoteException {
|
65 |
1756
| Byte[] res = null;
|
66 |
| |
67 |
1756
| ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
68 |
1756
| logger.debug("Loading resource "+name+" using class-loader "+cl);
|
69 |
| |
70 |
1755
| InputStream is = cl.getResourceAsStream(name);
|
71 |
1756
| if(is!=null) {
|
72 |
1634
| BufferedInputStream bis = new BufferedInputStream(is);
|
73 |
| |
74 |
1634
| Collection<Byte> c = new ArrayList<Byte>();
|
75 |
1634
| Integer b = -1;
|
76 |
1634
| try {
|
77 |
1634
| int buffSize = bis.available();
|
78 |
1634
| int readData = -1;
|
79 |
1634
| byte[] buff = new byte[buffSize];
|
80 |
| |
81 |
?
| while( (readData=bis.read(buff)) !=-1 ) {
|
82 |
| |
83 |
1634
| for(int i=0;i<readData;i++) {
|
84 |
6439602
| c.add(buff[i]);
|
85 |
| } |
86 |
| } |
87 |
1634
| logger.debug("Done... loaded "+name+" using class-loader "+cl);
|
88 |
| } catch (IOException ex) { |
89 |
0
| String msg = "Caught an I/O exception, unable to accomplish the loading of class/resource "+name;
|
90 |
0
| throw new RemoteException(msg);
|
91 |
| } |
92 |
1634
| res = (Byte[]) c.toArray(new Byte[c.size()]);
|
93 |
| } |
94 |
1756
| return res;
|
95 |
| } |
96 |
| |
97 |
| private static Logger logger = Logger.getLogger(JtrRmiClassLoader.class); |
98 |
| } |