コード例 #1
0
ファイル: ActionConfigMatcher.java プロジェクト: eeyoo/struts
  /**
   * Clones the ActionConfig and its children, replacing various properties with the values of the
   * wildcard-matched strings.
   *
   * @param path The requested path
   * @param orig The original ActionConfig
   * @param vars A Map of wildcard-matched strings
   * @return A cloned ActionConfig with appropriate properties replaced with wildcard-matched values
   */
  @Override
  public ActionConfig convert(String path, ActionConfig orig, Map<String, String> vars) {

    String methodName = convertParam(orig.getMethodName(), vars);

    if (StringUtils.isEmpty(methodName)) {
      methodName = ActionConfig.DEFAULT_METHOD;
    }

    if (!orig.isAllowedMethod(methodName)) {
      return null;
    }

    String className = convertParam(orig.getClassName(), vars);
    String pkgName = convertParam(orig.getPackageName(), vars);

    Map<String, String> params = replaceParameters(orig.getParams(), vars);

    Map<String, ResultConfig> results = new LinkedHashMap<>();
    for (String name : orig.getResults().keySet()) {
      ResultConfig result = orig.getResults().get(name);
      name = convertParam(name, vars);
      ResultConfig r =
          new ResultConfig.Builder(name, convertParam(result.getClassName(), vars))
              .addParams(replaceParameters(result.getParams(), vars))
              .build();
      results.put(name, r);
    }

    List<ExceptionMappingConfig> exs = new ArrayList<ExceptionMappingConfig>();
    for (ExceptionMappingConfig ex : orig.getExceptionMappings()) {
      String name = convertParam(ex.getName(), vars);
      String exClassName = convertParam(ex.getExceptionClassName(), vars);
      String exResult = convertParam(ex.getResult(), vars);
      Map<String, String> exParams = replaceParameters(ex.getParams(), vars);
      ExceptionMappingConfig e =
          new ExceptionMappingConfig.Builder(name, exClassName, exResult)
              .addParams(exParams)
              .build();
      exs.add(e);
    }

    return new ActionConfig.Builder(pkgName, orig.getName(), className)
        .methodName(methodName)
        .addParams(params)
        .addResultConfigs(results)
        .addInterceptors(orig.getInterceptors())
        .addExceptionMappings(exs)
        .location(orig.getLocation())
        .build();
  }
コード例 #2
0
  /**
   * Tests creating action flow override configuration.
   *
   * @throws Exception when something goes wrong.
   */
  @Test
  public void testCorrectFlowOverride() throws Exception {
    ActionProxy proxy = getActionProxy("/correctFlowOverride/correctFlowOverride");
    Assert.assertNotNull(proxy);
    proxy.getInvocation().getInvocationContext().setSession(new HashMap<String, Object>());
    proxy.execute();

    ActionConfig overriddenViewConf =
        configuration
            .getRuntimeConfiguration()
            .getActionConfig("/correctFlowOverride", "savePhone-2ViewOverride");

    Assert.assertNotNull(overriddenViewConf);
    Assert.assertEquals("phone", overriddenViewConf.getMethodName());
    Assert.assertEquals(
        "anotherPhone",
        overriddenViewConf
            .getResults()
            .get(Action.SUCCESS)
            .getParams()
            .get(ServletDispatcherResult.DEFAULT_PARAM));

    ActionConfig actionConfig =
        configuration
            .getRuntimeConfiguration()
            .getActionConfig("/correctFlowOverride", "saveName-1ViewOverride");

    Assert.assertNotNull(actionConfig);
    Assert.assertEquals("executeOverride", actionConfig.getMethodName());
    Assert.assertEquals(
        "name",
        actionConfig
            .getResults()
            .get(Action.SUCCESS)
            .getParams()
            .get(ServletDispatcherResult.DEFAULT_PARAM));
  }