Struts 2 configuration file changes

This reference describes configuration files changes between Struts 1.x and Struts 2.

Most migration changes are performed by the strutsmigration.jar tool. For detailed migration steps, see Migrating customized web applications to Struts 2


Contents

  1. Configuration File Migration

    1. Stores.WAR

    2. CommerceAccelerator.WAR

    3. OrganizationAdministration.WAR

    4. SiteAdministration.WAR

  2. Configuration of Struts1.x versus Struts2

    1. Action

    2. Forward

    3. GlobeForward

    4. Message Resource

    5. Redirect Forward

    6. Store Forward

  3. Plugins

  4. UrlRegistry and ViewRegistry Initialization


Configuration File Migration

Stores.WAR

  1. Struts Configuration files

    Changes Before After
    OOTB File Name

    struts-config.xml

    struts-config-xxx.xml

    struts-stores.xml

    struts-wcs-stores.xml

    struts-wcs-stores-xxx.xml

    File Location \WEB-INF WEB-INF\classes
    Customization files

    struts-config-ext.xml

    struts-wcs-stores-custom.xml

    <package extends="wcs-stores" name=" stores-custom " namespace="/">

  2. Web.xml

    Changes Before After
    Servlet Update

      <servlet>
              ...
              <servlet-name>Stores Request Servlet</servlet-name>
              <servlet-class>com.ibm.commerce.struts.ECActionServlet</servlet-class>
              ...
          </servlet>

      <servlet>
               ...       
              <servlet-name>Stores Request Servlet</servlet-name>
              <servlet-class>com.ibm.commerce.struts.v2.ECActionServlet</servlet-class>
              …
          </servlet>

    Add sruts2 Filter to the end of filter definition

      <filter>
              <filter-name>struts2</filter-name>
              <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
      		<init-param>
                  <param-name>config</param-name>
                  <param-value>struts-default.xml,struts-plugin.xml,struts-stores.xml</param-value>
              </init-param>
          </filter>
          <filter-mapping>
              <filter-name>struts2</filter-name>
              <url-pattern>/stores/servlet/*</url-pattern>
              <servlet-name>Stores Request Servlet</servlet-name>
          </filter-mapping>

    Add servelet context

      <context-param>
          <param-name>component-plugin-file</param-name>
          <param-value>ComponentPlugins.xml</param-value>
      </context-param>
      <context-param>
          <param-name>initServlet</param-name>
          <param-value>true</param-value>
      </context-param>
      <context-param>
      <param-name>isStruts2</param-name>
          <param-value>true</param-value>
      </context-param>

CommerceAccelerator.WAR

  1. Struts Configuration files

    Changes Before After
    OOTB File Name

    struts-config.xml

    struts-config-xxx.xml

    struts-accelerator.xml

    struts-wcs-accelerator.xml

    struts-wcs-accelerator-xxx.xml

    File Location \WEB-INF WEB-INF\classes
    Customization files

    struts-config-ext.xml

    struts-wcs-accelerator-custom.xml

    <package extends="wcs-accelerator" name="accelerator-custom " namespace="/">

  2. Web.xml

    Changes Before After
    Servlet Update

      <servlet>
              ...
              <servlet-name> Commerce Accelerator Request Servlet</servlet-name>
              <servlet-class>com.ibm.commerce.struts.ECActionServlet</servlet-class>
              ...
          </servlet>

      <servlet>
               ...       
              <servlet-name>Commerce Accelerator Request Servlet</servlet-name>
              <servlet-class>com.ibm.commerce.struts.v2.ECActionServlet</servlet-class>
              …
          </servlet>

    Add sruts2 Filter to the end of filter definition

      <filter>
              <filter-name>struts2</filter-name>
              <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
              <init-param>
                  <param-name>config</param-name>
                  <param-value>struts-default.xml,struts-plugin.xml,struts-accelerator.xml</param-value>
              </init-param>
          </filter>
          <filter-mapping>
              <filter-name>struts2</filter-name>
              <servlet-name>Commerce Accelerator Request Servlet</servlet-name>
          </filter-mapping>

    Add servlet context

      <context-param>
          <param-name>isStruts2</param-name>
          <param-value>true</param-value>
      </context-param>

OrganizationAdministration.WAR

  1. Struts Configuration files

    Changes Before After
    OOTB File Name

    struts-config.xml

    struts-config-xxx.xml

    struts-orgadmin.xml

    struts-wcs-orgadmin.xml

    struts-wcs-orgadmin-xxx.xml

    File Location \WEB-INF WEB-INF\classes
    Customization files

    struts-config-ext.xml

    struts-wcs-orgadmin-custom.xml

    <package extends="wcs-orgadmin" name="orgadmin-custom " namespace="/">

  2. Web.xml

    Changes Before After
    Servlet Update

      <servlet>
              ...
              <servlet-name>Organization Administration Request Servlet</servlet-name>
              <servlet-class>com.ibm.commerce.struts.ECActionServlet</servlet-class>
              ...
          </servlet>

      <servlet>
               ...       
              <servlet-name>Organization Administration Request Servlet</servlet-name>
              <servlet-class>com.ibm.commerce.struts.v2.ECActionServlet</servlet-class>
              …
          </servlet>

    Add sruts2 Filter to the end of filter definition

      <filter>
              <filter-name>struts2</filter-name>
              <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
              <init-param>
                  <param-name>config</param-name>
                  <param-value>struts-default.xml,struts-plugin.xml,struts-orgadmin.xml</param-value>
              </init-param>
          </filter>
          <filter-mapping>
              <filter-name>struts2</filter-name>
              <servlet-name>Organization Administration Request Servlet</servlet-name>
          </filter-mapping>

    Add servlet context

      <context-param>
          <param-name>isStruts2</param-name>
          <param-value>true</param-value>
      </context-param>

SiteAdministration.WAR

  1. Struts Configuration files

    Changes Before After
    OOTB File Name

    struts-config.xml

    struts-config-xxx.xml

    struts-siteadmin.xml

    struts-wcs-adminconsole.xml

    struts-wcs-adminconsole-xxx.xml

    File Location \WEB-INF WEB-INF\classes
    Customization files

    struts-config-ext.xml

    struts-wcs-adminconsole-custom.xml

    <package extends="wcs-adminconsole" name="adminconsole-custom " namespace="/">

  2. Web.xml

    Changes Before After
    Servlet Update

      <servlet>
              ...
              <servlet-name>Site Administration Request Servlet</servlet-name>
              <servlet-class>com.ibm.commerce.struts.ECActionServlet</servlet-class>
              ...
          </servlet>

      <servlet>
               ...       
              <servlet-name>Site Administration Request Servlet</servlet-name>
              <servlet-class>com.ibm.commerce.struts.v2.ECActionServlet</servlet-class>
              …
          </servlet>

    Add sruts2 Filter to the end of filter definition

      <filter>
              <filter-name>struts2</filter-name>
              <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
              <init-param>
                  <param-name>config</param-name>
                  <param-value>struts-default.xml,struts-plugin.xml,struts-siteadmin.xml</param-value>
              </init-param>
          </filter>
          <filter-mapping>
              <filter-name>struts2</filter-name>
              <servlet-name>Site Administration Request Servlet</servlet-name>
          </filter-mapping>

    Add servlet context

      <context-param>
          <param-name>isStruts2</param-name>
          <param-value>true</param-value>
      </context-param>


Configuration of Struts1.x versus Struts2

Action

Struts 1 Struts 2
1 <action type =” com.ibm.commerce.struts.BaseAction”/> <action class="com.ibm.commerce.struts.v2.BaseAction"/>
2 <action parameter="com.ibm.commerce.security.commands.LogonCmd" />

    <action>
    <param name="parameter">com.ibm.commerce.security.commands.LogonCmd</param>
    </action>

3 <action path="/Logon" /> <action name="Logon"/>
4

    <action>
        <set-property property="csrfProtected" value="0:0"/>
    </action>

    <action>
            <param name="csrfProtected">0:0</param>
    </action>

Examples: Struts1

Struts2

Forward

Struts 1 Struts 2
1 <forward/> <result/>
2 <forward name="RedirectView"/> <result name="RedirectView"/>
3 <forward path="/"/>

    <result>
        <param name="location">/</param>
    <result/>

4 <forward redirect="true"/>

    <result>
        <param name="redirect">true</param>
    </result>
    
    Default result type is “dispatcher”

Examples: Struts 1

Struts 2

GlobeForward

Struts 1 Struts 2
1 <global-forwards/> <global-results/>
2

    <global-forwards>
           <forward/>
    </global-forwards>

    <global-results>
            <result/>
    </global-results>

Examples: Struts 1

Struts 2

Message Resource

Struts 1 Struts 2
1 <message-resources/> <constant name="struts.custom.i18n.resources" value=""/>

Examples: Struts 1

Struts 2

Redirect Forward A new result type “wcsredirect” is defined in Struts2 for WebSphere Commerce that will override the default struts2 “redirect” result type. This result type redirects the result to a complete URL location. For example, redirect to

with parameters.

Struts 1 Struts 2
1

    <result-types>
    	<result-type class="com.ibm.commerce.struts.v2.WCSRedirectResult" name="wcsredirect"/>
    </result-types>

2

    <forward className="com.ibm.commerce.struts.ECActionForward"
                name="RedirectView" path="" redirect="true">
                <set-property property="resourceClassName" value="com.ibm.commerce.command.HttpRedirectViewCommandImpl"/>
            </forward>

    <result name="RedirectView" type="wcsredirect">
                    <param name="location">${redirectUrl}</param>
                    <param name="redirect">true</param>
                    <param name="resourceClassName">com.ibm.commerce.command.HttpRedirectViewCommandImpl</param>
                </result>

Store Forward A new result type “wcsstore” is defined in Struts 2 for WebSphere Commerce which will add store directory before the location. For example, for the result below the final URL location is

The final URL location is

1

    <result-types>
                <result-type class="com.ibm.commerce.struts.v2.WCSStoreDispatcherResult" name="wcsstore"/>
            </result-types>

2

    <forward className="com.ibm.commerce.struts.ECActionForward"
                name=" AjaxCategorySubscriptionDisplay/11001" path="/Snippets/Catalog/CategoryDisplay/CategorySubscriptionDisplay.jsp "/>

    <result name="AjaxCategorySubscriptionDisplay/11001" type="wcsstore">
        <param name="location">/Snippets/Catalog/CategoryDisplay/CategorySubscriptionDisplay.jsp</param>
    </result>


Plugins

Since Struts 2 does not support plugins composed in Struts Version 1, the method for initializing plugins has changed. A new file, ComponentPlugins.xml is used for this purpose. Move your plugin definitions from the struts 1 configuration file to ComponentPlugins.xml as indicated below.

Struts1 Struts2
File location Stores\WEB-INF\struts-config-*.xml Stores\WEB-INF\classes\ComponentPlugins.xml
schema

    <?xml version="1.0" encoding="UTF-8"?>
    <struts-config>
    <plug-in className="*">
        <set-property property="*" value="*"/>
    </plug-in>
    </struts-config>

    <?xml version="1.0" encoding="UTF-8"?>
    <ComponentPlugins>
    	<plug-in className="*" />
    </ComponentPlugins>

Plugin support

com.ibm.commerce.struts.ComponentPlugIn

com.ibm.commerce.struts.VerificationCodePlugInImpl

com.ibm.commerce.struts.v2.ComponentPlugIn

com.ibm.commerce.struts.v2.VerificationCodePlugInImpl

Plugin sample

    <plug-in className="com.ibm.commerce.struts.ComponentPlugIn">
      <set-property property="componentId" value="member"/>
      <set-property property="clientFacadeClassName" 
       value="com.ibm.commerce.member.facade.client.MemberFacadeClient"/>
    </plug-in>

    <plug-in className="com.ibm.commerce.struts.v2.ComponentPlugIn" 
    componentId="member" clientFacadeClassName="com.ibm.commerce.member.facade.client.MemberFacadeClient"/>
    	            

The plugins defined in ComponentPlugins.xml will be loaded when the servlet context is initialized. If you would like to have another file (for example customPlugins.xml) contain custom plugins, edit Stores\WEB-INF\web.xml Before:

After:


UrlRegistry and ViewRegistry Initialization

  1. . Register a servlet context listener to InitializationServlet.war InitializationServlet\WebContent\WEB-INF\web.xml.

      <listener>
      	<listener-class>com.ibm.commerce.struts.v2.StrutsConfigFilesServletContextListener</listener-class>
      </listener>

  2. StrutsConfigFilesServletContextListener will load following Struts files in classpath and init:

      "struts-default.xml,struts-plugin.xml,struts.xml,struts-accelerator.xml,struts-orgadmin.xml,struts-siteadmin.xml,struts-stores.xml";

  3. StrutsConfigFilesServletContextListener will register StrutsRegistrySourceImpl to UrlRegistry and ViewRegistry.

  4. After we upgrade to Struts 2, UrlRegistry, StrutsRegistry and ViewRegistry no longer support the refresh method in the WebSphere Commerce Administration Console.