mirror of https://github.com/apache/jclouds.git
cleaned up unnecessary wrapping of ExecutionException
This commit is contained in:
parent
ed0e6f2ebe
commit
d3555e7988
|
@ -64,11 +64,11 @@ public class CreateClientForCaller extends CacheLoader<ClassMethodArgs, Object>
|
|||
}
|
||||
|
||||
@Override
|
||||
public Object load(ClassMethodArgs from) throws ExecutionException {
|
||||
public Object load(ClassMethodArgs from) {
|
||||
Class<?> syncClass = Optionals2.returnTypeOrTypeOfOptional(from.getMethod());
|
||||
Class<?> asyncClass = sync2Async.get(syncClass);
|
||||
checkState(asyncClass != null, "configuration error, sync class " + syncClass + " not mapped to an async class");
|
||||
Object asyncClient = asyncMap.get(from);
|
||||
Object asyncClient = asyncMap.getUnchecked(from);
|
||||
checkState(asyncClient != null, "configuration error, sync client for " + from + " not found");
|
||||
Function<ClassMethodArgsAndReturnVal, Optional<Object>> optionalConverter = injector.getInstance(Key.get(new TypeLiteral<Function<ClassMethodArgsAndReturnVal, Optional<Object>>>() {
|
||||
}));
|
||||
|
|
|
@ -51,7 +51,6 @@ import java.util.Map.Entry;
|
|||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Provider;
|
||||
|
@ -145,7 +144,6 @@ import com.google.common.base.Preconditions;
|
|||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
|
@ -324,7 +322,7 @@ public class RestAnnotationProcessor<T> {
|
|||
@Inject
|
||||
public RestAnnotationProcessor(Injector injector, LoadingCache<Class<?>, Boolean> seedAnnotationCache, Cache<MethodKey, Method> delegationMap,
|
||||
@ApiVersion String apiVersion, @BuildVersion String buildVersion, ParseSax.Factory parserFactory,
|
||||
HttpUtils utils, ContentMetadataCodec contentMetadataCodec, TypeLiteral<T> typeLiteral) throws ExecutionException {
|
||||
HttpUtils utils, ContentMetadataCodec contentMetadataCodec, TypeLiteral<T> typeLiteral) {
|
||||
this.declaring = (Class<T>) typeLiteral.getRawType();
|
||||
this.injector = injector;
|
||||
this.parserFactory = parserFactory;
|
||||
|
@ -332,7 +330,7 @@ public class RestAnnotationProcessor<T> {
|
|||
this.contentMetadataCodec = contentMetadataCodec;
|
||||
this.uriBuilderProvider = injector.getProvider(UriBuilder.class);
|
||||
this.seedAnnotationCache = seedAnnotationCache;
|
||||
seedAnnotationCache.get(declaring);
|
||||
seedAnnotationCache.getUnchecked(declaring);
|
||||
this.delegationMap = delegationMap;
|
||||
if (declaring.isAnnotationPresent(SkipEncoding.class)) {
|
||||
skips = declaring.getAnnotation(SkipEncoding.class).value();
|
||||
|
@ -386,24 +384,18 @@ public class RestAnnotationProcessor<T> {
|
|||
private URI callerEndpoint;
|
||||
|
||||
public void setCaller(ClassMethodArgs caller) {
|
||||
try {
|
||||
seedAnnotationCache.get(caller.getMethod().getDeclaringClass());
|
||||
} catch (ExecutionException e) {
|
||||
Throwables.propagate(e);
|
||||
}
|
||||
seedAnnotationCache.getUnchecked(caller.getMethod().getDeclaringClass());
|
||||
this.caller = caller;
|
||||
try {
|
||||
UriBuilder builder = uriBuilderProvider.get().uri(getEndpointFor(caller.getMethod(), caller.getArgs(), injector));
|
||||
Multimap<String, String> tokenValues = addPathAndGetTokens(caller.getMethod().getDeclaringClass(), caller.getMethod(), caller.getArgs(), builder);
|
||||
callerEndpoint = builder.buildFromEncodedMap(Maps2.convertUnsafe(tokenValues));
|
||||
} catch (IllegalStateException e) {
|
||||
} catch (ExecutionException e) {
|
||||
Throwables.propagate(e);
|
||||
// no endpoint annotation
|
||||
}
|
||||
}
|
||||
|
||||
public GeneratedHttpRequest createRequest(Method method, Object... args) {
|
||||
try {
|
||||
inputParamValidator.validateMethodParametersOrThrow(method, args);
|
||||
ClassMethodArgs cma = logger.isTraceEnabled() ? new ClassMethodArgs(method.getDeclaringClass(), method, args)
|
||||
: null;
|
||||
|
@ -547,9 +539,6 @@ public class RestAnnotationProcessor<T> {
|
|||
}
|
||||
utils.checkRequestHasRequiredProperties(request);
|
||||
return request;
|
||||
} catch (ExecutionException e) {
|
||||
throw Throwables.propagate(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static Multimap<String, String> filterOutContentHeaders(Multimap<String, String> headers) {
|
||||
|
@ -563,7 +552,7 @@ public class RestAnnotationProcessor<T> {
|
|||
|
||||
public static final String BOUNDARY = "--JCLOUDS--";
|
||||
|
||||
private Multimap<String, String> addPathAndGetTokens(Class<?> clazz, Method method, Object[] args, UriBuilder builder) throws ExecutionException {
|
||||
private Multimap<String, String> addPathAndGetTokens(Class<?> clazz, Method method, Object[] args, UriBuilder builder) {
|
||||
if (clazz.isAnnotationPresent(Path.class))
|
||||
builder.path(clazz);
|
||||
if (method.isAnnotationPresent(Path.class))
|
||||
|
@ -583,7 +572,7 @@ public class RestAnnotationProcessor<T> {
|
|||
}
|
||||
|
||||
private Multimap<String, String> addMatrixParams(Collection<Entry<String, String>> tokenValues, Method method,
|
||||
Object... args) throws ExecutionException {
|
||||
Object... args) {
|
||||
Multimap<String, String> matrixMap = LinkedListMultimap.create();
|
||||
if (declaring.isAnnotationPresent(MatrixParams.class)) {
|
||||
MatrixParams matrix = declaring.getAnnotation(MatrixParams.class);
|
||||
|
@ -602,7 +591,7 @@ public class RestAnnotationProcessor<T> {
|
|||
}
|
||||
|
||||
private Multimap<String, String> addFormParams(Collection<Entry<String, String>> tokenValues, Method method,
|
||||
Object... args) throws ExecutionException {
|
||||
Object... args) {
|
||||
Multimap<String, String> formMap = LinkedListMultimap.create();
|
||||
if (declaring.isAnnotationPresent(FormParams.class)) {
|
||||
FormParams form = declaring.getAnnotation(FormParams.class);
|
||||
|
@ -621,7 +610,7 @@ public class RestAnnotationProcessor<T> {
|
|||
}
|
||||
|
||||
private Multimap<String, String> addQueryParams(Collection<Entry<String, String>> tokenValues, Method method,
|
||||
Object... args) throws ExecutionException {
|
||||
Object... args) {
|
||||
Multimap<String, String> queryMap = LinkedListMultimap.create();
|
||||
if (declaring.isAnnotationPresent(QueryParams.class)) {
|
||||
QueryParams query = declaring.getAnnotation(QueryParams.class);
|
||||
|
@ -712,7 +701,7 @@ public class RestAnnotationProcessor<T> {
|
|||
//TODO: change to LoadingCache<ClassMethodArgs, Optional<URI>> and move this logic to the CacheLoader.
|
||||
@VisibleForTesting
|
||||
public static URI getEndpointInParametersOrNull(Method method, final Object[] args, Injector injector)
|
||||
throws ExecutionException {
|
||||
{
|
||||
Map<Integer, Set<Annotation>> map = indexWithAtLeastOneAnnotation(method,
|
||||
methodToIndexOfParamToEndpointParamAnnotations);
|
||||
if (map.size() >= 1 && args.length > 0) {
|
||||
|
@ -757,7 +746,7 @@ public class RestAnnotationProcessor<T> {
|
|||
};
|
||||
|
||||
// TODO: change to LoadingCache<ClassMethodArgs, URI> and move this logic to the CacheLoader.
|
||||
public static URI getEndpointFor(Method method, Object[] args, Injector injector) throws ExecutionException {
|
||||
public static URI getEndpointFor(Method method, Object[] args, Injector injector) {
|
||||
URI endpoint = getEndpointInParametersOrNull(method, args, injector);
|
||||
if (endpoint == null) {
|
||||
Endpoint annotation;
|
||||
|
@ -951,13 +940,13 @@ public class RestAnnotationProcessor<T> {
|
|||
}
|
||||
};
|
||||
|
||||
public GeneratedHttpRequest decorateRequest(GeneratedHttpRequest request) throws NegativeArraySizeException,
|
||||
ExecutionException {
|
||||
OUTER: for (Entry<Integer, Set<Annotation>> entry : concat(//
|
||||
filterValues(methodToIndexOfParamToBinderParamAnnotation.get(request.getJavaMethod()).asMap(), notEmpty)
|
||||
.entrySet(), //
|
||||
filterValues(methodToIndexOfParamToWrapWithAnnotation.get(request.getJavaMethod()).asMap(), notEmpty)
|
||||
.entrySet())) {
|
||||
public GeneratedHttpRequest decorateRequest(GeneratedHttpRequest request) throws NegativeArraySizeException {
|
||||
Iterable<Entry<Integer, Set<Annotation>>> binderOrWrapWith = concat(
|
||||
filterValues(methodToIndexOfParamToBinderParamAnnotation.getUnchecked(request.getJavaMethod()).asMap(),
|
||||
notEmpty).entrySet(),
|
||||
filterValues(methodToIndexOfParamToWrapWithAnnotation.getUnchecked(request.getJavaMethod()).asMap(),
|
||||
notEmpty).entrySet());
|
||||
OUTER: for (Entry<Integer, Set<Annotation>> entry : binderOrWrapWith) {
|
||||
boolean shouldBreak = false;
|
||||
Annotation annotation = Iterables.get(entry.getValue(), 0);
|
||||
Binder binder;
|
||||
|
@ -1019,7 +1008,7 @@ public class RestAnnotationProcessor<T> {
|
|||
}
|
||||
|
||||
public static Map<Integer, Set<Annotation>> indexWithOnlyOneAnnotation(Method method, String description,
|
||||
LoadingCache<Method, LoadingCache<Integer, Set<Annotation>>> toRefine) throws ExecutionException {
|
||||
LoadingCache<Method, LoadingCache<Integer, Set<Annotation>>> toRefine) {
|
||||
Map<Integer, Set<Annotation>> indexToPayloadAnnotation = indexWithAtLeastOneAnnotation(method, toRefine);
|
||||
if (indexToPayloadAnnotation.size() > 1) {
|
||||
throw new IllegalStateException(String.format(
|
||||
|
@ -1030,8 +1019,8 @@ public class RestAnnotationProcessor<T> {
|
|||
}
|
||||
|
||||
private static Map<Integer, Set<Annotation>> indexWithAtLeastOneAnnotation(Method method,
|
||||
LoadingCache<Method, LoadingCache<Integer, Set<Annotation>>> toRefine) throws ExecutionException {
|
||||
Map<Integer, Set<Annotation>> indexToPayloadAnnotation = filterValues(toRefine.get(method).asMap(),
|
||||
LoadingCache<Method, LoadingCache<Integer, Set<Annotation>>> toRefine) {
|
||||
Map<Integer, Set<Annotation>> indexToPayloadAnnotation = filterValues(toRefine.getUnchecked(method).asMap(),
|
||||
new Predicate<Set<Annotation>>() {
|
||||
public boolean apply(Set<Annotation> input) {
|
||||
return input.size() == 1;
|
||||
|
@ -1041,9 +1030,9 @@ public class RestAnnotationProcessor<T> {
|
|||
}
|
||||
|
||||
//TODO: change to LoadingCache<ClassMethodArgs, HttpRequestOptions and move this logic to the CacheLoader.
|
||||
private Set<HttpRequestOptions> findOptionsIn(Method method, Object... args) throws ExecutionException {
|
||||
private Set<HttpRequestOptions> findOptionsIn(Method method, Object... args) {
|
||||
ImmutableSet.Builder<HttpRequestOptions> result = ImmutableSet.builder();
|
||||
for (int index : methodToIndexesOfOptions.get(method)) {
|
||||
for (int index : methodToIndexesOfOptions.getUnchecked(method)) {
|
||||
if (args.length >= index + 1) {// accommodate varargs
|
||||
if (args[index] instanceof Object[]) {
|
||||
for (Object option : (Object[]) args[index]) {
|
||||
|
@ -1064,10 +1053,11 @@ public class RestAnnotationProcessor<T> {
|
|||
}
|
||||
|
||||
public Multimap<String, String> buildHeaders(Collection<Entry<String, String>> tokenValues, Method method,
|
||||
final Object... args) throws ExecutionException {
|
||||
final Object... args) {
|
||||
Multimap<String, String> headers = LinkedHashMultimap.create();
|
||||
addHeaderIfAnnotationPresentOnMethod(headers, method, tokenValues);
|
||||
LoadingCache<Integer, Set<Annotation>> indexToHeaderParam = methodToIndexOfParamToHeaderParamAnnotations.get(method);
|
||||
LoadingCache<Integer, Set<Annotation>> indexToHeaderParam = methodToIndexOfParamToHeaderParamAnnotations
|
||||
.getUnchecked(method);
|
||||
for (Entry<Integer, Set<Annotation>> entry : indexToHeaderParam.asMap().entrySet()) {
|
||||
for (Annotation key : entry.getValue()) {
|
||||
String value = args[entry.getKey()].toString();
|
||||
|
@ -1132,9 +1122,10 @@ public class RestAnnotationProcessor<T> {
|
|||
|
||||
}
|
||||
|
||||
List<? extends Part> getParts(Method method, Object[] args, Iterable<Entry<String, String>> iterable) throws ExecutionException {
|
||||
List<? extends Part> getParts(Method method, Object[] args, Iterable<Entry<String, String>> iterable) {
|
||||
List<Part> parts = newLinkedList();
|
||||
LoadingCache<Integer, Set<Annotation>> indexToPartParam = methodToIndexOfParamToPartParamAnnotations.get(method);
|
||||
LoadingCache<Integer, Set<Annotation>> indexToPartParam = methodToIndexOfParamToPartParamAnnotations
|
||||
.getUnchecked(method);
|
||||
for (Entry<Integer, Set<Annotation>> entry : indexToPartParam.asMap().entrySet()) {
|
||||
for (Annotation key : entry.getValue()) {
|
||||
PartParam param = (PartParam) key;
|
||||
|
@ -1173,14 +1164,14 @@ public class RestAnnotationProcessor<T> {
|
|||
}
|
||||
|
||||
//TODO: change to LoadingCache<ClassMethodArgs, Multimap<String,String> and move this logic to the CacheLoader.
|
||||
private Multimap<String, String> getPathParamKeyValues(Method method, Object... args) throws ExecutionException {
|
||||
private Multimap<String, String> getPathParamKeyValues(Method method, Object... args) {
|
||||
Multimap<String, String> pathParamValues = LinkedHashMultimap.create();
|
||||
LoadingCache<Integer, Set<Annotation>> indexToPathParam = methodToIndexOfParamToPathParamAnnotations.get(method);
|
||||
LoadingCache<Integer, Set<Annotation>> indexToPathParam = methodToIndexOfParamToPathParamAnnotations.getUnchecked(method);
|
||||
|
||||
LoadingCache<Integer, Set<Annotation>> indexToParamExtractor = methodToIndexOfParamToParamParserAnnotations.get(method);
|
||||
LoadingCache<Integer, Set<Annotation>> indexToParamExtractor = methodToIndexOfParamToParamParserAnnotations.getUnchecked(method);
|
||||
for (Entry<Integer, Set<Annotation>> entry : indexToPathParam.asMap().entrySet()) {
|
||||
for (Annotation key : entry.getValue()) {
|
||||
Set<Annotation> extractors = indexToParamExtractor.get(entry.getKey());
|
||||
Set<Annotation> extractors = indexToParamExtractor.getUnchecked(entry.getKey());
|
||||
String paramKey = ((PathParam) key).value();
|
||||
Optional<?> paramValue = getParamValue(method, args, extractors, entry, paramKey);
|
||||
if (paramValue.isPresent())
|
||||
|
@ -1241,14 +1232,16 @@ public class RestAnnotationProcessor<T> {
|
|||
}
|
||||
|
||||
//TODO: change to LoadingCache<ClassMethodArgs, Multimap<String,String> and move this logic to the CacheLoader.
|
||||
private Multimap<String, String> getMatrixParamKeyValues(Method method, Object... args) throws ExecutionException {
|
||||
private Multimap<String, String> getMatrixParamKeyValues(Method method, Object... args) {
|
||||
Multimap<String, String> matrixParamValues = LinkedHashMultimap.create();
|
||||
LoadingCache<Integer, Set<Annotation>> indexToMatrixParam = methodToIndexOfParamToMatrixParamAnnotations.get(method);
|
||||
LoadingCache<Integer, Set<Annotation>> indexToMatrixParam = methodToIndexOfParamToMatrixParamAnnotations
|
||||
.getUnchecked(method);
|
||||
|
||||
LoadingCache<Integer, Set<Annotation>> indexToParamExtractor = methodToIndexOfParamToParamParserAnnotations.get(method);
|
||||
LoadingCache<Integer, Set<Annotation>> indexToParamExtractor = methodToIndexOfParamToParamParserAnnotations
|
||||
.getUnchecked(method);
|
||||
for (Entry<Integer, Set<Annotation>> entry : indexToMatrixParam.asMap().entrySet()) {
|
||||
for (Annotation key : entry.getValue()) {
|
||||
Set<Annotation> extractors = indexToParamExtractor.get(entry.getKey());
|
||||
Set<Annotation> extractors = indexToParamExtractor.getUnchecked(entry.getKey());
|
||||
String paramKey = ((MatrixParam) key).value();
|
||||
Optional<?> paramValue = getParamValue(method, args, extractors, entry, paramKey);
|
||||
if (paramValue.isPresent())
|
||||
|
@ -1267,14 +1260,16 @@ public class RestAnnotationProcessor<T> {
|
|||
|
||||
//TODO: change to LoadingCache<ClassMethodArgs, Multimap<String,String> and move this logic to the CacheLoader.
|
||||
//take care to manage size of this cache
|
||||
private Multimap<String, String> getFormParamKeyValues(Method method, Object... args) throws ExecutionException {
|
||||
private Multimap<String, String> getFormParamKeyValues(Method method, Object... args) {
|
||||
Multimap<String, String> formParamValues = LinkedHashMultimap.create();
|
||||
LoadingCache<Integer, Set<Annotation>> indexToFormParam = methodToIndexOfParamToFormParamAnnotations.get(method);
|
||||
LoadingCache<Integer, Set<Annotation>> indexToFormParam = methodToIndexOfParamToFormParamAnnotations
|
||||
.getUnchecked(method);
|
||||
|
||||
LoadingCache<Integer, Set<Annotation>> indexToParamExtractor = methodToIndexOfParamToParamParserAnnotations.get(method);
|
||||
LoadingCache<Integer, Set<Annotation>> indexToParamExtractor = methodToIndexOfParamToParamParserAnnotations
|
||||
.getUnchecked(method);
|
||||
for (Entry<Integer, Set<Annotation>> entry : indexToFormParam.asMap().entrySet()) {
|
||||
for (Annotation key : entry.getValue()) {
|
||||
Set<Annotation> extractors = indexToParamExtractor.get(entry.getKey());
|
||||
Set<Annotation> extractors = indexToParamExtractor.getUnchecked(entry.getKey());
|
||||
String paramKey = ((FormParam) key).value();
|
||||
Optional<?> paramValue = getParamValue(method, args, extractors, entry, paramKey);
|
||||
if (paramValue.isPresent())
|
||||
|
@ -1292,14 +1287,16 @@ public class RestAnnotationProcessor<T> {
|
|||
}
|
||||
|
||||
//TODO: change to LoadingCache<ClassMethodArgs, Multimap<String,String> and move this logic to the CacheLoader.
|
||||
private Multimap<String, String> getQueryParamKeyValues(Method method, Object... args) throws ExecutionException {
|
||||
private Multimap<String, String> getQueryParamKeyValues(Method method, Object... args) {
|
||||
Multimap<String, String> queryParamValues = LinkedHashMultimap.create();
|
||||
LoadingCache<Integer, Set<Annotation>> indexToQueryParam = methodToIndexOfParamToQueryParamAnnotations.get(method);
|
||||
LoadingCache<Integer, Set<Annotation>> indexToQueryParam = methodToIndexOfParamToQueryParamAnnotations
|
||||
.getUnchecked(method);
|
||||
|
||||
LoadingCache<Integer, Set<Annotation>> indexToParamExtractor = methodToIndexOfParamToParamParserAnnotations.get(method);
|
||||
LoadingCache<Integer, Set<Annotation>> indexToParamExtractor = methodToIndexOfParamToParamParserAnnotations
|
||||
.getUnchecked(method);
|
||||
for (Entry<Integer, Set<Annotation>> entry : indexToQueryParam.asMap().entrySet()) {
|
||||
for (Annotation key : entry.getValue()) {
|
||||
Set<Annotation> extractors = indexToParamExtractor.get(entry.getKey());
|
||||
Set<Annotation> extractors = indexToParamExtractor.getUnchecked(entry.getKey());
|
||||
String paramKey = ((QueryParam) key).value();
|
||||
Optional<?> paramValue = getParamValue(method, args, extractors, entry, paramKey);
|
||||
if (paramValue.isPresent())
|
||||
|
@ -1318,13 +1315,13 @@ public class RestAnnotationProcessor<T> {
|
|||
|
||||
//TODO: change to LoadingCache<ClassMethodArgs, Map<String,Object> and move this logic to the CacheLoader.
|
||||
//take care to manage size of this cache
|
||||
private Map<String, Object> buildPostParams(Method method, Object... args) throws ExecutionException {
|
||||
private Map<String, Object> buildPostParams(Method method, Object... args) {
|
||||
Map<String, Object> postParams = newHashMap();
|
||||
LoadingCache<Integer, Set<Annotation>> indexToPathParam = methodToIndexOfParamToPostParamAnnotations.get(method);
|
||||
LoadingCache<Integer, Set<Annotation>> indexToParamExtractor = methodToIndexOfParamToParamParserAnnotations.get(method);
|
||||
LoadingCache<Integer, Set<Annotation>> indexToPathParam = methodToIndexOfParamToPostParamAnnotations.getUnchecked(method);
|
||||
LoadingCache<Integer, Set<Annotation>> indexToParamExtractor = methodToIndexOfParamToParamParserAnnotations.getUnchecked(method);
|
||||
for (Entry<Integer, Set<Annotation>> entry : indexToPathParam.asMap().entrySet()) {
|
||||
for (Annotation key : entry.getValue()) {
|
||||
Set<Annotation> extractors = indexToParamExtractor.get(entry.getKey());
|
||||
Set<Annotation> extractors = indexToParamExtractor.getUnchecked(entry.getKey());
|
||||
String paramKey = ((PayloadParam) key).value();
|
||||
Optional<?> paramValue = getParamValue(method, args, extractors, entry, paramKey);
|
||||
if (paramValue.isPresent())
|
||||
|
|
Loading…
Reference in New Issue