Using pureXML in SCA component development with WebSphere Integration Developer V7

Learn how to develop service components by combining pureXML, data Web services, and data objects and using a sample module project with WebSphere® Integration Developer V7.

Share:

Jun Xue (xuejun@cn.ibm.com), Software Engineer, IBM

Jun Xue photoJun Xue is a Software Engineer at the IBM China Development Lab, Shanghai. He has 3 years experience in SOA solution design and development using DB2, WebSphere Process Server, and WebSphere Portal Server. He holds a Master's degree in Computer Science and Engineering from Shanghai Jiao Tong University.



Song Nian Shao (shaosn@cn.ibm.com), Software Engineer, IBM

Photo of Song Nian ShaoSong Nian Shao is a Software Engineer at the IBM China Development Lab, Shanghai. He has more than one year's experience in application development, especially in the field of middleware and data persistence.



28 July 2010

Also available in Chinese Portuguese

Overview

Service components, which adopt the Service Component Architecture (SCA) programming model, use business objects for exchanging data among them. A business object (BO) is a container for application data, such as a customer or an invoice. Therefore, it becomes a common problem on how to store and query business objects when developing different kinds of SCA components.

DB2® V9 pureXML supports storing and querying Extensible Markup Language (XML) documents in its native hierarchical format. The underlying structure of a business object is an XML schema definition (XSD). You can parse business objects into a XML document and deserialize them from the XML document using Service Data Object (SDO) APIs.

Instead of the traditional way to access database using a Data Access Object (DAO) pattern with JDBC or hibernate, this article shows you web services-based access to DB2 using Data web services, a new feature provided by IBM Data Studio.

In this article, you will learn how to develop SCA components using pureXML web services to store and query business objects with WebSphere Integration Developer.

The sample applications and code snippets help explain the benefits of integrating pureXML web services with SCA components. This article will cover basic principles that you need to know when using pureXML and developing SCA components. You will explore how to expose pureXML web services to access DB2, how to operate with business objects with SDO APIs, and how to call pureXML web services within your SCA component.


Prerequisites

In this article, you will use WebSphere Integration Developer together with Data Studio to build a sample application. We assume that you have experience with web services, pureXML, and SCA. For more information about these technologies, see the Resources section.

You need to install the following software:

  • WebSphere Integration Developer V7: This is an Eclipse-based tool for end-to-end integration of your SOA application.
  • IBM Data Studio: This development environment offers a multitude of functionalities, such as Data web service, which you can expose database operations as web services without programming.
  • DB2 V9: This is a hybrid database system utilizing pureXML technology to store XML data natively.

This article provides sample code that you can download.


Introduction

The sample application in this article is a fictitious Person Contact Service. Users or other applications can use this service to store and query person contact information. There are two main parts:

  • SCA service: This is a service developed using WebSphere Integration Developer V7. It provides two operations for person contact: one is to save the contact information, and the other is to query the contact information according to the person’s name.
  • Web service for data access: You will use Data Studio to expose the SQL or XML scripts as a web service. Its main function is to access data in DB2.

Figure 1 shows the architecture of the sample application.

Figure 1. Integrate pureXML web services with SCA component
Integrate pureXML web services with SCA component

Download the sample source code. The sample is designed to run with WebSphere Process Server V7. There is one deployable file for pureXML web service, the predefined library project, and the source code for SCA component module.

The following sample files are provided with this article:

  • ContactLib.zip contains the predefined library project, including the business objects and service interfaces.
  • ContactModule.zip contains the source code files for the SCA component module.
  • pureXMLWebService.zip contains the deployable WAR file for the sample pureXML web service and the corresponding data development project.

DB2 pureXML and Data web service

DB2 9 is a new generation data server with a revolutionary pureXML technology that can store XML data natively inside a DB2 database. It provides simple and efficient access to XML with the same levels of security, integrity, and resiliency taken for granted with relational data.

Modern SOA applications are often deployed with web services as a standardized and independent means of exposing business logic or data access over internet. You can utilize Data Studio to create web services to expose the data in DB2. Data Studio is an Eclipse-based tool including many new features, which includes support of Data web services. A Data web service is the next generation solution that significantly eases the development, deployment, and management of web services-based access to DB2 and other IBM database servers. It enables you to simply and quickly create either REST-style or SOAP binding services over HTTP to access data.


