diff --git a/AndroidAnnotations/androidannotations-rest-spring/rest-spring-api/src/main/java/org/androidannotations/rest/spring/annotations/Rest.java b/AndroidAnnotations/androidannotations-rest-spring/rest-spring-api/src/main/java/org/androidannotations/rest/spring/annotations/Rest.java
index 43fdd3d0a3..57edf93f7a 100644
--- a/AndroidAnnotations/androidannotations-rest-spring/rest-spring-api/src/main/java/org/androidannotations/rest/spring/annotations/Rest.java
+++ b/AndroidAnnotations/androidannotations-rest-spring/rest-spring-api/src/main/java/org/androidannotations/rest/spring/annotations/Rest.java
@@ -170,6 +170,47 @@
*
*
*
+ *
+ *
ResponseErrorHandler
+ *
+ * You can use your own error handler to customize how errors
+ * are handled. The {@link #responseErrorHandler()} parameter lets you define the
+ * {@link org.springframework.web.client.ResponseErrorHandler
+ * ResponseErrorHandler}.
+ *
+ *
+ *
+ * You can inject an {@link org.androidannotations.annotations.EBean EBean} response errork
+ * handler just like as a request factory.
+ *
+ *
+ *
+ * Example :
+ *
+ *
+ * @Rest(converters = MappingJacksonHttpMessageConverter.class, responseErrorHandler = MyResponseErrorHandler.class)
+ * public interface MyRestClient {
+ *
+ * @Get("/events")
+ * EventList getEvents();
+ * }
+ *
+ * public class MyResponseErrorHandler implements ResponseErrorHandler {
+ *
+ * @Override
+ * void handleError(ClientHttpResponse response) throws IOException {
+ * // handles the error in the given response
+ * }
+ *
+ * @Override
+ * boolean hasError(ClientHttpResponse response) throws IOException {
+ * // indicates whether the given response has any errors
+ * return true;
+ * }
+ * }
+ *
+ *
+ *
*
* Magic methods
*
@@ -274,4 +315,11 @@
* @return the request factory class
*/
Class> requestFactory() default Void.class;
+
+ /**
+ * The response error handler class which is used to handle errors.
+ *
+ * @return the response error handler class
+ */
+ Class> responseErrorHandler() default Void.class;
}
diff --git a/AndroidAnnotations/androidannotations-rest-spring/rest-spring-test/src/main/java/org/androidannotations/rest/spring/test/MyResponseErrorHandler.java b/AndroidAnnotations/androidannotations-rest-spring/rest-spring-test/src/main/java/org/androidannotations/rest/spring/test/MyResponseErrorHandler.java
new file mode 100644
index 0000000000..1191a1e10f
--- /dev/null
+++ b/AndroidAnnotations/androidannotations-rest-spring/rest-spring-test/src/main/java/org/androidannotations/rest/spring/test/MyResponseErrorHandler.java
@@ -0,0 +1,40 @@
+/**
+ * Copyright (C) 2010-2015 eBusiness Information, Excilys Group
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed To in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.androidannotations.rest.spring.test;
+
+import java.io.IOException;
+
+import org.springframework.http.client.ClientHttpResponse;
+import org.springframework.web.client.ResponseErrorHandler;
+
+public class MyResponseErrorHandler implements ResponseErrorHandler {
+
+ static boolean instanceCreated = false;
+
+ public MyResponseErrorHandler() {
+ instanceCreated = true;
+ }
+
+ @Override
+ public boolean hasError(ClientHttpResponse clientHttpResponse) throws IOException {
+ return false;
+ }
+
+ @Override
+ public void handleError(ClientHttpResponse clientHttpResponse) throws IOException {
+
+ }
+}
diff --git a/AndroidAnnotations/androidannotations-rest-spring/rest-spring-test/src/main/java/org/androidannotations/rest/spring/test/MyResponseErrorHandlerBean.java b/AndroidAnnotations/androidannotations-rest-spring/rest-spring-test/src/main/java/org/androidannotations/rest/spring/test/MyResponseErrorHandlerBean.java
new file mode 100644
index 0000000000..2cdf560b4e
--- /dev/null
+++ b/AndroidAnnotations/androidannotations-rest-spring/rest-spring-test/src/main/java/org/androidannotations/rest/spring/test/MyResponseErrorHandlerBean.java
@@ -0,0 +1,36 @@
+/**
+ * Copyright (C) 2010-2015 eBusiness Information, Excilys Group
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed To in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.androidannotations.rest.spring.test;
+
+import java.io.IOException;
+
+import org.androidannotations.annotations.EBean;
+import org.springframework.http.client.ClientHttpResponse;
+import org.springframework.web.client.ResponseErrorHandler;
+
+@EBean(scope = EBean.Scope.Singleton)
+public class MyResponseErrorHandlerBean implements ResponseErrorHandler {
+
+ @Override
+ public boolean hasError(ClientHttpResponse clientHttpResponse) throws IOException {
+ return false;
+ }
+
+ @Override
+ public void handleError(ClientHttpResponse clientHttpResponse) throws IOException {
+
+ }
+}
diff --git a/AndroidAnnotations/androidannotations-rest-spring/rest-spring-test/src/main/java/org/androidannotations/rest/spring/test/RestWithSimpleClassResponseErrorHandler.java b/AndroidAnnotations/androidannotations-rest-spring/rest-spring-test/src/main/java/org/androidannotations/rest/spring/test/RestWithSimpleClassResponseErrorHandler.java
new file mode 100644
index 0000000000..e52bc9f10d
--- /dev/null
+++ b/AndroidAnnotations/androidannotations-rest-spring/rest-spring-test/src/main/java/org/androidannotations/rest/spring/test/RestWithSimpleClassResponseErrorHandler.java
@@ -0,0 +1,24 @@
+/**
+ * Copyright (C) 2010-2015 eBusiness Information, Excilys Group
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed To in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.androidannotations.rest.spring.test;
+
+import org.androidannotations.rest.spring.annotations.Rest;
+import org.androidannotations.rest.spring.api.RestClientSupport;
+import org.springframework.http.converter.json.MappingJacksonHttpMessageConverter;
+
+@Rest(converters = { MappingJacksonHttpMessageConverter.class }, responseErrorHandler = MyResponseErrorHandler.class)
+public interface RestWithSimpleClassResponseErrorHandler extends RestClientSupport {
+}
diff --git a/AndroidAnnotations/androidannotations-rest-spring/rest-spring-test/src/main/java/org/androidannotations/rest/spring/test/RestWithSingletonBeanResponseErrorHandler.java b/AndroidAnnotations/androidannotations-rest-spring/rest-spring-test/src/main/java/org/androidannotations/rest/spring/test/RestWithSingletonBeanResponseErrorHandler.java
new file mode 100644
index 0000000000..e95daf9b65
--- /dev/null
+++ b/AndroidAnnotations/androidannotations-rest-spring/rest-spring-test/src/main/java/org/androidannotations/rest/spring/test/RestWithSingletonBeanResponseErrorHandler.java
@@ -0,0 +1,24 @@
+/**
+ * Copyright (C) 2010-2015 eBusiness Information, Excilys Group
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed To in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.androidannotations.rest.spring.test;
+
+import org.androidannotations.rest.spring.annotations.Rest;
+import org.androidannotations.rest.spring.api.RestClientSupport;
+import org.springframework.http.converter.json.MappingJacksonHttpMessageConverter;
+
+@Rest(converters = { MappingJacksonHttpMessageConverter.class }, responseErrorHandler = MyResponseErrorHandlerBean.class)
+public interface RestWithSingletonBeanResponseErrorHandler extends RestClientSupport {
+}
diff --git a/AndroidAnnotations/androidannotations-rest-spring/rest-spring-test/src/test/java/org/androidannotations/rest/spring/test/RestResponseErrorHandlerTest.java b/AndroidAnnotations/androidannotations-rest-spring/rest-spring-test/src/test/java/org/androidannotations/rest/spring/test/RestResponseErrorHandlerTest.java
new file mode 100644
index 0000000000..6c1efcc0b5
--- /dev/null
+++ b/AndroidAnnotations/androidannotations-rest-spring/rest-spring-test/src/test/java/org/androidannotations/rest/spring/test/RestResponseErrorHandlerTest.java
@@ -0,0 +1,45 @@
+/**
+ * Copyright (C) 2010-2015 eBusiness Information, Excilys Group
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed To in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.androidannotations.rest.spring.test;
+
+import static org.fest.assertions.api.Assertions.assertThat;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.Robolectric;
+import org.robolectric.RobolectricTestRunner;
+import org.springframework.web.client.ResponseErrorHandler;
+
+@RunWith(RobolectricTestRunner.class)
+public class RestResponseErrorHandlerTest {
+
+ @Test
+ public void testSameAsSingletonBeanResponseErrorHandler() {
+ RestWithSingletonBeanResponseErrorHandler restClient = new RestWithSingletonBeanResponseErrorHandler_(Robolectric.application);
+ ResponseErrorHandler errorHandler = restClient.getRestTemplate().getErrorHandler();
+ MyResponseErrorHandlerBean errorHandlerBean = MyResponseErrorHandlerBean_.getInstance_(Robolectric.application);
+
+ assertThat(errorHandler).isSameAs(errorHandlerBean);
+ }
+
+ @Test
+ public void testInstanceCreatedFromNonBeanClassAsResponseErrorHandler() {
+ new RestWithSimpleClassResponseErrorHandler_(Robolectric.application);
+
+ assertThat(MyResponseErrorHandler.instanceCreated).isTrue();
+ }
+
+}
diff --git a/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/main/java/org/androidannotations/rest/spring/handler/RestHandler.java b/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/main/java/org/androidannotations/rest/spring/handler/RestHandler.java
index ee902d392f..51ed12d345 100644
--- a/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/main/java/org/androidannotations/rest/spring/handler/RestHandler.java
+++ b/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/main/java/org/androidannotations/rest/spring/handler/RestHandler.java
@@ -78,6 +78,8 @@ public void validate(Element element, ElementValidation validation) {
restSpringValidatorHelper.validateInterceptors(element, validation);
restSpringValidatorHelper.validateRequestFactory(element, validation);
+
+ restSpringValidatorHelper.validateResponseErrorHandler(element, validation);
}
@Override
@@ -86,6 +88,7 @@ public void process(Element element, RestHolder holder) {
setConverters(element, holder);
setInterceptors(element, holder);
setRequestFactory(element, holder);
+ setResponseErrorHandler(element, holder);
}
private void setRootUrl(Element element, RestHolder holder) {
@@ -128,4 +131,12 @@ private void setRequestFactory(Element element, RestHolder holder) {
holder.getInit().body().add(invoke(holder.getRestTemplateField(), "setRequestFactory").arg(requestFactory));
}
}
+
+ private void setResponseErrorHandler(Element element, RestHolder holder) {
+ DeclaredType responseErrorHandler = annotationHelper.extractAnnotationClassParameter(element, getTarget(), "responseErrorHandler");
+ if (responseErrorHandler != null) {
+ JInvocation errorHandler = codeModelHelper.newBeanOrEBean(responseErrorHandler, holder.getInitContextParam());
+ holder.getInit().body().add(invoke(holder.getRestTemplateField(), "setErrorHandler").arg(errorHandler));
+ }
+ }
}
diff --git a/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/main/java/org/androidannotations/rest/spring/helper/RestSpringClasses.java b/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/main/java/org/androidannotations/rest/spring/helper/RestSpringClasses.java
index 106b0a37cd..6eff694ed9 100644
--- a/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/main/java/org/androidannotations/rest/spring/helper/RestSpringClasses.java
+++ b/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/main/java/org/androidannotations/rest/spring/helper/RestSpringClasses.java
@@ -30,6 +30,7 @@ public final class RestSpringClasses {
public static final String HTTP_BASIC_AUTHENTICATION = "org.springframework.http.HttpBasicAuthentication";
public static final String REST_CLIENT_EXCEPTION = "org.springframework.web.client.RestClientException";
public static final String NESTED_RUNTIME_EXCEPTION = "org.springframework.core.NestedRuntimeException";
+ public static final String RESPONSE_ERROR_HANDLER = "org.springframework.web.client.ResponseErrorHandler";
private RestSpringClasses() {
diff --git a/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/main/java/org/androidannotations/rest/spring/helper/RestSpringValidatorHelper.java b/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/main/java/org/androidannotations/rest/spring/helper/RestSpringValidatorHelper.java
index bb18eb8cca..61b8b0a0f5 100644
--- a/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/main/java/org/androidannotations/rest/spring/helper/RestSpringValidatorHelper.java
+++ b/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/main/java/org/androidannotations/rest/spring/helper/RestSpringValidatorHelper.java
@@ -302,36 +302,44 @@ public void validateInterceptors(Element element, ElementValidation valid) {
}
}
- public void validateRequestFactory(Element element, ElementValidation valid) {
- TypeMirror clientHttpRequestFactoryType = annotationHelper.typeElementFromQualifiedName(CLIENT_HTTP_REQUEST_FACTORY).asType();
- DeclaredType requestFactory = annotationHelper.extractAnnotationClassParameter(element, annotationHelper.getTarget(), "requestFactory");
- if (requestFactory != null) {
- if (annotationHelper.isSubtype(requestFactory, clientHttpRequestFactoryType)) {
- Element requestFactoryElement = requestFactory.asElement();
- if (requestFactoryElement.getKind().isClass()) {
- if (!annotationHelper.isAbstract(requestFactoryElement)) {
- if (requestFactoryElement.getAnnotation(EBean.class) != null) {
+ public void validateRestSimpleParameter(Element element, String requiredClass, String parameterName, ElementValidation validation) {
+ TypeMirror requiredType = annotationHelper.typeElementFromQualifiedName(requiredClass).asType();
+ DeclaredType paramterType = annotationHelper.extractAnnotationClassParameter(element, annotationHelper.getTarget(), parameterName);
+ if (paramterType != null) {
+ if (annotationHelper.isSubtype(paramterType, requiredType)) {
+ Element parameterElement = paramterType.asElement();
+ if (parameterElement.getKind().isClass()) {
+ if (!annotationHelper.isAbstract(parameterElement)) {
+ if (parameterElement.getAnnotation(EBean.class) != null) {
return;
}
- List constructors = ElementFilter.constructorsIn(requestFactoryElement.getEnclosedElements());
+ List constructors = ElementFilter.constructorsIn(parameterElement.getEnclosedElements());
for (ExecutableElement constructor : constructors) {
if (annotationHelper.isPublic(constructor) && constructor.getParameters().isEmpty()) {
return;
}
}
- valid.addError("The requestFactory class must have a public no argument constructor or must be annotated with @EBean");
+ validation.addError(element, "The " + parameterName + " class must have a public no argument constructor or must be annotated with @EBean");
} else {
- valid.addError("The requestFactory class must not be abstract");
+ validation.addError(element, "The " + parameterName + " class must not be abstract");
}
} else {
- valid.addError("The requestFactory class must be a class");
+ validation.addError(element, "The " + parameterName + " class must be a class");
}
} else {
- valid.addError("The requestFactory class must be a subtype of " + CLIENT_HTTP_REQUEST_FACTORY);
+ validation.addError(element, "The " + parameterName + " class must be a subtype of " + requiredClass);
}
}
}
+ public void validateRequestFactory(Element element, ElementValidation validation) {
+ validateRestSimpleParameter(element, CLIENT_HTTP_REQUEST_FACTORY, "requestFactory", validation);
+ }
+
+ public void validateResponseErrorHandler(Element element, ElementValidation validation) {
+ validateRestSimpleParameter(element, RestSpringClasses.RESPONSE_ERROR_HANDLER, "responseErrorHandler", validation);
+ }
+
public void throwsOnlyRestClientException(ExecutableElement element, ElementValidation valid) {
List extends TypeMirror> thrownTypes = element.getThrownTypes();
if (thrownTypes.size() > 0) {
diff --git a/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/test/java/org/androidannotations/rest/spring/AbstractResponseErrorHandler.java b/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/test/java/org/androidannotations/rest/spring/AbstractResponseErrorHandler.java
new file mode 100644
index 0000000000..65f89c22c5
--- /dev/null
+++ b/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/test/java/org/androidannotations/rest/spring/AbstractResponseErrorHandler.java
@@ -0,0 +1,22 @@
+/**
+ * Copyright (C) 2010-2015 eBusiness Information, Excilys Group
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed To in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.androidannotations.rest.spring;
+
+import org.springframework.web.client.ResponseErrorHandler;
+
+public abstract class AbstractResponseErrorHandler implements ResponseErrorHandler {
+
+}
diff --git a/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/test/java/org/androidannotations/rest/spring/ClientWithAbstractResponseErrorHandler.java b/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/test/java/org/androidannotations/rest/spring/ClientWithAbstractResponseErrorHandler.java
new file mode 100644
index 0000000000..acc97ef39b
--- /dev/null
+++ b/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/test/java/org/androidannotations/rest/spring/ClientWithAbstractResponseErrorHandler.java
@@ -0,0 +1,24 @@
+/**
+ * Copyright (C) 2010-2015 eBusiness Information, Excilys Group
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed To in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.androidannotations.rest.spring;
+
+import org.androidannotations.rest.spring.annotations.Rest;
+import org.springframework.http.converter.json.MappingJacksonHttpMessageConverter;
+
+@Rest(converters = { MappingJacksonHttpMessageConverter.class }, responseErrorHandler = AbstractResponseErrorHandler.class)
+public interface ClientWithAbstractResponseErrorHandler {
+
+}
diff --git a/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/test/java/org/androidannotations/rest/spring/ClientWithNonClassResponseErrorHandler.java b/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/test/java/org/androidannotations/rest/spring/ClientWithNonClassResponseErrorHandler.java
new file mode 100644
index 0000000000..b255df16c4
--- /dev/null
+++ b/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/test/java/org/androidannotations/rest/spring/ClientWithNonClassResponseErrorHandler.java
@@ -0,0 +1,26 @@
+/**
+ * Copyright (C) 2010-2015 eBusiness Information, Excilys Group
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed To in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.androidannotations.rest.spring;
+
+
+import org.androidannotations.rest.spring.annotations.Rest;
+import org.springframework.http.converter.json.MappingJacksonHttpMessageConverter;
+import org.springframework.web.client.ResponseErrorHandler;
+
+@Rest(converters = { MappingJacksonHttpMessageConverter.class }, responseErrorHandler = ResponseErrorHandler.class)
+public interface ClientWithNonClassResponseErrorHandler {
+
+}
diff --git a/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/test/java/org/androidannotations/rest/spring/ClientWithNonResponseErrorHandler.java b/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/test/java/org/androidannotations/rest/spring/ClientWithNonResponseErrorHandler.java
new file mode 100644
index 0000000000..2127a3168e
--- /dev/null
+++ b/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/test/java/org/androidannotations/rest/spring/ClientWithNonResponseErrorHandler.java
@@ -0,0 +1,24 @@
+/**
+ * Copyright (C) 2010-2015 eBusiness Information, Excilys Group
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed To in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.androidannotations.rest.spring;
+
+import org.androidannotations.rest.spring.annotations.Rest;
+import org.springframework.http.converter.json.MappingJacksonHttpMessageConverter;
+
+@Rest(converters = { MappingJacksonHttpMessageConverter.class }, responseErrorHandler = Object.class)
+public interface ClientWithNonResponseErrorHandler {
+
+}
diff --git a/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/test/java/org/androidannotations/rest/spring/ClientWithValidResponseErrorHandler.java b/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/test/java/org/androidannotations/rest/spring/ClientWithValidResponseErrorHandler.java
new file mode 100644
index 0000000000..d00c9a0c38
--- /dev/null
+++ b/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/test/java/org/androidannotations/rest/spring/ClientWithValidResponseErrorHandler.java
@@ -0,0 +1,24 @@
+/**
+ * Copyright (C) 2010-2015 eBusiness Information, Excilys Group
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed To in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.androidannotations.rest.spring;
+
+
+import org.androidannotations.rest.spring.annotations.Rest;
+import org.springframework.http.converter.json.MappingJacksonHttpMessageConverter;
+
+@Rest(converters = { MappingJacksonHttpMessageConverter.class }, responseErrorHandler = ValidResponseErrorHandler.class)
+public interface ClientWithValidResponseErrorHandler {
+}
diff --git a/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/test/java/org/androidannotations/rest/spring/ClientWithWrongConstructorResponseErrorHandler.java b/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/test/java/org/androidannotations/rest/spring/ClientWithWrongConstructorResponseErrorHandler.java
new file mode 100644
index 0000000000..744c91d3c8
--- /dev/null
+++ b/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/test/java/org/androidannotations/rest/spring/ClientWithWrongConstructorResponseErrorHandler.java
@@ -0,0 +1,24 @@
+/**
+ * Copyright (C) 2010-2015 eBusiness Information, Excilys Group
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed To in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.androidannotations.rest.spring;
+
+import org.androidannotations.rest.spring.annotations.Rest;
+import org.springframework.http.converter.json.MappingJacksonHttpMessageConverter;
+
+@Rest(converters = { MappingJacksonHttpMessageConverter.class }, responseErrorHandler = WrongConstructorResponseErrorHandler.class)
+public interface ClientWithWrongConstructorResponseErrorHandler {
+
+}
diff --git a/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/test/java/org/androidannotations/rest/spring/RestResponseErrorHandlerTest.java b/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/test/java/org/androidannotations/rest/spring/RestResponseErrorHandlerTest.java
new file mode 100644
index 0000000000..1c64c0b482
--- /dev/null
+++ b/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/test/java/org/androidannotations/rest/spring/RestResponseErrorHandlerTest.java
@@ -0,0 +1,61 @@
+/**
+ * Copyright (C) 2010-2015 eBusiness Information, Excilys Group
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed To in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.androidannotations.rest.spring;
+
+import java.io.IOException;
+
+import org.androidannotations.internal.AndroidAnnotationProcessor;
+import org.androidannotations.testutils.AAProcessorTestHelper;
+import org.junit.Before;
+import org.junit.Test;
+
+public class RestResponseErrorHandlerTest extends AAProcessorTestHelper {
+
+ @Before
+ public void setUp() {
+ addManifestProcessorParameter(RestInterceptorTest.class);
+ addProcessor(AndroidAnnotationProcessor.class);
+ }
+
+ @Test
+ public void clientWithValidResponseErrorHandlerCompiles() {
+ CompileResult result = compileFiles(ClientWithValidResponseErrorHandler.class);
+ assertCompilationSuccessful(result);
+ }
+
+ @Test
+ public void clientWithNonResponseErrorHandlerDoesNotCompile() throws IOException {
+ CompileResult result = compileFiles(ClientWithNonResponseErrorHandler.class);
+ assertCompilationErrorOn(ClientWithNonResponseErrorHandler.class, "@Rest", result);
+ }
+
+ @Test
+ public void clientWithWrongConstructorResponseErrorHandlerDoesNotCompile() throws IOException {
+ CompileResult result = compileFiles(ClientWithWrongConstructorResponseErrorHandler.class);
+ assertCompilationErrorOn(ClientWithWrongConstructorResponseErrorHandler.class, "@Rest", result);
+ }
+
+ @Test
+ public void clientWithAbstractResponseErrorHandlerDoesNotCompile() throws IOException {
+ CompileResult result = compileFiles(ClientWithAbstractResponseErrorHandler.class);
+ assertCompilationErrorOn(ClientWithAbstractResponseErrorHandler.class, "@Rest", result);
+ }
+ @Test
+ public void clientWithNonClassResponseErrorHandlerDoesNotCompile() throws IOException {
+ CompileResult result = compileFiles(ClientWithNonClassResponseErrorHandler.class);
+ assertCompilationErrorOn(ClientWithNonClassResponseErrorHandler.class, "@Rest", result);
+ }
+}
diff --git a/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/test/java/org/androidannotations/rest/spring/ValidResponseErrorHandler.java b/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/test/java/org/androidannotations/rest/spring/ValidResponseErrorHandler.java
new file mode 100644
index 0000000000..8d51a3d4cd
--- /dev/null
+++ b/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/test/java/org/androidannotations/rest/spring/ValidResponseErrorHandler.java
@@ -0,0 +1,34 @@
+/**
+ * Copyright (C) 2010-2015 eBusiness Information, Excilys Group
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed To in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.androidannotations.rest.spring;
+
+import java.io.IOException;
+
+import org.springframework.http.client.ClientHttpResponse;
+import org.springframework.web.client.ResponseErrorHandler;
+
+public class ValidResponseErrorHandler implements ResponseErrorHandler {
+
+ @Override
+ public boolean hasError(ClientHttpResponse clientHttpResponse) throws IOException {
+ return false;
+ }
+
+ @Override
+ public void handleError(ClientHttpResponse clientHttpResponse) throws IOException {
+
+ }
+}
diff --git a/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/test/java/org/androidannotations/rest/spring/WrongConstructorResponseErrorHandler.java b/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/test/java/org/androidannotations/rest/spring/WrongConstructorResponseErrorHandler.java
new file mode 100644
index 0000000000..b88a49e18b
--- /dev/null
+++ b/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/test/java/org/androidannotations/rest/spring/WrongConstructorResponseErrorHandler.java
@@ -0,0 +1,42 @@
+/**
+ * Copyright (C) 2010-2015 eBusiness Information, Excilys Group
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed To in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.androidannotations.rest.spring;
+
+import java.io.IOException;
+
+import org.springframework.http.client.ClientHttpResponse;
+import org.springframework.web.client.ResponseErrorHandler;
+
+public class WrongConstructorResponseErrorHandler implements ResponseErrorHandler {
+
+ public WrongConstructorResponseErrorHandler(String someParam) {
+ this();
+ }
+
+ private WrongConstructorResponseErrorHandler() {
+
+ }
+
+ @Override
+ public boolean hasError(ClientHttpResponse clientHttpResponse) throws IOException {
+ return false;
+ }
+
+ @Override
+ public void handleError(ClientHttpResponse clientHttpResponse) throws IOException {
+
+ }
+}
\ No newline at end of file