Developing adaptive composite business services using WebSphere Business Services Fabric: Part 4: Service assembly with the Dynamic Assembler SCA component

Continuing with composite business service modeling, ontology editing, and policy simulation from Part 3, this installment provides a step-by-step sample to demonstrate how to use the Business Services Dynamic Assembler SCA component to assemble services in the IBM® WebSphere® Business Services Fabric tooling environment. This content is part of the IBM WebSphere Developer Technical Journal.

Libra Huang (librah@tw.ibm.com), IT Architect, IBM SOA Solution Center

Author photoLibra Huang is an IT Architect with SOA Solution Center (SSC), IBM Software Group. His background is in J2EE and is now heavily involved with Composite Business Services (CBS) assets development for banking industry.



Hicks Lin (zhlin@tw.ibm.com), Software Engineer, IBM SOA Solution Center

Hicks LinHicks Lin is a developer from IBM China Software Development Lab in Taipei. He is currently developing Composite Business Service (CBS) applications for banking industry. He is interested in SOA, J2EE and other emerging server-side technologies.



Jimmy Tan (jimmytan@tw.ibm.com), Software Engineer, IBM SOA Solution Center

Author photoJimmy Tan is a senior developer from SOA Solution Center, IBM Software Group. He is developing Composite Business Service (CBS) for banking industry. He is interested in SOA, J2EE and software architecture.



Daniel Wu (danielwu@tw.ibm.com), Staff Software Engineer, IBM SOA Solution Center

Daniel WuDaniel Wu is working at IBM Software Group as a software engineer in developing Composite Business Service (CBS) application for banking industry.



Frank Wong (zhwong@cn.ibm.com), Staff Software Engineer, IBM SOA Solution Center

Author photoFrank Wong is a software engineer from IBM China Software Development Lab, Taipei. He is currently developing Composite Business Services (CBS) as the banking industry's solution accelerators.



22 August 2007

Also available in Japanese

Introduction

This series of articles has been discussing the end-to-end process of creating composite business services with IBM WebSphere Business Services Fabric Version 6.0. Part 1 introduced the idea of composite business services, and how WebSphere Business Services Fabric supports the development of these services, then Part 2 explained how WebSphere Business Services Fabric can help resolve a proposed business problem by illustrating the resulting analysis and design steps.

In the case study presented in Part 2, you learned that our fictional International Bank (INT Bank) wants their new loan processing application to select the appropriate credit information service provider based on the loan size and wallet share of the customer applying for the loan. The two service providers that will be used are:

  • Customer Credit Information System (CCIS), which is an internal INT Bank application.
  • Credit Digger, an external service renowned for providing high quality customer credit information.

Updated article
The previous article in this series, Part 3: CBS modeling, ontology editing, and policy simulation, has been updated since its original publication to reflect WebSphere Business Services Fabric V6.0.2.

In Part 3, you created the business service model as a first step to resolve INT Bank’s business problem. Here, in Part 4, you will step through the process of using the IBM Business Services Dynamic Assembler component (hereafter referred to as Dynamic Assembler) to assemble and realize the business service, and conduct unit testing in the integrated test environment. With Dynamic Assembler, the binding between requester and the actual service provider can be deferred until run time and be dependent upon specific parameters.

To demonstrate dynamic assembly and help you follow along, a sample application is provided with this article that includes two different Web service implementations.

Below are the general steps for assembling and testing the sample CBS. This article explains the tasks associated with each of these steps in detail:

  1. Setup the CCIS and Credit Digger sample Web services
  2. Create the CreditService SCA module with the Dynamic Assembler
  3. Import the SCA module into Composition Studio
  4. Perform a component test on the SCA module

This article assumes you have read the previous articles in this series.


A. Setup the CCIS and Credit Digger sample Web services

Sample Web services implementations of CCIS and CreditDigger are provided with this article for illustration and testing purposes. The enterprise application archive file provided, CreditVeriSrvcEAR, includes two Web applications:

  • CreditVeriCD includes the Credit Digger Web service.
  • CreditVeriCCIS includes the Customer Credit Information System Web service.

Both Web service implementations share the same Web service interface, and so either could be dynamically selected at run time by the Dynamic Assembler.