Service Data Objects in WebSphere Integration Developer

SCA services typically use document-style business data for parameters and return values, and SDOs are the preferred form for data and metadata. SCA defines the services as components and the connectivity between them. SDOs define the data that is flowing between components.

SDOs support XML schema for metadata and XML as a data source and support for using XPath expressions to get and set values. When you work with SDO, you can create one or many structures called data objects, each of which includes business data organized into a collection of named properties. You can then get or set the data for each property, whether the property holds a data item, such as a customer name, or a reference to another data object. Properties that hold data items are based on data types such as a string or integer.

In WebSphere Integration Developer, you dynamically define and access a data object and reference data-type descriptions at runtime. In our sample application, the data object will be serialized into XML document and then saved into the database. Figure 2 shows an example of an XML document that represents the data object after serialization.

Figure 2. Example XML document representing the data object
Example XML document representing the data object

Review business objects and the service interface

There is one business object named Contact and one service interface named ContactService that are defined in our sample application, as shown in Figure 3 and Figure 4. The service defined two operations around the business object Contact: one is to save the contact information and the other is to query the contact information by the person’s name.

Figure 3. Business object
Business object
Figure 4. Service interface
Service interface

Setup the sample database

The business object defined in the above section will be stored into the DB2 database using native XML format. You can refer to the Data Definition Language (DDL) statements in Listing 1 to create the database and table for the sample application.

Listing 1. DDL for the database and table
create database condb using codeset utf8 territory us

create table contact_table (
  id bigint primary key not null generated by default as identity 
  ( START WITH 1 INCREMENT BY 1 MINVALUE 1 MAXVALUE 10000 NO CYCLE CACHE 20), 
  contactdoc xml
);

Expose the pureXML Data web services

The pureXML Data web service in our sample shows you how to save the XML document of the data object and how to return the query results. Data web services are comprised of SQL scripts or procedures that you want to expose as services. Follow these steps to create the SQL web services using Data Studio:

  1. To open a new Data Development project from the Data Project Explorer, right-click on the blank panel and select New > Data Development Project from the pop-up menu. The new data development project wizard appears.
  2. Type the project name as SampleDBService and click Next. Select the existing connection named condb. If there is no database connection, you can click New to create one.
  3. Click Finish and the new project is shown in the Data Project Explorer (Figure 5).
    Figure 5. Data Development project
    Data Development project
  4. To create a new SQL script, from the Data Project Explorer, select the SQL Scripts node, and right-click and select New > SQL or XQuery Script. This launches the wizard.
  5. Enter the name as saveContact for the script name and click Finish to open the SQL Editor.
  6. Enter the statement as shown in Listing 2 and save it.
    Listing 2. SQL script for saveContact
    insert into contact_table (contactdoc) values (:contactdoc)
  7. Repeat Steps 4 to 6 to create another SQL script named queryContactByName (see Listing 3).
    Listing 3. SQL script for queryContactByName
    select xmlserialize(contactdoc as clob(32000)) as contact from contact_table
    where xmlexists('$doc/*[local-name()="ROOT"][lastName=$lastName and 
     firstName=$firstName]'
    passing contactdoc as "doc",
    cast (:lastName as varchar(100)) as "lastName",
    cast (:firstName as varchar(100)) as "firstName")
  8. The two SQL scripts are ready, as shown in Figure 6.
    Figure 6. SQL Editor
    SQL Editor
  9. To create a web service, from the Data Project Explorer, select the Web Services node, and right-click and select New Web Service. This launches the New Web Service wizard (Figure 7).
    Figure 7. New Web Service wizard
    New Web Service wizard
  10. Enter your web service name, such as ContactDBService, and click Finish. Your newly created web service ContactDBService is listed under the Web Services node in the Data Project Explorer, as shown in Figure 8.
  11. To add a SQL script to your web service, drag and drop saveContact.sql onto the web service ContactDBService from the Data Project Explorer. Your web service now has an operation named saveContact (see Figure 8).
  12. Similarly, add the SQL script queryContactByName.sql to the web service ContactDBService. You now have two operations in your ContactDBService web service: saveContract and queryContactByName (see Figure 8).
    Figure 8. Overview of ContactDBService web service
    Overview of ContactDBService web service

    Now that your web service is defined, you can build a deployable file for WebSphere Process Server V7. From the Data Project Explorer, select ContactDBService, and right-click and select Build and Deploy to launch the wizard. Ensure your selections are the same values with those shown in Figure 9.

    Figure 9. Build a deployable file for the web service
    Build a deployable file for the web service

    The selected values for the deployment are:

    1. Web server type: WebSphere Application Server V7 (all releases)
    2. Option: Build deployable files only, do not deploy to a web server, Selected
    3. Data Handler: JDBC, Selected
    4. Message protocols: REST (web access) and SOAP over HTTP, Selected

