// 拦截Action处理的拦截方法
 public String intercept(ActionInvocation invocation) throws Exception {
   // 取得请求相关的ActionContext实例
   ActionContext ctx = invocation.getInvocationContext();
   Map session = ctx.getSession();
   // 取出名为user的Session属性
   String user = (String) session.get("user");
   // 如果没有登录,或者登录所用的用户名不是scott,都返回重新登录
   if (user != null && user.equals("crazyit.org")) {
     return invocation.invoke();
   }
   // 没有登录,将服务器提示设置成一个HttpServletRequest属性
   ctx.put("tip", "您还没有登录,请输入crazyit.org,leegang登录系统");
   // 直接返回login的逻辑视图
   return Action.LOGIN;
 }
Example #2
0
  /**
   * Allows the Interceptor to do some processing on the request before and/or after the rest of the
   * processing of the request by the DefaultActionInvocation or to short-circuit the processing and
   * just return a String return code.
   *
   * @param invocation
   * @return
   * @throws Exception
   */
  public String intercept(ActionInvocation invocation) throws Exception {
    executed = true;
    Assert.assertNotSame(DEFAULT_FOO_VALUE, foo);
    Assert.assertEquals(expectedFoo, foo);

    return invocation.invoke();
  }
  // Convenience functions for sending various upnp service requests
  public static ActionInvocation send(
      final Device dev, String instanceID, String service, String action, String... args) {
    Service svc = dev.findService(ServiceId.valueOf("urn:upnp-org:serviceId:" + service));
    final String uuid = getUUID(dev);
    if (svc != null) {
      Action x = svc.getAction(action);
      String name = getFriendlyName(dev);
      boolean log = !action.equals("GetPositionInfo");
      if (x != null) {
        ActionInvocation a = new ActionInvocation(x);
        a.setInput("InstanceID", instanceID);
        for (int i = 0; i < args.length; i += 2) {
          a.setInput(args[i], args[i + 1]);
        }
        if (log) {
          LOGGER.debug("Sending upnp {}.{} {} to {}[{}]", service, action, args, name, instanceID);
        }
        new ActionCallback(a, upnpService.getControlPoint()) {
          @Override
          public void success(ActionInvocation invocation) {
            rendererMap.mark(uuid, ACTIVE, true);
          }

          @Override
          public void failure(
              ActionInvocation invocation, UpnpResponse operation, String defaultMsg) {
            LOGGER.debug("Action failed: {}", defaultMsg);
            rendererMap.mark(uuid, ACTIVE, false);
          }
        }.run();

        if (log) {
          for (ActionArgumentValue arg : a.getOutput()) {
            LOGGER.debug(
                "Received from {}[{}]: {}={}",
                name,
                instanceID,
                arg.getArgument().getName(),
                arg.toString());
          }
        }
        return a;
      }
    }
    return null;
  }
  public String intercept(ActionInvocation invocation) throws Exception {

    //		ActionContext ctx = ActionContext.getContext();
    //		int role = Integer.parseInt( ctx.getSession()
    //			.get("role").toString());

    return invocation.invoke();
  }
  public String intercept(ActionInvocation actionInvocation) throws Exception {
    ServletContext context = ServletActionContext.getServletContext();
    ActionContext act = actionInvocation.getInvocationContext();

    Map<String, Object> application = act.getApplication();

    String gingkgoHome = System.getProperty("gingkgo.home");
    if (null == gingkgoHome) System.setProperty("gingkgo.home", context.getRealPath(""));

    // 设置系统模块
    if (null == application.get(EbizCommon.EBIZ_APP_MODULES)) {
      List<Module> modules = moduleService.roGetModuleList(true);
      Set<String> ms = new HashSet<String>(0);
      for (Module module : modules) {
        ms.add(module.getModuleName());
      }
      application.put(EbizCommon.EBIZ_APP_MODULES, ms);
    }

    // 设置产品组成
    if (null == application.get(EbizCommon.EBIZ_APP_PACKAGE_ITEM)) {
      List<ProductItem> items = productService.getProductItems(ProductType.Package);
      application.put(EbizCommon.EBIZ_APP_PACKAGE_ITEM, items);
    }

    // 主菜单
    if (null == application.get(EbizCommon.EBIZ_APP_MAIN_MENU)) {
      List<MenuItem> items = new ArrayList<MenuItem>();
      items.add(new MenuItem("Desktop", "桌面", "", "ROLE_USER"));
      items.add(new MenuItem("Products", "产品资源", "", "ROLE_PRODUCT"));
      items.add(new MenuItem("Order", "订单管理", "", "ROLE_SALES"));
      items.add(new MenuItem("Operate", "计调操作", "", "ROLE_OPERATOR"));
      items.add(new MenuItem("Express", "配送管理", "", "ROLE_TRANSPORT"));
      items.add(new MenuItem("CRM", "客户管理", "", "ROLE_AGENT_MANAGER"));
      items.add(new MenuItem("Finance", "财务结算", "", "ROLE_FINANCE"));
      items.add(new MenuItem("Stat", "统计分析", "", "ROLE_SUPERUSER"));
      items.add(new MenuItem("System", "系统设置", "", "ROLE_SUPERUSER"));
      items.add(new MenuItem("Config", "设置", "", "ROLE_SUPERUSER"));
      items.add(new MenuItem("Company", "公司设置", "", "ROLE_SUPERUSER"));
      for (MenuItem menuItem : items) {
        List<Shortcut> cuts = shortcutManager.getShortcutByModule(menuItem.getItemName());
        for (Shortcut shortcut : cuts) {
          menuItem
              .getChild()
              .add(
                  new MenuItem(
                      shortcut.getModuleName(),
                      shortcut.getDisplayName(),
                      shortcut.getRelativePath(),
                      shortcut.getRoles()));
        }
      }
      application.put(EbizCommon.EBIZ_APP_MAIN_MENU, items);
    }

    // 设置产品组成
    if (null == application.get(EbizCommon.EBIZ_SYS_CONFIG)) {
      List<SysConfig> items = configService.getAllConfig();
      for (SysConfig config : items) {
        application.put(config.getName(), config.getValue());
      }
      application.put(EbizCommon.EBIZ_SYS_CONFIG, "OK");
    }

    // XML设置参数
    if (null == application.get(EbizCommon.EBIZ_RES_CONFIG)) {
      try {
        application.put(
            EbizCommon.EBIZ_RES_CONFIG, XMLUtility.getInstance(context.getRealPath(XML_PATH)));
      } catch (ParserConfigurationException pce) {
        logger.error("", pce);
      } catch (IOException ioe) {
        logger.error("", ioe);
      } catch (SAXException saxe) {
        logger.error("", saxe);
      } catch (Exception e) {
        logger.error("", e);
      }
    }

    ActionContext.getContext().getValueStack().push(this);

    return actionInvocation.invoke();
  }