Tutorials > Program model > Web services > Create a WebSphere Commerce service module (SOI) > Creating the Get TutorialStore service
Implement the client library
In this step, you add convenience methods that hide the complexity of creating the different GetTutorialStore requests.
Procedure
- Open the SOITutorialStore-Client/src/com.mycompany.commerce.soitutorialstore.facade.SOITutorialStoreFacadeConstants class.
- Add the following constants to represent the actions supported by the store, XPath search expressions, and URL parameter names.
/** * The XPath key for the TutorialStore. */ public static String XPATH_STORE = "/TutorialStore"; /** * The XPath key for finding a store by ID. */ public static String IDEXPRESSION = "/TutorialStore/TutorialStoreIdentifier[(UniqueID={0})]"; /** * The store ID. */ public static String STORE_ID = "storeId";
- Save the SOITutorialStoreFacadeConstants class.
- Open the com.mycompany.commerce.soitutorialstore.facade.client.SOITutorialStoreFacadeClient class.
- Add the following client methods that build the appropriate BOD:
/** * This method composes a Get BOD with an expression to find a store by ID * and sends the BOD to the TutorialStore-Server. */ public ShowTutorialStoreDataAreaType findStoreById(String[] storeId, String accessProfile) { final String METHODNAME = "findStoreById"; // Build the expression. String expression = java.text.MessageFormat.format( SOITutorialStoreFacadeConstants.IDEXPRESSION, storeId); SelectionCriteriaHelper selectionCriteriaHelper = new SelectionCriteriaHelper( expression); selectionCriteriaHelper.addAccessProfile(accessProfile); ExpressionType queryExpression = selectionCriteriaHelper .getSelectionCriteriaExpression(); // Create the request message. GetType verb = createGetVerb(queryExpression); // Execute the request. ShowTutorialStoreDataAreaType showTutorialStoreDataArea = null; try { showTutorialStoreDataArea = getTutorialStore(verb); } catch (TutorialStoreException e) { e.printStackTrace(); } return showTutorialStoreDataArea; } /** * This method composes a Get BOD with an expression to find all the stores * and sends the BOD to the TutorialStore-Server. */ public ShowTutorialStoreDataAreaType findAllStores() { final String METHODNAME = "findAllStores"; // Build the expression. SelectionCriteriaHelper selectionCriteriaHelper = new SelectionCriteriaHelper( SOITutorialStoreFacadeConstants.XPATH_STORE); selectionCriteriaHelper .addAccessProfile(SOITutorialStoreFacadeConstants.ACCESS_PROFILE_SUMMARY_INFORMATION); ExpressionType queryExpression = selectionCriteriaHelper .getSelectionCriteriaExpression(); // Create the request message. GetType verb = createGetVerb(queryExpression); // Send the request. ShowTutorialStoreDataAreaType showTutorialStoreDataArea = null; try { showTutorialStoreDataArea = getTutorialStore(verb); } catch (TutorialStoreException e) { e.printStackTrace(); } return showTutorialStoreDataArea; }
- Save the SOITutorialStoreFacadeClient class.
- Organize the imports for the SOITutorialStore-Client project:
- Open the Java perspective in WebSphere Commerce Developer.
- Right-click the SOITutorialStore-Client\src folder and select Source.
- Select Organize Imports.