1 package dynaop.remote; 2 3 import java.io.IOException ; 4 import java.io.ObjectInputStream ; 5 import java.io.ObjectOutputStream ; 6 import java.net.URL ; 7 import java.net.URLConnection ; 8 import java.rmi.RemoteException ; 9 10 import dynaop.Interceptor; 11 import dynaop.Invocation; 12 13 18 class StubInterceptor implements Interceptor { 19 20 public Object intercept(Invocation invocation) throws Throwable { 21 InvocationHandle handle = 22 new InvocationHandle(invocation.getMethod(), 23 invocation.getArguments()); 24 25 Object result; 26 URL url = (URL ) invocation.getProxy().getProxyContext().unwrap(); 27 URLConnection connection; 28 try { 29 connection = url.openConnection(); 30 connection.setDoOutput(true); 31 connection.setDoInput(true); 32 connection.setUseCaches(false); 33 34 ObjectOutputStream out = 36 new ObjectOutputStream (connection.getOutputStream()); 37 out.writeObject(handle); 38 out.flush(); 39 out.close(); 40 41 ObjectInputStream in = 43 new ObjectInputStream (connection.getInputStream()); 44 result = in.readObject(); 45 in.close(); 46 47 if (result instanceof ThrowableWrapper) 49 throw ((ThrowableWrapper) result).getThrowable(); 50 51 return result; 52 } 53 catch (IOException e) { 54 throw new RemoteException ("Error invoking remote service.", e); 55 } 56 } 57 } 58 | Popular Tags |