Skip to content
Browse files

Merge pull request #132 from square/jw/defer

Defer non-interface methods to normal invocation.
  • Loading branch information...
2 parents 89fd13b + 32e12d7 commit f54d6ad8be61ffe53b578b54c52bf09aa86ad158 @JakeWharton JakeWharton committed
View
18 retrofit/src/main/java/retrofit/http/RestAdapter.java
@@ -5,6 +5,7 @@
import java.io.UnsupportedEncodingException;
import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Proxy;
@@ -100,15 +101,26 @@ private RestAdapter(Server server, Provider<HttpClient> httpClientProvider, Exec
@SuppressWarnings("unchecked")
public <T> T create(Class<T> type) {
return (T) Proxy.newProxyInstance(type.getClassLoader(), new Class<?>[] { type },
- new RestHandler());
+ new RestHandler(type));
}
private class RestHandler implements InvocationHandler {
- final Map<Method, MethodDetails> methodDetailsCache =
+ private final Class<?> declaringType;
+ private final Map<Method, MethodDetails> methodDetailsCache =
new LinkedHashMap<Method, MethodDetails>();
+ RestHandler(Class<?> declaringType) {
+ this.declaringType = declaringType;
+ }
+
@SuppressWarnings("unchecked")
- @Override public Object invoke(Object proxy, Method method, final Object[] args) {
+ @Override public Object invoke(Object proxy, Method method, final Object[] args)
+ throws InvocationTargetException, IllegalAccessException {
+ // If the method is not a direct member of the interface then defer to normal invocation.
+ if (method.getDeclaringClass() != declaringType) {
+ return method.invoke(this, args);
+ }
+
// Load or create the details cache for the current method.
final MethodDetails methodDetails;
synchronized (methodDetailsCache) {
View
1 retrofit/src/test/java/retrofit/http/RestAdapterTest.java
@@ -539,7 +539,6 @@ public void testSynchronousWithAsyncCallback() {
method.init();
}
- @Ignore // TODO Issue #130
@Test public void testNonEndpointMethodsSucceed() {
TypeTestService service = restAdapter.create(TypeTestService.class);
assertThat(service.equals(new Object())).isFalse();

0 comments on commit f54d6ad

Please sign in to comment.
Something went wrong with that request. Please try again.