A deployable WAR file is generated in the directory of your workspace, SampleDBService/DataServerWebServices/ContactDBService. In order to use it in the sample SCA service, deploy it to the WebSphere Process Server V7 testing environment installed together with WebSphere Integration Developer V7.


Create the sample SCA service

This section describes how to develop the sample service component with the WSDL port type interface and Java™ implementation.

The business objects and interfaces are ready for you to use. Download the ContactLib.zip file and save it to your local file folder. Then import the predefined Library project to WebSphere Integration Developer.

To create a new module project:

  1. To create a new module, click File > New >Module. The wizard appears. Enter the Module name, such as ContactModule, and click Finish. You can see the project has been created in the Business Integration view.
  2. To add library dependencies, click Dependencies in ContactModule to open the editor. When you click Add in the Libraries section, the Library Selection dialog appears. Select ContactLib and click OK, as shown in Figure 10.
    Figure 10. Add dependencies library
    Add dependencies library
  3. To save the Dependencies modification, press Ctrl+S and close the Dependencies editor.

    Now that you have created a new module project and have a reference to the predefined library, you can continue to create the Java component:

  4. Open the Assembly Diagram editor, select and drag Java to the editor, and rename the component to ContactComponent, as shown in Figure 11.
    Figure 11. Assembly Diagram Editor
    Assembly Diagram Editor
  5. To assign an interface, right-click ContactComponent, select Add > Interface, select ContactService, and then click OK.
  6. Click Ctrl+S to save the Assembly Diagram.

Access the pureXML web service

An existing pureXML web service, ContactDBService, is ready from our previous section. Once it has been deployed to WebSphere Process Server, you can call it from a module using an import.

To access the existing web service:

  1. Export the WSDL files of the web service ContactDBService from the running WebSphere Process Server by saving and unzipping it to your local directory.
    Figure 12. Export WSDL files from server
    Export WSDL files from server
  2. To import the WSDL files to your module, right-click the project ContactModule and select Import from the pop-up menu. When the import dialog appears, select WSDL and XSD under Business Integration section. Click Next as shown in Figure 13.
    Figure 13. Import WSDL and XSD files
    Import WSDL and XSD files
  3. To locate the local file, select option Local WSDL or XSD file or both, and click Next. Browse to the source directory where you just saved the exported files. Select the ContactDBService.wsdl file and ContactModule as the target module or library. Click Finish.
  4. To create an import, open the Assembly Diagram editor. Select and drag Import to the editor.
  5. To assign an interface for the import, right-click Import1 and click Add Interface from the pop-up menu. Select ContactDBService and click OK.
  6. To generate the web service binding for Import1, right-click Import1 and select Generate Binding... > Web Service Binding. The import details dialog box appears as shown in Figure 14. Select the option Use an existing web service port, click Browse to select the existing port ContactDBSerivceSOAPHTTP and click OK. A dialog prompts you to select the Transport Protocol for the web service binding. Select the option SOAP1.1/HTTP and click Finish.
    Figure 14. Web service binding
    Web service binding
  7. To create a connection between ContactComponent and Import1, save the Assembly Diagram editor. The editor looks similar to Figure 15.
    Figure 15. Assembly Diagram Editor
    Assembly Diagram Editor

Create the implementation for ContactComponent

