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 IBM Websphere Commerce Version 7 Feature Pack 6 web applications to Struts 2

Contents

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.ECActionStrutsServlet</servlet-class>
            ...
    </servlet>
    Add servlet 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>
    
    Add listener context
    <listener>
    	<listener-class>com.ibm.commerce.struts.v2.StrutsConfigFilesServletContextListener</listener-class>
    </listener>
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
<action parameter="com.ibm.commerce.security.commands.LogonCmd"
            		path="/Logon" type="com.ibm.commerce.struts.BaseAction">
            <set-property property="csrfProtected" value="0:0"/>
            <set-property property="https" value="0:1"/>
            <set-property property="authenticate" value="0:0"/>
</action>
Struts2
<action class="com.ibm.commerce.struts.v2.BaseAction" name="Logon">
            <param name="authenticate">0:0</param>
            <param name="csrfProtected">0:0</param>
            <param name="https">0:1</param>
            <param name="parameter">com.ibm.commerce.security.commands.LogonCmd</param>
</action>
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
        <forward className="com.ibm.commerce.struts.ECActionForward"
            name="LogoffView" path="/Logoff.jsp">
            <set-property property="properties" value="storeDir=no"/>
            <set-property property="resourceClassName" value="com.ibm.commerce.command.HttpForwardViewCommandImpl"/>
        </forward>
Struts 2
        <result name="LogoffView">
                <param name="location">/Logoff.jsp</param>
                <param name="properties">storeDir=no</param>
                <param name="resourceClassName">com.ibm.commerce.command.HttpForwardViewCommandImpl</param>
        </result>

GlobeForward

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

Examples:

Struts 1
<global-forwards>
       <forward className="com.ibm.commerce.struts.ECActionForward"
            name="CookieErrorView" path="/GenericSystemError.jsp">
            <set-property property="properties" value="storeDir=no"/>
            <set-property property="resourceClassName" value="com.ibm.commerce.command.HttpForwardViewCommandImpl"/>
        </forward>
</global-forwards>
Struts 2
<global-results>
        <result name="CookieErrorView">
                <param name="location">/GenericSystemError.jsp</param>
                <param name="properties">storeDir=no</param>
                <param name="resourceClassName">com.ibm.commerce.command.HttpForwardViewCommandImpl</param>
            </result>
</global-results>
Message Resource
Struts 1 Struts 2
1 <message-resources/> <constant name="struts.custom.i18n.resources" value=""/>

Examples:

Struts 1
<message-resources
        className="com.ibm.commerce.struts.messages.WCMessageResourcesConfig"
        factory="com.ibm.commerce.struts.messages.WCPropertyMessageResourcesFactory"
        key="org.apache.struts.action.MESSAGE" null="true" parameter="com.ibm.strutsstore.resources.ApplicationResources">
        <set-property property="additionalProperties" value="com.ibm.commerce.ras.properties.ecServerMessages"/>
</message-resources>
Struts 2
<constant name="struts.custom.i18n.resources" value="com.ibm.commerce.ras.properties.ecServerMessages” />

Redirect Forward

A new result type “wcsredirect” is defined in Struts2 for HCL 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
https://hostname:port/webapp/wcs/stores/servlet/ReLogonFormView
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 HCL Commerce which will add store directory before the location. For example, for the result below the final URL location is
<result name="AjaxCategorySubscriptionDisplay/11001" type="wcsstore">
    <param name="location">/Snippets/Catalog/CategoryDisplay/CategorySubscriptionDisplay.jsp</param>
</result>
The final URL location is
AuroraB2BStorefrontAssetStore/Snippets/Catalog/CategoryDisplay/CategorySubscriptionDisplay.jsp
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:
<context-param>
		<param-name>component-plugin-file</param-name>
        		<param-value>ComponentPlugins.xml</param-value>
	</context-param>
After:
<context-param>
		<param-name>component-plugin-file</param-name>
        		<param-value>ComponentPlugins.xml, customPlugins.xml</param-value>
	</context-param>