Contents


Testing WebSphere Commerce Web services interoperability using soapUI, Part 2

Using customized LoginServices assets

Comments

The customized assets described in this Part 2 tutorial are based on the Creating an outbound Web service client for WebSphere Commerce tutorial in the WebSphere Information Center. That tutorial provides instructions on how to generate similar customized assets to test WebSphere Commerce as a service consumer. Also, other than the last part of this tutorial, under each section there is a link provided for information on how to generate the described customized assets. The last part of the tutorial describes the customized JSPs used.

You also need to install and configure the required prerequisites.

Generating LoginDataObjects from WSDL

Reference Generating the MyCompanyMember data objects from the external system WSDL topic in the WebSphere Commerce Information Center.

In Figure 1, the LoginDataObjects project is created to store the Service Data Objects (SDOs) generated from the provided WSDL. These objects represent the request and response messages to the external Web service. They interact with the actual SOAP XML messages sent and received by the WebSphere Commerce messaging system to the external Web service. The LoginRequestCmdImpl command, described in a later step, will make use of this SDO code. The LoginDataObjects directory structure and files are shown below.

Figure 1. LoginDataObjects project containing the request and response SDOs
LoginDataObjects project containing the request and response SDOs
LoginDataObjects project containing the request and response SDOs

Implementing the LoginServices client API

Reference the Implementing the MyCompanyMember client API topic in the WebSphere Commerce Information Center.

LoginServices client API is created in the WebSphereCommerceServerExtensionsLogic project. This API uses the SDOs generated in the previous step to send request messages and handle response messages via the WebSphere Commerce messaging system.

The API consists of the following artifacts (Figure 2):

  • LoginClientFacadeImpl
    - Uses LoginRequestInvocationServiceObjectImpl to convert the request SDO (LoginRequest) to the request XML.- Instructs the WebSphere Commerce messaging system to transmit the message.- Uses ReplyInvocationServiceObjectImpl to convert the response XML to the response SDO (integer).
  • LoginRequestInvocationServiceObjectImpl
    -
    Converts the request LoginRequest SDO to XML.
  • ReplyInvocationServiceObjectImpl
    -
    Converts the response XML to the integer SDO.
    Figure 2. LoginServices client API
    LoginServices client API
    LoginServices client API

Creating a task command to send and receive messages

Reference the Creating a task command to send and receive message topic in the WebSphere Commerce Information Center.

A new task command, LoginRequestCmd, is created to build a LoginRequest request SDO, use the LoginServices client API to transmit the message, and handle the integer response SDO. This is essentially a wrapper to calling the SDOs that interact with the SOAP messages. See Figure 3.

Figure 3. LoginRequestCmd task command builds the LoginRequest request SDO
LoginRequestCmd task command builds the LoginRequest request SDO
LoginRequestCmd task command builds the LoginRequest request SDO

Integrating the LoginServices client API with WebSphere Commerce

Reference the Integrating the MyCompanyMember client API with WebSphere Commerce topic in the WebSphere Commerce Information Center.

A custom Logon command, TestLogonCmdImpl.java, is needed to integrate with the LoginServices client API that instructs the client API to build and send the appropriate message. This LogonCmdImpl extends out-of-the-box Logon command and invokes the LoginRequestCmdImpl, which then calls the generated SDO code to send and receive the SOAP XML message via the WebSphere Commerce messaging system. See Figure 4.

Figure 4. TestLogonCmd command calls the LoginServices client API
TestLogonCmd command calls the LoginServices client API
TestLogonCmd command calls the LoginServices client API

You need to register this extension command to the command registry by running the following SQL statement. Use the STOREENT_ID, for example 10001, for the test store instead of using "0" below, which applies to all stores.

INSERT INTO CMDREG 
STOREENT_ID, INTERFACENAME, CLASSNAME, TARGET) 
VALUES (0, 'com.ibm.commerce.security.commands.LogonCmd',
' com.test.commerce.login.commands.TestLogonCmdImpl', 
'Local');

Configuring the WebSphere Commerce messaging system

Reference the Configuring the WebSphere Commerce messaging system topic in the WebSphere Commerce Information Center.

A new message type is created and configured to point to the external Web service. This step configures the messaging system to send and receive the SOAP XML messages. Use the following SQL to register the message type:

INSERT INTO MSGTYPES (MSGTYPE_ID, MSGTDIR, NAME, 
VIEWNAME, DESCRIPTION) VALUES (1999, 1, 
'com.test.commerce.login', '', 'Login Customization');

A server restart is necessary before proceeding. A new transport for "WebServices (HTTP)" needs to be added, if not already added (see Figure 5). If it is not already added, follow the instructions in the reference link.

