Uploaded image for project: 'Struts 1'
  1. Struts 1
  2. STR-3132

Improve wildcards resolution in action-mappings

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 1.3.8
    • Fix Version/s: Future
    • Component/s: Core
    • Labels:
      None
    • Environment:
      Struts 1.3.8
    • Flags:
      Patch

      Description

      Hello

      In my struts-config.xml, i define generic mappings using wildcards to normalize actions suite.

      The is no posibility actualy to define 2 action mappings with the same path structure but not the same configuration.

      My exemple is :

      <action path="///prepare"
      name="

      {1}Form" scope="session"
      validate="false"
      command="prepare-{2}-{1}

      " catalog="cctp-

      {1}"
      forward="/{1}

      /

      {2}/prepare/rooting.do">
      </action>

      <action path="///prepare"
      name="{2}

      Form" scope="session"
      validate="false"
      command="prepare-

      {2}-{1}" catalog="cctp-{1}"
      forward="/{1}/{2}

      /prepare/rooting.do">
      </action>

      Struts always retrieve the second one, even if the mapping is not correct (wrong form name, wrong command ...)
      The only way i found to enable this behavior, is to setup the following property in action servlet (web.xml)

      <init-param>
      <param-name>configFactory</param-name>
      <param-value>org.apache.struts.config.impl.CustomMatcherModuleConfigFactory</param-value>
      </init-param>

      And Then redfine , ModuleConfigFactory, ModuleConfigImpl and ActionConfigMatcher.
      Just to redefine the method "match" in ActionConfigMatcher as following:

      public ActionConfig match(String path) {
      ActionConfig config = null;
      if (compiledPaths.size() > 0) {
      if (log.isDebugEnabled())
      log.debug("Attempting to match '" + path + "' to a wildcard pattern");
      if (path.length() > 0 && path.charAt(0) == '/')
      path = path.substring(1);
      HashMap vars = new HashMap();
      Iterator i = compiledPaths.iterator();
      do {
      if (!i.hasNext())
      break;
      Mapping m = (Mapping) i.next();
      if (wildcard.match(vars, path, m.getPattern())) {
      if (log.isDebugEnabled())
      log.debug("Path matches pattern '" + m.getActionConfig().getPath() + "'");
      ActionConfig lTempconfig = convertActionConfig(path, m.getActionConfig(), vars);

      // Test if ActionConfig is correct before returning it
      if(StringUtils.isNotBlank(lTempconfig.getName()) && lTempconfig.getModuleConfig().findFormBeanConfig(lTempconfig.getName()) == null)

      { // The form doesn't exists log.debug("FormBean not defined '" + lTempconfig.getName() + "' config ignored"); }

      else

      { config =lTempconfig; }

      }
      } while (true);
      }
      return config;
      }

      In that exemple i just test formBean config but it is important to chek all actionConfigs such as class, command ...

      thanks
      LAurent MORIN

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              laurent.morin Laurent MORIN
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: