com.github.tcurrie.rest.factory.proxy.ProxyInvocationHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rest.factory Show documentation
Show all versions of rest.factory Show documentation
Simple rest client-server factory, you give it a url, it does the rest!
package com.github.tcurrie.rest.factory.proxy;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class ProxyInvocationHandler implements InvocationHandler {
private final Map> methodHandlers;
public static > ProxyInvocationHandler create(final Stream methodHandlers) {
return new ProxyInvocationHandler(methodHandlers.collect(Collectors.toMap(ProxyMethod::getMethod, m->m)));
}
private ProxyInvocationHandler(final Map> methodHandlers) {
this.methodHandlers = methodHandlers;
}
@Override
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
return methodHandlers.get(method).invoke(args);
}
}