Tutorials > Program model > Web services > Create a WebSphere Commerce service module (SOI) > Creating the Get TutorialStore service

< Previous | Next >


Implement the client library

In this step, you add convenience methods that hide the complexity of creating the different GetTutorialStore requests.


Procedure

  1. Open the SOITutorialStore-Client/src/com.mycompany.commerce.soitutorialstore.facade.SOITutorialStoreFacadeConstants class.

  2. 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"; 
    

  3. Save the SOITutorialStoreFacadeConstants class.

  4. Open the com.mycompany.commerce.soitutorialstore.facade.client.SOITutorialStoreFacadeClient class.

  5. 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;
    
        }
    

  6. Save the SOITutorialStoreFacadeClient class.

  7. Organize the imports for the SOITutorialStore-Client project:

    1. Open the Java perspective in WebSphere Commerce Developer.

    2. Right-click the SOITutorialStore-Client\src folder and select Source.

    3. Select Organize Imports.

< Previous | Next >


+

Search Tips   |   Advanced Search