@SuppressWarnings("unchecked")
@VisibleForTesting
protected Key<? extends Function<HttpResponse, ?>> getParserOrThrowException(Invocation invocation) {
Invokable<?, ?> invoked = invocation.getInvokable();
Set<String> acceptHeaders = getAcceptHeaders.apply(invocation);
ResponseParser annotation = invoked.getAnnotation(ResponseParser.class);
Class<?> rawReturnType = invoked.getReturnType().getRawType();
if (annotation == null) {
if (rawReturnType.equals(void.class) || invoked.getReturnType().equals(futureVoidToken)) {
return Key.get(ReleasePayloadAndReturn.class);
} else if (rawReturnType.equals(boolean.class) || rawReturnType.equals(Boolean.class)
|| invoked.getReturnType().equals(futureBooleanToken)) {
return Key.get(ReturnTrueIf2xx.class);
} else if (rawReturnType.equals(InputStream.class)
|| invoked.getReturnType().equals(futureInputStreamToken)) {
return Key.get(ReturnInputStream.class);
} else if (rawReturnType.equals(HttpResponse.class)
|| invoked.getReturnType().equals(futureHttpResponseToken)) {
return Key.get(Class.class.cast(IdentityFunction.class));
} else if (acceptHeaders.contains(APPLICATION_JSON)) {
return getJsonParserKeyForMethod(invoked);
} else if (acceptHeaders.contains(APPLICATION_XML) || invoked.isAnnotationPresent(JAXBResponseParser.class)) {
return getJAXBParserKeyForMethod(invoked);
} else if (rawReturnType.equals(String.class) || invoked.getReturnType().equals(futureStringToken)) {
return Key.get(ReturnStringIf2xx.class);
} else if (rawReturnType.equals(URI.class) || invoked.getReturnType().equals(futureURIToken)) {
return Key.get(ParseURIFromListOrLocationHeaderIf20x.class);
} else {
throw new IllegalStateException("You must specify a ResponseParser annotation on: " + invoked.toString());
}
}
return Key.get(annotation.value());
}