Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,5 @@
Class<?>[] converters();

Class<?>[] interceptors() default {};
Class<?> requestFactory() default Void.class;
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public void validate(Element element, AnnotationElements validatedElements, IsVa

validatorHelper.validateInterceptors(element, valid);

validatorHelper.validateRequestFactory(element, valid);

validatorHelper.hasInternetPermission(typeElement, androidManifest, valid);
}

Expand All @@ -83,6 +85,7 @@ public void process(Element element, RestHolder holder) {
setRootUrl(element, holder);
setConverters(element, holder);
setInterceptors(element, holder);
setRequestFactory(element, holder);
}

private void setRootUrl(Element element, RestHolder holder) {
Expand Down Expand Up @@ -116,4 +119,12 @@ private void setInterceptors(Element element, RestHolder holder) {
}
}
}

private void setRequestFactory(Element element, RestHolder holder) {
DeclaredType requestFactoryType = annotationHelper.extractAnnotationClassParameter(element, getTarget(), "requestFactory");
if (requestFactoryType != null) {
JInvocation requestFactory = codeModelHelper.newBeanOrEBean(holder, requestFactoryType, holder.getInitContextParam());
holder.getInit().body().add(invoke(holder.getRestTemplateField(), "setRequestFactory").arg(requestFactory));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public final class CanonicalNameConstants {
public static final String REST_TEMPLATE = "org.springframework.web.client.RestTemplate";
public static final String HTTP_MESSAGE_CONVERTER = "org.springframework.http.converter.HttpMessageConverter";
public static final String CLIENT_HTTP_REQUEST_INTERCEPTOR = "org.springframework.http.client.ClientHttpRequestInterceptor";
public static final String CLIENT_HTTP_REQUEST_FACTORY = "org.springframework.http.client.ClientHttpRequestFactory";
public static final String HTTP_AUTHENTICATION = "org.springframework.http.HttpAuthentication";
public static final String HTTP_BASIC_AUTHENTICATION = "org.springframework.http.HttpBasicAuthentication";
public static final String REST_CLIENT_EXCEPTION = "org.springframework.web.client.RestClientException";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,65 +15,9 @@
*/
package org.androidannotations.helper;

import static java.util.Arrays.asList;
import static org.androidannotations.helper.AndroidConstants.LOG_DEBUG;
import static org.androidannotations.helper.AndroidConstants.LOG_ERROR;
import static org.androidannotations.helper.AndroidConstants.LOG_INFO;
import static org.androidannotations.helper.AndroidConstants.LOG_VERBOSE;
import static org.androidannotations.helper.AndroidConstants.LOG_WARN;
import static org.androidannotations.helper.CanonicalNameConstants.CLIENT_HTTP_REQUEST_INTERCEPTOR;
import static org.androidannotations.helper.CanonicalNameConstants.HTTP_MESSAGE_CONVERTER;
import static org.androidannotations.helper.CanonicalNameConstants.INTERNET_PERMISSION;
import static org.androidannotations.helper.ModelConstants.GENERATION_SUFFIX;
import static org.androidannotations.helper.ModelConstants.VALID_ENHANCED_COMPONENT_ANNOTATIONS;
import static org.androidannotations.helper.ModelConstants.VALID_ENHANCED_VIEW_SUPPORT_ANNOTATIONS;

import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;

import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.Modifier;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
import javax.lang.model.type.ArrayType;
import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.ErrorType;
import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.ElementFilter;
import javax.lang.model.util.Elements;

import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.EBean;
import org.androidannotations.annotations.EFragment;
import org.androidannotations.annotations.EIntentService;
import org.androidannotations.annotations.EService;
import org.androidannotations.annotations.Receiver;
import org.androidannotations.annotations.Trace;
import org.androidannotations.annotations.ViewById;
import org.androidannotations.annotations.rest.Delete;
import org.androidannotations.annotations.rest.Get;
import org.androidannotations.annotations.rest.Head;
import org.androidannotations.annotations.rest.Options;
import org.androidannotations.annotations.rest.Post;
import org.androidannotations.annotations.rest.Put;
import org.androidannotations.annotations.rest.Rest;
import org.androidannotations.annotations.sharedpreferences.DefaultBoolean;
import org.androidannotations.annotations.sharedpreferences.DefaultFloat;
import org.androidannotations.annotations.sharedpreferences.DefaultInt;
import org.androidannotations.annotations.sharedpreferences.DefaultLong;
import org.androidannotations.annotations.sharedpreferences.DefaultString;
import org.androidannotations.annotations.sharedpreferences.SharedPref;
import org.androidannotations.annotations.*;
import org.androidannotations.annotations.rest.*;
import org.androidannotations.annotations.sharedpreferences.*;
import org.androidannotations.api.rest.RestClientErrorHandling;
import org.androidannotations.api.rest.RestClientHeaders;
import org.androidannotations.api.rest.RestClientRootUrl;
Expand All @@ -83,6 +27,18 @@
import org.androidannotations.model.AnnotationElements;
import org.androidannotations.process.IsValid;

import javax.lang.model.element.*;
import javax.lang.model.type.*;
import javax.lang.model.util.ElementFilter;
import javax.lang.model.util.Elements;
import java.lang.annotation.Annotation;
import java.util.*;

import static java.util.Arrays.asList;
import static org.androidannotations.helper.AndroidConstants.*;
import static org.androidannotations.helper.CanonicalNameConstants.*;
import static org.androidannotations.helper.ModelConstants.*;

public class ValidatorHelper {

private static final List<String> VALID_REST_INTERFACES = asList(RestClientHeaders.class.getName(), RestClientErrorHandling.class.getName(), RestClientRootUrl.class.getName(), RestClientSupport.class.getName());
Expand Down Expand Up @@ -1161,6 +1117,40 @@ public void hasInternetPermission(Element element, AndroidManifest androidManife
}
}

public void validateRequestFactory(Element element, IsValid 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) {
return;
}
List<ExecutableElement> constructors = ElementFilter.constructorsIn(requestFactoryElement.getEnclosedElements());
for (ExecutableElement constructor : constructors) {
if (annotationHelper.isPublic(constructor) && constructor.getParameters().isEmpty()) {
return;
}
}
valid.invalidate();
annotationHelper.printAnnotationError(element, "The requestFactory class must have a public no argument constructor or must be annotated with @EBean");
} else {
valid.invalidate();
annotationHelper.printAnnotationError(element, "The requestFactory class must not be abstract");
}
} else {
valid.invalidate();
annotationHelper.printAnnotationError(element, "The requestFactory class must be a class");
}
} else {
valid.invalidate();
annotationHelper.printAnnotationError(element, "The requestFactory class must be a subtype of " + CLIENT_HTTP_REQUEST_FACTORY);
}
}
}

public void hasBeforeTextChangedMethodParameters(ExecutableElement executableElement, IsValid valid) {
List<? extends VariableElement> parameters = executableElement.getParameters();
boolean charSequenceParameterFound = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Copyright (C) 2010-2013 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.test15.rest;

import org.androidannotations.annotations.EBean;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;

@EBean
public class MyRequestFactory extends HttpComponentsClientHttpRequestFactory {

private static final int TIME_OUT = 30 * 1000;

public MyRequestFactory() {
setConnectTimeout(TIME_OUT);
setReadTimeout(TIME_OUT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@
import org.springframework.web.client.RestTemplate;

// if defined, the rootUrl will be added as a prefix to every request
@Rest(rootUrl = "http://company.com/ajax/services", converters = { MappingJacksonHttpMessageConverter.class, EBeanConverter.class }, interceptors = { RequestInterceptor.class, EBeanInterceptor.class })
@Rest(rootUrl = "http://company.com/ajax/services", converters = { MappingJacksonHttpMessageConverter.class, EBeanConverter.class },
interceptors = { RequestInterceptor.class, EBeanInterceptor.class },
requestFactory = MyRequestFactory.class)
public interface MyService {

// *** GET ***
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.