Пример #1
0
 @Override
 public MethodAction createActionIfPossible(String actionName) {
   // will resolve if both a class and method name can be parsed, and a valid class with that
   // method name can be loaded
   String methodName = MethodAction.methodNameForAction(actionName);
   String className = MethodAction.classNameForAction(actionName);
   if (StringUtils.isEmpty(methodName) || StringUtils.isEmpty(className)) {
     return null;
   }
   try {
     Class<?> clazz = Class.forName(className); // TODO - Restricted in GAE - why is this better?
     // ClassLoaderUtil.loadClass(className);
     Method method = ReflectUtil.findMethod(clazz, methodName);
     if (method == null) {
       return null;
     }
     MethodAction methodAction = new MethodAction(clazz, method, findInterceptors(method));
     // force instantiation of controller - this allows controllers to be injected into eachother
     // and also flushes out instantiation issues at startup
     Object controller = createController(methodAction);
     controllerInstances.put(methodAction.type(), controller);
     return methodAction;
   } catch (BaseException e) {
     throw e;
   } catch (Exception e) {
     return null;
   }
 }
  protected ActionRequest createActionRequest(String actionPath) {
    HttpServletRequest servletRequest = mock(HttpServletRequest.class);
    HttpServletResponse servletResponse = mock(HttpServletResponse.class);
    HttpSession httpSession = mock(HttpSession.class);
    ServletContext servletContext = mock(ServletContext.class);

    when(servletRequest.getSession()).thenReturn(httpSession);
    when(httpSession.getServletContext()).thenReturn(servletContext);

    MadvocController madvocController = new MadvocController();

    Object action = new Object();
    ActionInfo actionInfo =
        new ActionInfo(
            Action.class,
            ReflectUtil.findMethod(Action.class, "view"),
            null,
            null,
            new ActionDef(actionPath, "GET"),
            null,
            false,
            null,
            null);

    return new ActionRequest(
        madvocController,
        actionInfo.getActionPath(),
        actionInfo,
        action,
        servletRequest,
        servletResponse);
  }