Use a client library
A client library is used to create a web service request to WebSphere Commerce. We can use a WebSphere Commerce services client library (for example, MemberFacadeClient) in a standard Java application.
Before beginning
- Understand and select your client library authentication mechanism.
- Deploy the client library to your development environment using the instructions for the authentication mechanism we select.
Task info
A client library's use depends on how it is invoked:
- Use the GetData tag to perform a service request; for example, creating a Get request by using a JSP, applicable to Management Center and Store clients.
- Use the ComponentServiceAction; for example, creating a Change/Process request from the Store.
- Directly using the client library; for example, a J2SE application.
To use a client library:
Procedure
- Add the client library JAR file path to the build path of your Java application.
- Initialize the client library, as seen in the following code sample:
private MemberFacadeClient iClient = null; /** * 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); }
- 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_INFORMATION + "}/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", new 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()); } } }
- Process the response as appropriate for our Java application.
Related concepts
Client library for WebSphere Commerce services
Web enablement for the client library
Client library enablement for Struts
Related tasks
Deploying the client library
Extending the client library
Related reference
Client library exceptions
WebSphere Commerce foundation tag library