Develop > Business logic layer > Developing the business logic layer using the BOD command framework > Work with WebSphere Commerce service modules


Add a custom user or error message to a BOD service module

Add custom messages to the BOD framework commands involves creating the properties file with a specified naming convention and location. The logging framework is configured to traverse up the package hierarchy and find and load any resource bundles (properties files) with names matching the naming convention.


Procedure

  1. Create a properties file to list the message values, for each locale that you wish to support:

    1. The property file should be located in the com.mycompany.logging.properties package where mycompany is the company name or some other, arbitrary unique identifier. The most important thing is that the package name ends with logging.properties and that this package can be found at or above the calling class in the package hierarchy.

    2. The name of the property files must follow the pattern below: WcMyServiceModuleMessages_locale.properties , where MyServiceModule is the name of the service module and locale is the locale identifier (for example, en_US).

    # translateable messages for the MyServiceModule component
    # Message keys are defined in the class
    # com.mycompany.logging.MyServiceModuleMessageKeys
    MYCO0001E= MYCO0001E: The value "{1}" is invalid for parameter name "{0}"
    MYCO0002I= MYCO0002I: The value {0} is over 9000!
    

  2. Create a message key class which captures the property file keys. This class must define a static instance variable for each of the message keys defined in the property file.

    1. If only server code needs to access the messages, create a new interface class in the MyServiceModule-Server project. The suggested naming convention is MyServiceModuleApplicationMessageKey.java. If both client and server need to access the messages, create the interface in the MyServiceModule-Client project, with a suggested naming convention of MyServiceModuleClientApplicationMessageKey.java.

    2. For each message, create a line similar to the following in the interface class:

      /**
       * MyServiceModule command invalid parameter
       * param 0: The name of the invalid parameter
       * param 1: The value of the invalid parameter
       */
      public final static String MYCOMPANY_MYCOMMAND_INVALID_PARAMETER = "MYCO0001E"; 
      

  3. Log the error...

    Logger logger = LoggingHelper.getLogger(MyClass.class); logger.logp(Level.SEVERE, "MyClass","MyMethod", MyServiceModuleMessageKeys.MYCOMPANY_MYCOMMAND_INVALID_PARAMETER, new Object[] {parameterName, parameterValue} );
    


Related concepts

WebSphere Commerce BOD command framework

Business logic layer design patterns

Access control in the BOD command framework

Service module configuration

Data service layer


+

Search Tips   |   Advanced Search