use of org.webpieces.router.api.actions.Redirect in project webpieces by deanhiller.
the class MetaLoader method preconditionCheck.
private void preconditionCheck(RouteMeta meta, Method controllerMethod) {
if (meta.getRoute().isPostOnly()) {
Class<?> clazz = controllerMethod.getReturnType();
if (CompletableFuture.class.isAssignableFrom(clazz)) {
Type genericReturnType = controllerMethod.getGenericReturnType();
ParameterizedType t = (ParameterizedType) genericReturnType;
Type type2 = t.getActualTypeArguments()[0];
if (!(type2 instanceof Class))
throw new IllegalArgumentException("Since this route=" + meta + " is for POST, the method MUST return a type 'Redirect' or 'CompletableFuture<Redirect>' for this method=" + controllerMethod);
@SuppressWarnings("rawtypes") Class<?> type = (Class) type2;
if (!Redirect.class.isAssignableFrom(type))
throw new IllegalArgumentException("Since this route=" + meta + " is for POST, the method MUST return a type 'Redirect' or 'CompletableFuture<Redirect>' not 'CompletableFuture<" + type.getSimpleName() + ">'for this method=" + controllerMethod);
} else if (!Redirect.class.isAssignableFrom(clazz))
throw new IllegalArgumentException("Since this route=" + meta + " is for POST, the method MUST return a type 'Redirect' or 'CompletableFuture<Redirect>' not '" + clazz.getSimpleName() + "' for this method=" + controllerMethod);
} else {
Class<?> clazz = controllerMethod.getReturnType();
if (CompletableFuture.class.isAssignableFrom(clazz)) {
Type genericReturnType = controllerMethod.getGenericReturnType();
ParameterizedType t = (ParameterizedType) genericReturnType;
Type type2 = t.getActualTypeArguments()[0];
if (!(type2 instanceof Class))
throw new IllegalArgumentException("This route=" + meta + " has a method that MUST return a type 'Action' or 'CompletableFuture<Action>' for this method(and did not)=" + controllerMethod);
@SuppressWarnings("rawtypes") Class<?> type = (Class) type2;
if (!Action.class.isAssignableFrom(type))
throw new IllegalArgumentException("This route=" + meta + " has a method that MUST return a type 'Action' or 'CompletableFuture<Action>' not 'CompletableFuture<" + type.getSimpleName() + ">'for this method=" + controllerMethod);
} else if (!Action.class.isAssignableFrom(clazz))
throw new IllegalArgumentException("This route=" + meta + " has a method that MUST return a type 'Action' or 'CompletableFuture<Action>' not '" + clazz.getSimpleName() + "' for this method=" + controllerMethod);
}
}
Aggregations