Tutorials > Program model > Web services > Create a new WebSphere Commerce BOD service module
Implement the client library
The client library's primary purpose is to simplify and eliminate code on the client. The client library is essentially a Java layer to help Java applications integrate with the service architecture, with no additional code generation required. The client library already has support for session and authentication and provides Java-based clients a standardized mechanism to create the logical SDO objects to represent service requests.
Each service module should provide a client library project to access the services provided by the module. The client project contains the following:
- Interfaces of the service provided for each noun
- A constant file that is sharable between client and server
- A client package that contains
- The abstract client Java class that contains common methods and methods required
- A programming friendly Web enabled Java class that extends from the abstract class to implement the Java friendly and Web enabled methods
- Noun specific exceptions to represent client errors and server errors
The following diagram shows the client library in the context of the overall customization process:
This lesson of the tutorial shows you how to add convenience methods that hide the complexity of creating the different GetBODTutorialStore, ChangeBODTutorialStore and ProcessBODTutorialStore requests.
Procedure
- Open the com.mycompany.commerce.bodtutorialstore.facade.BODTutorialStoreFacadeConstants class in the BODTutorialStore-Client project.
- Add the constants that represent actions supported by the store, supported XPath expressions and access profiles.
// ========================================== // The following is a predefined set of access profiles provided by the component. // ========================================== /** * This constants represents an access profile that returns detail * information about the noun. This includes most of the * information associated with the specified noun. */ public static final String ACCESS_PROFILE_DETAIL_INFORMATION = "MyCompany_Details"; // ===================================================== // The following is a list of actions that can be used for the process request. // ===================================================== /** * The Open Store process action. */ public static String PROCESS_ACTION_OPEN = "Open"; /** * The Close Store process action. */ public static String PROCESS_ACTION_CLOSE = "Close"; // ============================================================ // The following is the change actions and XPath keys. // ============================================================ /** * The Change action to update a store. */ public static String CHANGE_ACTION_UPDATE = "Change"; /** * The XPath key to update the store state. */ public static String XPATH_STORE = "/TutorialStore[{0}]"; /** * The XPath key to update the store description. */ public static String XPATH_DESCRIPTION = "/TutorialStore[{0}]/StoreDescription"; // =================================================================== // The following is a list of Get expression XPath keys. // ============================================================ /** * The XPath key for finding all stores. */ public static String ALLEXPRESSION = "/TutorialStore"; /** * The XPath key for finding a store by ID. */ public static String IDEXPRESSION = "/TutorialStore[StoreIdentifier[(UniqueID={0})]]"; /** * The XPath key for finding a store by name. */ public static String NAMEEXPRESSION = "/TutorialStore[StoreIdentifier[ExternalIdentifier[(NameIdentifier=\"{0}\")]]]";
- Import the provided BODTutorialStoreFacadeClient class containing the Java friendly client methods:
- In the Enterprise Explorer view, right-click the BODTutorialStore-Client/src/com.mycompany.commerce.bodtutorialstore.facade.client package.
- Select Import > FileSystem. Click Next.
- Browse to the temporary location where you unzipped TutorialStore.zip.
- Browse to the BODTutorialStore-Client\src\com.mycompany.commerce.bodtutorialstore.facade.client folder.
- Select BODTutorialStoreFacadeClient.java Click Finish.
- Click Yes to All to overwrite the existing file.
- Organize the imports for the BODTutorialStore-Client project:
- Open the Java perspective in WebSphere Commerce Developer.
- Right-click the BODTutorialStore-Client\src folder and select Source.
- Select Organize Imports.