Figure 5. WebServices (HTTP) transport
WebServices (HTTP) transport
WebServices (HTTP) transport

Configure the LoginRequest Customization message type:

  1. Open the WebSphere Commerce Admin Console.
  2. Select Configuration > Message Types.
  3. Click New.
  4. Enter the following as shown in Figure 6:
    Figure 6. Change Message Transport Assignment - Message Type
    Change Message Transport Assignment - Message Type
    Change Message Transport Assignment - Message Type
  5. Select com.test.commerce.login from the Message Type drop down list.
  6. Transport: WebServices(HTTP)
  7. Device format: webservices
  8. Click Next.
  9. URL: http://localhost:8088/mockLoginServices (see Figure 7)
  10. Click Finish.
    Figure 7. Change Message Transport Assignment - Parameters
    7. Change Message Transport Assignment - Parameters
    7. Change Message Transport Assignment - Parameters
  11. Add/Create a component invocation file to the server (Figure 8). There is a sample wc-invocation-client.xml in the sample code section of this tutorial:
    WCDE_installdir\xml\config\ext\.global\com.test.commerce.login\
     wc-invocation-client.xml
    Figure 8. Location of wc-invocation-client.xml
    Location of wc-invocation-client.xml
    Location of wc-invocation-client.xml

Generating the LoginServices Web service

The "LoginServices" project (Figure 9), created in this step acts as a test service at the WebSphere Commerce server. It is not mandatory because WebSphere Commerce will consume the sample LoginServices MockService Web service at soapUI in the logon scenario, instead of this test LoginServices. It is documented here for reference only.

Reference the Generating the MyCompanyMember Services sample user Web service topic in the WebSphere Commerce Information Center.

The following describes the configuration of WebSphere Commerce as a service provider of the Login Web service with the LoginServices.wsdl provided. The LoginServicesImpl is the message response class, returning a response similar to the "Response 1" in soapUI. It has the following method, which takes the loginRequest consisting of username and password and returns an integer response, 1 (true) or 0 (false).

public int execute(LoginTest.LoginRequest loginRequest) throws java.rmi.RemoteException {
// put logic here to return a true (1) or false (0) value 
//for the "test" LoginServices
return 1;
}
Figure 9. LoginServices test service at the WebSphere Commerce server
LoginServices test service at the WebSphere Commerce server
LoginServices test service at the WebSphere Commerce server

You need to add and publish the LoginServicesEAR project to the WebSphere Commerce application so that the LoginServices test service is started when the WebSphere Commerce server is started (Figure 10).

Figure 10. Add and publish the LoginServicesEAR
Add and publish the LoginServicesEAR
Add and publish the LoginServicesEAR

Deploying the LoginServices client

Reference the Deploying and validating the MyCompanyMember client topic in the WebSphere Commerce Information Center.

Add the LoginDataObjects project to the WebSphere Commerce application by updating the Project Utility JARs in the WebSphere Commerce Deployment Descriptor (Figure 11). In a runtime server environment, you can update the deployment descriptor, that is, application.xml.

Figure 11. Add LoginDataObjects to the WebSphere Commerce application
Add LoginDataObjects to the WebSphere Commerce application
Add LoginDataObjects to the WebSphere Commerce application

Update the Stores manifest file referencing the LoginDataObjects project. Navigate to the Stores.war > WebContent > META-INF folder and update the MANIFEST.MF file with the following jar dependency:

Manifest-Version: 1.0
Class-Path: LoginDataObjects.jar

Modifying JSPs to display a Web service response

The sample code in this tutorial contains two JSPs that have been modified to display the Web service request and response parameters on the page:

  1. The UserLogonForm.jsp is modified during the logon failure scenario when the user is not authenticated because the Web service response is false.
    \Stores\WebContent\AdvancedB2BDirect\UserArea\
    AccountSection\LogonSubsection\UserLogonForm.jsp
  2. The TopCategoriesDisplay.jsp is modified during the successful logon scenario when the user is authenticated and redirected to the home page because the Web service response is true.
    \Stores\WebContent\AdvancedB2BDirect\ShoppingArea\       
    CatalogSection\CategorySubsection\TopCategoriesDisplay.jsp

Conclusion

This tutorial explained how customized LoginServices assets are created and then used in the "WebSphere Commerce as a service consumer" section in Part 1 of the tutorial. It described how these assets are generated and how to integrate them into a development environment for testing.


Downloadable resources


Related topics


Comments

Sign in or register to add and subscribe to comments.

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=WebSphere
ArticleID=374092
ArticleTitle=Testing WebSphere Commerce Web services interoperability using soapUI, Part 2
publish-date=03042009