Implementing the client library
In this step, you add convenience methods that hide the complexity of creating the different GetTutorialStore requests.
Procedure
- In the Enterprise Explorer view, go to SOITutorialStore-Client/src/com.mycompany.commerce.soitutorialstore.facade.
- Open the SOITutorialStoreFacadeConstants class for editing.
- 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 final String XPATH_STORE = "/TutorialStore"; /** * The XPath key for finding a store by ID. */ public static final String IDEXPRESSION = "/TutorialStore/TutorialStoreIdentifier[(UniqueID={0})]"; /** * The store ID. */ public static final String STORE_ID = "storeId";
- Save your changes and close the file.
- Go to com.mycompany.commerce.soitutorialstore.facade.client.
- Open the SOITutorialStoreFacadeClient class for editing.
- Add the following Import:
import com.ibm.commerce.foundation.common.util.logging.LoggingHelper;
- 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. * @throws TutorialStoreException */ public ShowTutorialStoreDataAreaType findStoreById(String[] storeId, String accessProfile) throws TutorialStoreException { final String METHODNAME = "findStoreById"; if(LoggingHelper.isEntryExitTraceEnabled(LOGGER)){ LOGGER.entering(CLASSNAME, METHODNAME); } // 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); // Perform the request. ShowTutorialStoreDataAreaType showTutorialStoreDataArea = getTutorialStore(verb); if(LoggingHelper.isEntryExitTraceEnabled(LOGGER)){ LOGGER.exiting(CLASSNAME, METHODNAME); } 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() throws Exception { final String METHODNAME = "findAllStores"; if (LoggingHelper.isEntryExitTraceEnabled(LOGGER)){ LOGGER.entering(CLASSNAME, METHODNAME); } // 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 = getTutorialStore(verb); if(LoggingHelper.isEntryExitTraceEnabled(LOGGER)){ LOGGER.exiting(CLASSNAME, METHODNAME); } return showTutorialStoreDataArea; }
- Save your changes and close the file.
- Organize the imports for the SOITutorialStore-Client project:
- Open the Java perspective in WebSphere Commerce Developer.
- Right-click the SOITutorialStore-Client\src folder.
- Select Source > Organize Imports.