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
- 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="/">
- 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>
- 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="/">
- 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>
- 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="/">
- 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>
- 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="/">
- 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"
/> |
|
3 | <action path="/Logon" /> |
<action name="Logon"/> |
4 |
|
|
Examples:
<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>
<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>
Struts 1 | Struts 2 | |
1 | <forward/> |
<result/> |
2 | <forward name="RedirectView"/> |
<result name="RedirectView"/> |
3 |
|
|
4 | <forward redirect="true"/> |
|
Examples:
<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>
<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 |
|
|
Examples:
<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>
<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>
Struts 1 | Struts 2 | |
1 | <message-resources/> |
<constant name="struts.custom.i18n.resources" value=""/> |
Examples:
<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>
<constant name="struts.custom.i18n.resources" value="com.ibm.commerce.ras.properties.ecServerMessages” />
Redirect Forward
https://hostname:port/webapp/wcs/stores/servlet/ReLogonFormView
with
parameters.Struts 1 | Struts 2 | |
1 |
|
|
2 |
|
|
Store Forward
<result name="AjaxCategorySubscriptionDisplay/11001" type="wcsstore">
<param name="location">/Snippets/Catalog/CategoryDisplay/CategorySubscriptionDisplay.jsp</param>
</result>
AuroraB2BStorefrontAssetStore/Snippets/Catalog/CategoryDisplay/CategorySubscriptionDisplay.jsp
1 |
|
|
2 |
|
|
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 |
|
|
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 |
|
|
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
<context-param>
<param-name>component-plugin-file</param-name>
<param-value>ComponentPlugins.xml</param-value>
</context-param>
<context-param>
<param-name>component-plugin-file</param-name>
<param-value>ComponentPlugins.xml, customPlugins.xml</param-value>
</context-param>