Commerce

Consume SOAP based web services using EMF ( Eclipse Modeling Framework) in IBM WCS.

Use Case:                                    

Let us think that we have to consume a SOAP service which is exposed by third party service. Its required to Invoke this SOAP service from WebSphere Commerce application to fetch certain information from the service provider to validate flow in commerce or store information in commerce.

Learning Objectives:
  1. Required settings to enable Development, XML, Web Service capabilities in Rational Application Developer (IDE)
  2. SDO creation using wsdl file
  3. Required settings to generate WCS 7 compatible Java artifacts from genmodel in SDO
  4. Service Integration In WebSphere Commerce
  5. Message creation and configuration in WCS
  6. Configure invocation component in WC folder

 

Requirements:
  1. IBM WCS version 7
  2. RAD IDE
  3. A Valid wsdl file from service provider or wsdl endpoint URL to point this soap service.

 

Let’s discusses about each learning objectives in-detail.  I would like to classify the whole procedure into six parts.

Parts:
  1. Settings In RAD
  2. EMF project creation
  3. Generation of SDO
  4. Implement Client API for the service with task commands
  5. Message type creation and configuration
  6. Adding  component invocation file to WC directory

 

Part 1:

I.    Settings in RAD:

  1. Open RAD IDE
  2. Select Windows->Preferences
  3. Preferences window opens and expand ‘General’ menu Item.
  4. Select capabilities option.
  5. In the right side capabilities area, select below options
    1. Development
    2. Web Service Developer
    3. XML Developer
  6. Click ok button to save the settings
  7. See the screen shot below

 

 

II.   Display of Properties View:

  1. Open RAD
  2. select Windows->show view -> Properties

 

III.   Settings for Java Artefacts generation for SOAP service

  1. Open RAD
  2. Navigate to Window->Preferences->Web Services->WebSphere->JAX-RPC Code Generation
  3. Select WSDL2JAVA tag
  4. Disable ‘Disable data binding and use SOAPElement’
  5. Click Ok to save changes
  6. Find screenshot below

 

Part 2:

IV.   Create EMF Project from service wsdl using EMF framework in RAD

  1. Download the service wsdl file from given URL
  2. Open RAD
  3. Select File->New->Project
  4. Select ‘EMF Project’ from New Project window and click Next button
  5. Provide name for Project name field. For example, project name is ‘MyCompanyCustomerValidationSDO’. Click next to proceed further
  6. In next window, select XML Schema as model Importer and click next
  7. In next window, browse wsdl file and click on load button. After it loaded successfully, click next
  8. Select the all required packages in next window and click finish.
  9. Once It’s done, one new SDO project will be created in project explorer.
  10. Find the screenshot for all the above steps.

 

  1. Settings for generating Java artifacts (SDOs) for MyCompanyCustomerValidationSDO project using genmodel in it.
    1. Expand MyCompanyCustomerValidationSDO project in enterprise explorer view.
    2. Select and open the genmodel ‘CustomerValidation.genmodel’. Double click opens it
    3. Expand CustomerValidation model
    4. Select the datatype ‘Common’ and its corresponding details will be shown in properties view.
    5. In properties tab, make sure that ‘prefix’ value matches with the datatype name.

 

  1. Similarly, check the prefix for other data type’ V104’. If have many data types in the model, we have to check for all of those prefixes in properties view
  2. Click on save button in main menu bar.
  3. Now select the genmodel ‘CustomerValidation’
  4. Check the below properties are correctly configured in properties view
  5. Click on save button.

 

Part 3:

VI.   Generating Java Artifacts (SDOs) from genmodel in EMF Project.

  1. Open genmodel
  2. Select the model ‘CustomerValidation’
  3. Right click on model and click on set SDO Default
  4. Click on save button
  5. Right click on model and click on ‘Generate Model Code’ option.
  6. With this, the data objects are created for the project.

 

Part 4:

VII.   Implement Client  API to handle service Invocation.

  1. This client is used to send request messages and handle response messages
  2. This class converts request SDO into request xml
  3. It instructs the WebSphere commerce messaging system to transmit the message
  4. It converts response xml to response SDO object
  5. Create a package ‘mycompany.customervalidation’ in WebSphereCommerceServerExtensionsLogic->src
  6. Create a class namely ‘MyCompanyCustomerValidationClientFacadeImpl.java‘ in that package
  7. Define COMPONENT_ID as ‘mycompnay.customervalidation’, we refer this value to create a directory in wcsinstalleddirectory/wc/xml/config
  8. Define action as ‘CustomerValidation’, we refer this value in wc-component-client.xml
  9. Example method to invoke service

 

public PushUserConfirmationType validateCustomerServiceInvocation(String action,        PushUserType pushUser ) throws InvocationServiceException {

DocumentRoot docRoot = MemberFactory.eINSTANCE.createDocumentRoot();                              docRoot.setPushUser(pushUser);       
DataObjectInvocationServiceObjectImpl requestDataObject = new DataObjectInvocationServiceObjectImpl();
               requestDataObject.setDataObject(docRoot.getPushUser());
DataObjectInvocationServiceObjectImpl responseDataObject = new DataObjectInvocationServiceObjectImpl();
                              String actionCode = null;
InvocationService invocationService = new InvocationService(COMPONENT_ID, action, actionCode);
               invocationService.invoke(requestDataObject, responseDataObject);
return (PushUserConfirmationType)responseDataObject.getDataObject();

}

 

 

VIII.  Task commands to handle request and response SDO objects

  1. Create a task command in package ‘mycompany.customervalidation’
  2. Also create an Interface for that task command
  3. Prepare request SDO object with all the required input fields
  4. Once response object is returned to task command, process it fetch the response SDO objects

 

Part 5:

IX.  Create message type for soap service in WCS

  1. Here we have to  configure the new message type to point to the sample web service
  2. Insert the below query in the commerce database
  3. INSERT INTO MSGTYPES (MSGTYPE_ID, MSGTDIR, NAME, VIEWNAME, DESCRIPTION) VALUES ((SELECT MAX(MSGTYPE_ID)+1 FROM MSGTYPES), 1, ‘com.mycompany.commerce.customervalidation, ”, Customer Validation Customization’);

 

X.   Configure message type in commerce admin tool

  1. Open WebSphere commerce admin console
  2. Logon to the admin console tool
  3. Select site option from the window
  4. Select Configuration->Message Types
  5. Click on New button
  6. Select the message type, transport and device format
  7. Provide the wsdl end point URL in next screen and click finish button

 

 

Part 6:

XI.  Configure invocation component file in WC

  1. Create a directory ‘com.mycompnay.customervalidation-ext’ under  WC_eardir\xml\config\
  2. Create a file ‘SDO.properties’ in com.mycompnay.customervalidation-ext
  3. Add package Impl class in this properties file.
  4. Create xml file ‘wc-component-client.xml’ under com.mycompnay.customervalidation-ext
  5. Add the newly created emf project to the build path.
  6. Start the commerce server
  7. Test the service by executing the task command.

About The Author

Leave a Reply

*