To create the Java implementation for ContactComponent:

  1. Open the Assembly Diagram editor. Double-click ContactComponent, keep the defaults, and click OK.
  2. The Java class named ContactComponentImpl is created and it opens automatically in the code editor. The class provides a basic skeleton of all the methods defined in the service interface.
  3. To implement the logic to do the transformation between the business object and the XML string, copy the code in Listing 4 to the class ContactComponentImpl.
    Listing 4. Sample Java code for transformation between business object and XML string
    /**
     * Serialize data object to xml string.
     */
    public String dataObjectToString(DataObject dataObject) {
    	ByteArrayOutputStream baos = new ByteArrayOutputStream();
    	try {
    		xmlSerializerService.writeDataObject(dataObject, 
            "namespace","ROOT", baos);
    	} catch (IOException e) {
    		e.printStackTrace();
    	}
    	return baos.toString();
    }
    
    /**
     * Deserialize xml string to data object.
     */
    public DataObject stringToDataObject(String string) {
    	ByteArrayInputStream bais = 
    		new ByteArrayInputStream(string.getBytes());
    	BOXMLDocument boxmldoc;
    	try {
    		boxmldoc = xmlSerializerService.readXMLDocument(bais);
    		return boxmldoc.getDataObject();
    	} catch (IOException e) {
    		e.printStackTrace();
    	}
    	return null;
    }
    
    private static BOXMLSerializer xmlSerializerService = 
     (BOXMLSerializer) new ServiceManager()
    	.locateService("com/ibm/websphere/bo/BOXMLSerializer");
  4. To implement the methods saveContact and queryContactByName, add the logic as shown in Listing 5.
    Listing 5. Sample implementation of methods saveContact and queryContactByName
    public Integer saveContact(DataObject contact) {
    	Service service = locateService_ContactDBServicePartner();
    	// Get the input of the partner service.
    	DataObject input = boFactory.createByType(service.getReference()
    			.getOperationType("saveContact").getInputType());
    	input.setString("contactdoc", dataObjectToString(contact));
    	// Invoke the partner service and get output.
    	DataObject output = (DataObject)service
    			.invoke("saveContact",input);
    	return output.getInt("updateCount");
    }
    
    public DataObject queryContactByName(String firstName, String lastName) {
    	Service service = locateService_ContactDBServicePartner();
    	DataObject input = boFactory.createByType(service.getReference()
    			.getOperationType("queryContactByName")
    			.getInputType());
    	input.setString("firstName", firstName);
    	input.setString("lastName", lastName);
    	DataObject output = (DataObject)service
    			.invoke("queryContactByName", input);
    	DataObject row = (DataObject)output.getList("row").get(0);
    	return stringToDataObject(row.getString("CONTACT"));
    }

Test the sample application in WebSphere Integration Developer

To test the sample application in WebSphere Integration Developer using the Universal Test Environment:

  1. To start the server, in the view of Servers, right-click WebSphere Process Server v7.0 at localhost and select Start from the pop-up menu.
  2. To start testing of the module, right-click ContactModule and select Test > Test Module from the pop-up menu, as shown in Figure 16.
    Figure 16. Test module
    Test module
  3. The Integration Test Client appears. It lists all the component services and corresponding service operations defined in the module. There are two operations, saveContact and queryContactByName in ContactService. You can select any one of them for testing. Take saveContact as an example, enter the values for each fields, and click the Continue button in the left-top bar to launch the test, as shown in Figure 17.
    Figure 17. Integration Test Client
    Integration Test Client
  4. The Deployment Location dialog appears. Select WebSphere Process Server v7.0 at localhost and then click Finish. You may be prompted to enter the username and password to logon to WebSphere Process Server.
  5. You will now see the result of the invocation. See Figure 18 to review the saved business objects as an XML document in DB2.
    Figure 18. Sample XML document of business object in DB2
    Sample XML document of business object in DB2
  6. Repeat Steps 2 to 4 to test the other service operations.

Conclusion

Service Component Architecture is widely used to build SOA systems, and the persistence of message (business object) exchanges between components can result in problems. This article introduced a solution by integrating pureXML web services with SCA components. The article also described how to develop and test the SCA component application using WebSphere Integration Developer. The provided sample applications illustrated the ease and flexibility of combining pureXML web services and SCA components.

Acknowledgements

The authors would like to thank Xiang Cheng, Pei Jian Dong, and Bian Yun Zhi for their help with this article.


Downloads

DescriptionNameSize
Code sampleContactLib.zip6KB
Code sampleContactModule.zip10KB
Code samplepureXMLWebService.zip501KB

Resources

Learn

Get products and technologies

Discuss

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 WebSphere on developerWorks


static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=WebSphere, Information Management, XML
ArticleID=502428
ArticleTitle=Using pureXML in SCA component development with WebSphere Integration Developer V7
publish-date=07282010