示例#1
0
 @Override
 public Object resolve(
     MethodAction action,
     RouteType routeType,
     HttpServletRequest req,
     HttpServletResponse resp,
     Map<String, String> pathVars)
     throws ActionException {
   Object controller = getOrCreateController(action);
   Map<Annotation, ActionInterceptor<Annotation>> interceptors = action.interceptors();
   Object result = null;
   Exception exception = null;
   try {
     result = beforeInterceptors(interceptors, req, resp);
     List<?> arguments = bindArguments(action, req, resp, pathVars);
     result = result != null ? result : action.invoke(controller, arguments);
     result = afterInterceptors(result, interceptors, req, resp);
   } catch (InvocationTargetException e) {
     // we need to unwrap InvocationTargetExceptions to get at the real exception
     exception = Cast.as(e.getTargetException(), Exception.class);
     if (exception == null) {
       throw new BaseException(e);
     }
   } catch (Exception e) {
     exception = e;
   }
   if (exception != null) {
     result = exceptionInterceptors(interceptors, req, resp, exception);
     if (result == null) {
       throw new ActionException(exception, "Failed in %s: %s", action, exception.getMessage());
     }
   }
   Logger.debug("%s -> %s resolved", req.getRequestURI(), action);
   return result;
 }
示例#2
0
 /**
  * We treat all values as collections. Nulls are treated as an empty collection, Non-collections
  * are treated as a collection of length 1
  *
  * @param value
  * @return
  */
 @SuppressWarnings("unchecked")
 private Collection<Object> getCollectionValues(Object value) {
   if (value == null) {
     return Collections.emptyList();
   }
   Collection<Object> collection = Cast.as(value, Collection.class);
   return collection == null ? Collections.singleton(value) : collection;
 }
示例#3
0
 @Override
 public <T> T getRawRequest(Class<T> type) {
   return Cast.as(getRawRequest(), type);
 }