Develop > Persistence layer > Work with WebSphere Commerce services


Use a client library

You can use a WebSphere Commerce services client library (for example, MemberFacadeClient) in a standard Java application.


Before you begin

To use a client library:


Procedure

  1. Add the client library JAR file path to the build path of your Java application.

  2. Initialize the client library, as seen in the following code sample:

        /**
     * Sets the initializes the client based on the
    <code> CallbackHandler
    </code>  * @param aCallbackHandler {@link CallbackHandler}
     */
    private void initializeClient(CallbackHandler aCallbackHandler) {
            iClient = new MemberFacadeClient(iBusinessContext, aCallbackHandler); }
    

  3. Use the client library, as seen in the following code sample for a Get service call:

    //Initialize the client with site admin user permissions
    initializeClient(new SampleCallbackHandlerImpl(SITE_ADMIN_LOGON_ID, SITE_ADMIN_PWD)); 
    //Create the BOD                
    GetType getType =
    AbstractBusinessObjectDocumentFacadeClient.createGetVerb(
            SelectionCriteriaHelper.STR_XPATH_LANG, 
            "{" + MemberFacadeConstants.SELF + "=true;" +
            SelectionCriteriaHelper.STR_ACCESS_PROFILE_PARAMETER  + "="
    +
            MemberFacadeConstants.ACCESS_PROFILE_SUMMARY_INFOMATION +
    "}/Person"); 
    //Use the client library to call the Get Person Web service        
        
    ShowPersonDataAreaType showPersonDAT = iClient.getPerson(getType); 
    // Get the PersonType from the response and use the printPerson()
    method to display the response data           
    PersonType person = (PersonType) showPersonDAT.getPerson().get(0); // Output the logon ID
    System.out.println(person.getCredential().getLogonID());
    

    An example for calling a Process or Change service is seen in the following code sample:

    //Initialize the client to run as a guest user - use null as the
    callback handler
    initializeClient(null); Map parameters = new HashMap();         
    parameters.put("logonId", new String[]{ "myLogonId" } ); parameters.put("logonPassword", String[]{ "myPassw0rd" }); parameters.put("lastName", new String[]{"myLastName"}); parameters.put("city",        new String[]{"Toronto"}); 
    try{
            Map result = iClient.registerPerson(parameters);         String [] strUserId = (String[]) result.get("userId");         System.out.println("========= New userId: " +
    strUserId[0]); } catch (PersonException e) {
            List listErrors = e.getClientErrors();         if (listErrors != null) {
                    for (int i=0; i
    < listErrors.size(); i++) {
                            ClientError clientError = (ClientError)
    listErrors.get(i);                         System.out.println("Message: " +
    clientError.getLocalizedMessage(Locale.ENGLISH));                         System.out.println("Error key: " +
    clientError.getErrorKey());                         System.out.println("Error code: " +
    clientError.getErrorCode());                 }
            }
    }
    

  4. Process the response as appropriate for the Java application.


Related concepts

Client library for WebSphere Commerce services

Web enablement for the client library

WebSphere Commerce Web services

Client library enablement for Struts


Related tasks

Deploy the client library

Extend the client library

Related reference

Client library exceptions

WebSphere Commerce foundation tag library


+

Search Tips   |   Advanced Search