Skip to content

Instantly share code, notes, and snippets.

@an-sangkil
Created April 20, 2015 02:03
Show Gist options
  • Save an-sangkil/82fe1d33dd0ee1fbadff to your computer and use it in GitHub Desktop.
Save an-sangkil/82fe1d33dd0ee1fbadff to your computer and use it in GitHub Desktop.
Proxy Test
package proxy;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
public class DebugHandler implements InvocationHandler {
public DebugHandler() {
}
private Object target;
public Object getTarget() {
return target;
}
public void setTarget(Object target) {
this.target = target;
}
@Override
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
System.out.println("----------------------------");
System.out.println("Method 호출 = " + method);
return method.invoke(target, args);
}
}
package proxy;
public class EmpManager implements IEmpManager{
public void getMessage () {
System.out.println("message Call");
}
}
package proxy;
public interface IEmpManager {
public void getMessage ();
}
package proxy;
import java.lang.reflect.Proxy;
public class ProxyTest {
public static void main(String args[]) throws Exception {
IEmpManager empManager = new EmpManager();
DebugHandler debugHandler = new DebugHandler();
debugHandler.setTarget(empManager);
IEmpManager proxyManager = (IEmpManager)Proxy.newProxyInstance(IEmpManager.class.getClassLoader(), new Class[] {IEmpManager.class}, debugHandler);
proxyManager.getMessage();
System.out.println("end");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment