How to customize the error behavior when accessing WCM resources
Applies to
HCL Digital Experience v9.5 or higher
Introduction
This article describes the procedure to customize the default HTTP-404 and HTTP-403 error codes that might been noticed when using the WCM servlet. Depending on the scenario, you will receive a different error message. This article applies to the following scenarios:
-
Non-existent WCM URLs.
For example:
http://hostname/wps/wcm/non-existent.Opening this URL will result in a a default 404 error message such as:
Error 404: java.io.FileNotFoundException: CWSRV0190E: File not found: /non-existent -
A WCM URL containing a non-existent JSP file.
For example:
http://hostname/wps/wcm/webinterface/login/login2.jsp.Opening this URL will result in a default 404 error page specific for JSPs such as:
-
The URL is valid, but the user does not have access to the item.
For example:
http://hostname/wps/wcm/myconnect/mylib/mysitearea/mycontent.Opening this URL will result in a default 403 error such as:
Message: Error 403: CWSRV0295E: Error reported: 403
Instructions
-
Open a command prompt or terminal session to access the HCL DX binaries.
-
Create a temporary directory and ensure the current user has read and write permissions.
Note
The user can use an existing temporary directory (for example,
/tmp) if they have the required permissions. Throughout this example, the/tmpand/tmp/wcm_expandeddirectories are used. -
Navigate to the
<wp_profile_root>/bindirectory. -
Use the
wsadmincommand to export thewcm.earfile. For example:wsadmin.sh(bat) -user <admin_user_id> -password <admin_password> -c '$AdminApp export wcm /tmp/wcm.ear' -
Use the
EARExpander.(bat|sh)utility to expand thewcm.earfile into the temporary directory../EARExpander.sh -ear /tmp/wcm.ear -operationDir /tmp/wcm_expanded/ -operation expand -
Navigate to the expanded directory and locate the
web.xmlfile under/tmp/wcm_expanded/ilwwcm.war/WEB-INF/. -
Backup the
web.xmlfile. -
Open the
web.xmlfile in a text editor and locate the following entry:<mime-mapping id="MimeMapping_1088994409133"> <extension>zip</extension> <mime-type>application/x-gzip</mime-type> </mime-mapping> -
Add the following entries right below
</mime-mapping>then save theweb.xmlfile. For example:<mime-mapping id="MimeMapping_1088994409133"> <extension>zip</extension> <mime-type>application/x-gzip</mime-type> </mime-mapping> <error-page> <error-code>404</error-code> <location>/html/custom_errors/error404.html</location> </error-page> <error-page> <error-code>403</error-code> <location>/html/custom_errors/error403.html</location> </error-page> -
In the
/tmp/wcm_expanded/ilwwcm.war/directory, create the nested directory structure:html/custom_errors/. -
Create a new file named
error404.htmlin thehtml/custom_errors/directory with the following code:<html> <p>This is a custom 404 error page!</p> <br>Sorry, I could not find this item for you! </html> -
Create a new file named
error403.htmlin the same directory with the following code:<html> <p>This is a custom 403 error page!</p> <br>You have no access to this item! </html> -
Rename the copy of the
wcm.earfile in the/tmpdirectory that was previously exported towcm.bak. -
Use the
EARExpander.(bat|sh)utility to collapse the changes made back into a newwcm.earfile:./EARExpander.sh -ear /tmp/wcm.ear -operationDir /tmp/wcm_expanded/ -operation collapse -
Use the following
wsadmincommand to update thewcm.earfile:./wsadmin.sh -user <admin_user_id> -password <admin_password> -c '$AdminApp update wcm app {-operation update -contents /tmp/wcm.ear}' -
If HCL DX runs on a cluster, open the IBM Integrated Solutions Console (WAS admin console) and perform a full resynchronization with all nodes.