To deploy the sample Web services into the runtime environment and verify them:

  1. In WebSphere Integration Developer, open the Server view in any perspective to find the new WebSphere Business Services Fabric Server v6.0 (Figure 1). Because the WebSphere Business Services Fabric server is built on top of WebSphere Process Server, the usual SCA modules (including BPEL or mediations) could be deployed and tested on this server instance.

    Figure 1. Server view inside WebSphere Integration Developer
    Figure 1. Server view inside WebSphere Integration Developer
  2. The WebSphere Business Services Fabric V6.0.2 Tool Pack contains a built-in Unit Test Environment (UTE). Before using the UTE, the security information must be configured correctly. Select the WebSphere Business Services Fabric Server v6.0 and the Server Overview panel will display (Figure 2).

  3. In the Security section, enter the User ID and Password for the Fabric server. The default User ID and Password values are admin and webify, respectively (Figure 2).

    Figure 2. Change the security information in server overview
    Figure 2. Change the security information in server overview
  4. From the J2EE™ perspective, import the CreditVeriSrvcEAR.ear into the workspace. For Target server, select WebSphere Business Services Fabric Server v6.0 (Figure 3).

    Figure 3. Import the sample Web service project into the workspace
    Figure 3. Import the sample Web service project into the workspace
  5. The CreditVeriSrvcEAR.ear includes two Web modules: CreditVeriCD.war and CreditVeriCCIS.war. Select both Web projects and click Finish to start the import (Figure 4).

    Figure 4. The two Web projects inside the EAR module
    Figure 4. The two Web projects inside the EAR module
  6. The two Web services are now deployed to the Fabric server, and so you can try to test them. Go to any of the Web projects under WebContent/wsdl and find the wsdl file for the Web services. (As shown in Figure 6, the CCIS and Credit Digger Web services take loanAmount and other input parameters and return the corresponding credit score.) Right click on a WSDL file and select Web Service => Test with Web Service Explorer. (Figure 5)

    Figure 5. Test the Web service with Web Service Explorer
    Figure 5. Test the Web service with Web Service Explorer
  7. Enter the parameters shown in Figure 6 and click Go. You should receive the resulting credit score, with the CCIS Web service having been successfully invoked.

    Figure 6. Input parameters and verify the Web service execution result
    Figure 6. Input parameters and verify the Web service execution result

B. Create the CreditService SCA module with the Dynamic Assembler

Create SCA module

  1. In the Business Integration perspective, right-click to create a New => Module project (Figure 7). Figure 8 shows the resulting artifacts in this new Module project. (If you are not familiar with SCA module, see the WebSphere Integration Developer Information Center and Building SOA solutions with the Service Component Architecture for more information.)

    Figure 7. Create a new business integration module
    Figure 7. Create a new business integration module
    Figure 8. The new Business Integration module
    Figure 8. The new Business Integration module
  2. Right-click Interfaces to import the CCIS and CreditDigger Web services WSDL files, along with their dependent resources (Figure 9). The sample WSDL could be found in the FabricSCASample.zip download file.

    Figure 9. Import a WSDL file
    Figure 9. Import a WSDL file
  3. Double-click Assembly Diagram in the Business Integration view to open the Assembly Editor. Drag and drop a Dynamic Assembler component (Figure 10) into the assembly diagram and rename it as CreditDA. The Dynamic Assembler component is a new SCA component provided by WebSphere Business Services Fabric that can be used to select a suitable service endpoint from among different registered service implementations, based on context, content, and contract information

    Figure10. The new Dynamic Assembler component
    Figure10. The new Dynamic Assembler component
  4. To add an interface to the new component, right click on the CreditDA component and select Add => Interface (Figure 11). When prompted, select the CreditVerificationSrvc interface.

    Figure 11. Add a new interface to the Dynamic Assembler component
    Figure 11. Add a new interface to the Dynamic Assembler component
  5. Right-click on the CreditDA component. To generate an implementation for the CreditDA component, right-click on the component and select Generate Implementation (Figure 12). When prompted, select the default package for the implementation.

    Figure 12. Generate the default implementation for Dynamic Assembler component
    Figure 12. Generate the default implementation for Dynamic Assembler component

Building a Dynamic Assembler extension model

WebSphere Business Services Fabric V6.0.2 provides an extension framework that enables you to plug in customized code that will be invoked by the WebSphere Business Service Fabric runtime during the service invocation lifecycle. The extension framework lets you to override default policy behavior, fire events, and extract context information from the payload. Next, you will create a context extractor extension that will enable you to extract the context information from the payload and add it to the Dynamic Assembler context. Based on the supplied loan amount and organization information in the context, Dynamic Assembler will bind the service request to either CCIS or CreditDigger. (See the WebSphere Business Services Fabric Information Center for other extension interfaces.)

  1. Before creating a context extractor, the required WebSphere Business Services Fabric Java™ libraries need to be imported into the project build path. Right-click on the CreditSrvc module project, and select Properties (Figure 13).

  2. From the list of properties on the left, select Java Build Path, then select the Libraries tab (Figure 14).

  3. Click Add External JARs to add these three Java libraries, located at <WebSphere Integration Developer installation path>\runtimes\bi_v6\lib\ext:

    • fabric-da.api.jar
    • fabric-da-sca.jar
    • fabric-da.scdl.jar.
    Figure 13. Add project properties
    Figure 13. Add project properties
    Figure 14. Add Fabric libraries as external JARs
    Figure 14. Add Fabric libraries as external JARs
  4. Drag and drop a Java component into the Assembly Diagram and rename it as CreditContextExtractor. You will put the Java code extension to this component.

    Figure 15. Create a new Java component for context extractor
    Figure 15. Create a new Java component for context extractor
  5. Right click on the CreditContextExtractor component and select Add => Interface to add the com.ibm.websphere.fabric.da.plugin.ContextExtractor interface to the component. (Figure 16)

    Figure 16. Add the context extractor interface to the Java component
    Figure 16. Add the context extractor interface to the Java component
  6. The next job is to implement the ContextExtractor based on the imported interface. Right-click on the CreditContextExtractor to generate an implementation. Listing 1 shows the default generated code.

    Listing 1. Default implementation for CreditContextExtractor
    public class CreditContextExtractorImpl implements ContextExtractor {
    	/**
    	 * Default constructor.
    	 */
    	public CreditContextExtractorImpl() {
    		super();
    	}
    	
    	private ContextExtractor getMyService() {
    		return (ContextExtractor) ServiceManager.INSTANCE.locateService("self");
    	}
    
    	public Context extractContext(PendingRequest arg0)
    			throws UnexpectedContentException {
    		//TODO Needs to be implemented.
    		return null;
    	}
    }
  7. You will add code to the extractContext method to extract loanAmount and organizationId values from the service request body. The organizationId represents which organization (either INT bank, INT-CA, or INT-TX) this request originates from. Figure 17 shows the service request body format, and Listing 2 shows the code that retrieves loanAmount and organizationId from the SOAP request body.

    Figure 17. CreditVerificationSrvc WSDL
    Figure 17. CreditVerificationSrvc WSDL
    Listing 2. Code segment to obtain required assertion property from request
    //Get message body from request
    DataObject body = arg0.getMessageBody();
    DataObject creditRequest = ((DataObject)body.getSequence(0).getValue(0));
                                        
    //Print out the content of data object via SdoUtil provided by Fabric
    System.out.println(SdoUtil.printTree(creditRequest)); 
                                        
    //Retrieve loanAmount and organizationId value
    Integer loanAmount = (Integer) creditRequest.get("loanAmount");
    Integer organizationId = (Integer)creditRequest.get("organizationId");

    Listing 3 shows a sample result output of the data object CreditRequestBO.

    Listing 3. Sample output of the data object
    <dataobject>
    	CreditRequestBO
    		companyName:  IBM <simple>  (java.lang.String);
    		companyDUNSId:  123456 <simple>  (java.lang.String);
    		loanAmount: 10000 <simple>  (java.lang.Integer);
    		organizationId: 1 <simple>  (java.lang.Integer);  
    </dataobject>
  8. After the loanAmount and organizationId parameters values are retrieved from the request, the parameters can be passed into Dynamic Assembly component for endpoint selection decision. You now need to add the loanAmount and organizationId values to the context, as shown in Listing 4, so that Dynamic Assembler can use this information to select the endpoints.

    Note that in this sample application, the organizationId retrieved from the request is just an external representation used to simplify the input of original organization name information. You need to map the external organizationId to the internal organization instance ID (from the organization instances that you created in Part 3 so that WebSphere Business Services Fabric can recognize it. The organization instances URI value can be found in the organization Property window, shown in Figure 18 (open the Subscriber Explorer view, then select the organization instance that you want to examine). For your reference, the table below lists the mapping between organizationId and organization instance id URI. WebSphere Business Services Fabric provides an SDK that enables you to query for this type of information. (To simplify this example, this information was hardcoded in the Content Extractor component.)

    organizationId (input parameter)Organization nameorganization instance id
    0International Bankfc://fabric/subscriber/organization-inst#82fa27a2-702e-42ae-88c7-41c134e10643
    1International Bank of Californiafc://fabric/subscriber/organization-inst#4cbd859b-52fd-4f48-b8b3-381e8ac6dadb
    2International Bank of Texasfc://fabric/subscriber/organization-inst#eb5357a3-c3a6-4853-bca5-fcd3fd42bf9f
    Figure 18. Get International Bank organization instance id from subscriber explorer
    Figure 18. Get International Bank organization instance id from subscriber explorer
  9. The loanAmount value needs to be bound to the LoanAmountAssertion, which was created in Part 3. The LoanAmountAssertion URI value can be found in its Property window. From the Business Services view, select any endpoint (Figure 19), then select the Assertions tab. Select the LoanAmountAssertion and click the Edit button to bring up the Property window (Figure 20).

    Figure 19. Switch to Business Services perspective
    Figure 19. Switch to Business Services perspective
    Figure 20. Get the assertion property URI from assertion information window
    Figure 20. Get the assertion property URI from assertion information window
    Listing 4 . Add parameter values to context
    //Get the request context
    Context context = arg0.getContext();
    
    //Bind the loanAmount value to LoanAmountAssertion
    final String LOANAMOUNT_URI ="http://intbank/loan/loanorigination#loanAmount";
    context.setSelectionProperty(LOANAMOUNT_URI,  new TypedValue(loanAmount.toString()));
    
    
    //Map the organizationId value to organization instance URI
    String organizationINST =null;
    switch (organizationId.intValue()) {
    	// 0 => International Bank
    	case 0:  organizationINST=INTLBANK_ID; break; 
    
    	//1 => International Bank of California
    	case 1:  organizationINST=INTLBANKCA_ID; break;
    
    	//2 => International Bank of Texas
    	case 2:  organizationINST=INTLBANKTX_ID; break;
    
    	//Otherwise, invalid input
    	default: System.out.println("No Valid Input for Organization ID");break;
    }
    
    //Bind to organization instance URI to organization
    final String ORG_URI =  
    	"http://www.webifysolutions.com/2005/10/catalog/subscriber#Organization";
    context.setSelectionProperty(ORG_URI, new TypedValue(organizationINST));
    
    return context;

    The complete reference code (CreditContextExtractorImpl.java) can be found in the Download section.

  10. It's time to assemble the components in the CreditSrcs SCA module. This will be accomplished through wiring. Drag and drop an Export component onto the assembly diagram, rename it to CreditDAExport (Figure 21).

    Figure 21. Create new export component
    Figure 21. Create new export component
  11. Add one interface for the export component. In this case, specify the CreditVerificationSrvc interface (Figure 22).

    Figure 22. Add a new interface to the export component
    Figure 22. Add a new interface to the export component
  12. Wire these three components together (Figure 23). At this point, you have finished everything you needed to do within the Business Integration perspective.

    Figure 23. Wire the components in assembly diagram
    Figure 23. Wire the components in assembly diagram

C. Import the SCA module into Composition Studio

The tasks in this section will be based on the project artifacts created from Part 3, upon which you will make minor changes for the SCA module introduced in this article. Namely, you will associate a business service with the new SCA module:

  1. Switch to the Business Service perspective.

    Figure 24. Switch to Business Service perspective
    Figure 24. Switch to Business Service perspective
  2. Right click on Composite Service, then select New => Composite Service. (Figure 25)

    Figure 25. Create a new composite service
    Figure 25. Create a new composite service
  3. Select the following values for these fields in the New Composite Service panel (Figure 26):

    • Project: LoanOrigination
    • Namespace: Loan Origination Instance
    • SCA Project: CreditSrvc

    Click Finish to start the import.

    Figure 26. Select Project, Namespace, and SCA Project values for the new composite service
    Figure 26. Select Project, Namespace, and SCA Project values for the new composite service
  4. After importing the CreditSrvc composite service, the service now needs to be associated with the Business Service utilizing it. Select Business Service => Process Service => Loan Processing Service (Figure 27). The Process Service window will display (Figure 28).

    Figure 27. Change the process service information
    Figure 27. Change the process service information
  5. Go to the Interfaces tab, select the CreditVerifiationSrvc interface, and click Edit (Figure 28).

    Figure 28. Edit the interface information
    Figure 28. Edit the interface information
  6. When the Edit Interface dialog displays, change the module from <Fabric Hub> to the CreditSrvc SCA module. (Figure 29). Here, the SCA module in WebSphere Business Services Fabric V6.0.2 will replace the <Fabric Hub> model in Version 6.0. Click OK to finish.

    Figure 29. Replace the <Fabric Hub> module with the SCA project
    Figure 29. Replace the <Fabric Hub> module with the SCA project
  7. When all the changes in the Business Service perspective are complete, click the Submit Changelist button to submit the changes (Figure 30).

    Figure 30. Submit changelist
    Figure 30. Submit changelist
  8. In the Fabric 6.0.2 Tool Pack, the changes in the UTE repository (BSR) are approved automatically by the system. After submitting the change list, click the Update Project button to synchronize the content from the BSR (Figure 31).

    Figure 31. Update project information
    Figure 31. Update project information

D. Perform a component test on the SCA module

You can now run a component test to make sure everything works as expected.

  1. Switch to the Business Integration perspective and click the assembly diagram in the Business Explorer view to open the Assembly Editor.

  2. Right-click on the CreditDAExport component and select Test Component (Figure 32).

    Figure 32. Right click on the export component to perform component test
    Figure 32. Right click on the export component to perform component test
  3. From the Events tab, enter the following values for these input request parameters (Figure 33):

    • companyName: IBM
    • companyDUNSId: 1234
    • loanAmount: 10000
    • organizationId: 1

    Click Continue.

    Figure 33. Input parameters for testing
    Figure 33. Input parameters for testing
  4. Select WebSphere Business Services Fabric Server v6.0 as the Deployment location (Figure 34).

    Figure 34. Select deployment location
    Figure 34. Select deployment location
  5. Enter User ID and Password for the component test (default values are admin and webify, respectively) (Figure 35).

    Figure 35. Enter security information for component test
    Figure 35. Enter security information for component test
  6. Figure 36 shows the execution result. In the Console tab, you can see Credit Digger Service was selected per the supplied test data. According to the scenario defined in the previous article, when loanAmount is larger than 10000 and organization is International Bank of California (organizationId =1), then the Credit Digger service should be selected and invoked. See Part 3 for additional testing scenarios.

    Figure 36. Verify the execution result
    Figure 36. Verify the execution result

Conclusion

In this article, you learned how to use a Dynamic Assembler SCA module to perform services through dynamic assembly in a WebSphere Business Services Fabric project. You also learned how to use Dynamic Assembler extension to extract data from a request message body and supply the information to the Dynamic Assembler to accommodate a dynamic endpoint selection decision. Finally, with the Unit Test Environment you were able to test the component to make sure your code works correctly.

For more learning resources on WebSphere Business Services Fabric SCA programming, including other Version 6.0.2 Dynamic Assembler extensions, see the IBM WebSphere Business Services Fabric Information Center.

This article concludes this series on developing adaptive business services with WebSphere Business Services Fabric. With the information provided in this series, you learned about the concepts of composite business services, and should now be ready to build and test these dynamic services for your applications to deliver business function based on context and policy.


Acknowledgements

The authors thank Chaitanya Laxminarayan, Keith McCarthy, and the WebSphere Business Services Fabric product technical team for their support making this series of articles complete and accurate.


More in this series


Download

DescriptionNameSize
Sample applicationFabricSCASample.20070808.zip42 KB

Resources

Comments

developerWorks: Sign in

Required fields are indicated with an asterisk (*).


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Information in your profile (your name, country/region, and company name) is displayed to the public and will accompany any content you post, unless you opt to hide your company name. You may update your IBM account at any time.

All information submitted is secure.

Choose your display name



The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

Required fields are indicated with an asterisk (*).

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


All information submitted is secure.

Dig deeper into Business process management on developerWorks


static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Business process management, WebSphere, SOA and web services
ArticleID=249714
ArticleTitle=Developing adaptive composite business services using WebSphere Business Services Fabric: Part 4: Service assembly with the Dynamic Assembler SCA component
publish-date=08222007