Integrating healthcare services, Part 2: Using Apache...

22
Integrating healthcare services, Part 2: Using Apache ServiceMix as a Healthcare Service Bus Interconnect multiple JBI servers hosting healthcare applications Skill Level: Intermediate Bilal Siddiqui ([email protected]) Consultant 08 Jun 2010 A Healthcare Service Bus (HSB) enables diverse healthcare applications to interconnect and interoperate for efficient service delivery. Part 1 of this two-part article discusses the aggregation of healthcare services using Java™ Business Integration (JBI) architecture. This concluding installment shows how you can use an open source JBI implementation — Apache ServiceMix — as an HSB. You'll configure an application as a ServiceMix-hosted internal service, learn how to interconnect multiple JBI environments, and find out how you can integrate an industry standard for healthcare interoperability into ServiceMix. By connecting various healthcare applications to a Java Business Integration (JBI) server, you can build an enterprise service bus for healthcare: a Healthcare Service Bus (HSB). Part 1 of this two-part article introduces JBI, explains its architecture, and discusses how it can be used as an HSB that aggregates services such as a prescription application, a radiology-department application, and a donor-group application. This second part demonstrates how to configure these services so that a JBI server can start acting as an HSB. I'll show you how to use Apache ServiceMix, a popular open source implementation of JBI, as an HSB. I'll start by introducing ServiceMix and one of its important components. Then I'll describe how to use that component to configure an application as an internal service hosted on Apache ServiceMix. The third section will show how to interconnect two JBI environments so that an application connected to one JBI environment can interconnect and interoperate with Using Apache ServiceMix as a Healthcare Service Bus Trademarks © Copyright IBM Corporation 2010. All rights reserved. Page 1 of 22

Transcript of Integrating healthcare services, Part 2: Using Apache...

Page 1: Integrating healthcare services, Part 2: Using Apache ...public.dhe.ibm.com/software/dw/java/j-hsb2-pdf.pdf · 6. The sixth interceptor transforms Java objects into XML format and

Integrating healthcare services, Part 2: UsingApache ServiceMix as a Healthcare Service BusInterconnect multiple JBI servers hosting healthcareapplications

Skill Level: Intermediate

Bilal Siddiqui ([email protected])Consultant

08 Jun 2010

A Healthcare Service Bus (HSB) enables diverse healthcare applications tointerconnect and interoperate for efficient service delivery. Part 1 of this two-partarticle discusses the aggregation of healthcare services using Java™ BusinessIntegration (JBI) architecture. This concluding installment shows how you can use anopen source JBI implementation — Apache ServiceMix — as an HSB. You'llconfigure an application as a ServiceMix-hosted internal service, learn how tointerconnect multiple JBI environments, and find out how you can integrate anindustry standard for healthcare interoperability into ServiceMix.

By connecting various healthcare applications to a Java Business Integration (JBI)server, you can build an enterprise service bus for healthcare: a Healthcare ServiceBus (HSB). Part 1 of this two-part article introduces JBI, explains its architecture,and discusses how it can be used as an HSB that aggregates services such as aprescription application, a radiology-department application, and a donor-groupapplication.

This second part demonstrates how to configure these services so that a JBI servercan start acting as an HSB. I'll show you how to use Apache ServiceMix, a popularopen source implementation of JBI, as an HSB. I'll start by introducing ServiceMixand one of its important components. Then I'll describe how to use that componentto configure an application as an internal service hosted on Apache ServiceMix. Thethird section will show how to interconnect two JBI environments so that anapplication connected to one JBI environment can interconnect and interoperate with

Using Apache ServiceMix as a Healthcare Service Bus Trademarks© Copyright IBM Corporation 2010. All rights reserved. Page 1 of 22

Page 2: Integrating healthcare services, Part 2: Using Apache ...public.dhe.ibm.com/software/dw/java/j-hsb2-pdf.pdf · 6. The sixth interceptor transforms Java objects into XML format and

an application connected to another JBI environment. The last section providessome tips on how to integrate the functionality of HL7 (Healthcare Level 7, a popularhealthcare standard introduced in Part 1) into JBI.

Introducing Apache ServiceMix

Apache ServiceMix can host JBI applications, such as those shown in Figures 4, 5,6, and 7 of Part 1. To implement components of the JBI environment, ServiceMixuses the popular open source Spring framework (see Resources). You use SpringXML configuration to configure services inside the JBI environment, which makes itstraightforward to specify the Java classes that need to be instantiated.

In addition to implementing the JBI specification, ServiceMix comes bundled withsome useful preconfigured components that you can use directly in your JBIapplication. Recall from the Mixing internal and external services in JBI section ofPart 1 that you need a Service Engine (SE) in order to implement an internal servicesuch as the Radiology Department application. ServiceMix provides a variety ofreusable SEs that you can use to build your internal services. For this article, you'lluse a ServiceMix SE called CXF Service Engine (CXFSE).

CXFSE is a wrapper for the open source Apache CXF Web services framework. Itlets you use the functionality of Apache CXF in a ServiceMix application. ApacheCXF allows you to build web service applications that are fully integrated withinternal business logic. CXFSE has many features that make it suitable for use inapplications such as an HSB.

Apache CXF uses the concept of interceptors to integrate a web service front end(that is, the interface defined in a Web Services Description Language [WSDL] file)with the web service's business logic. CXF provides several ready-to-useinterceptors and also allows you to add your own. An interceptor does a specific job,and you can configure a chain of interceptors to do exactly what your business logicrequires. For example, you can configure the following chain of interceptors:

1. An interceptor receives a service request from a service consumer andtransforms the request to another format.

2. Another interceptor creates Java objects from the request.

3. The third interceptor invokes the business logic and passes Java objectsalong with the invocation call.

4. Another one or few interceptors can contain the actual business logic.

5. The fifth interceptor fetches new Java objects from the business-logicapplication.

developerWorks® ibm.com/developerWorks

Using Apache ServiceMix as a Healthcare Service Bus Trademarks© Copyright IBM Corporation 2010. All rights reserved. Page 2 of 22

Page 3: Integrating healthcare services, Part 2: Using Apache ...public.dhe.ibm.com/software/dw/java/j-hsb2-pdf.pdf · 6. The sixth interceptor transforms Java objects into XML format and

6. The sixth interceptor transforms Java objects into XML format and sendsthe response back to the service consumer.

I won't discuss the details of building or configuring CXF interceptors in this article.Instead, I'll use a simple default combination of ready-made interceptors that caninvoke the Radiology Department application. To learn more about Apache CXF,see Resources.

CXFSE is a configurable wrapper, which means you can control the behavior of yourSE by writing an XML file. I'll demonstrate shortly how you can write the XMLconfiguration for CXFSE for the Radiology Department application. But first, I'llpresent a high-level plan for all the actions required to host an internal application (orservice) on ServiceMix.

Hosting the Radiology Department application as an internalservice

The procedure for hosting an internal service on ServiceMix requires severalconfigurations, which I'll break down into the following five steps:

1. Write and compile the Java class containing the business logic for theRadiology Department application, and expose the class as a webservice.

2. Configure the Java classes of the Radiology Department application inthe Spring framework, so that the framework instantiates the classes andmakes them available according to application requirements.

3. Write a WSDL interface for the Radiology Department application. TheJBI specification uses WSDL 2.0 to define the interface of servicesexposed by internal and external service providers.

4. Write the JBI configurations for the service provider (that is the RadiologyDepartment application) as well as the service consumer. (Recall thePrescription application in Figure 6 of Part 1, which is a service consumerthat sends service requests to the Radiology Department application.)

5. Package the Radiology Department application as a JBI service assemblyand copy the package into ServiceMix.

After you perform Step 5, you'll see your HSB in action by sending messages fromthe Prescription application (a service consumer) to the Radiology Departmentapplication.

ibm.com/developerWorks developerWorks®

Using Apache ServiceMix as a Healthcare Service Bus Trademarks© Copyright IBM Corporation 2010. All rights reserved. Page 3 of 22

Page 4: Integrating healthcare services, Part 2: Using Apache ...public.dhe.ibm.com/software/dw/java/j-hsb2-pdf.pdf · 6. The sixth interceptor transforms Java objects into XML format and

Now I'll describe and demonstrate each step.

Radiology Department application as a simple Java class

Listing 1 shows a simple Java class named RadiologyDepartment, which hasjust one method, named performTest():

Listing 1. The RadiologyDepartment class

package com.hsb;

import javax.jws.WebService;import javax.xml.ws.Holder;

import com.hsb.Radiology;

@WebService(serviceName="RadiologyService",targetNamespace="http://hsb.org/radiology-department",endpointInterface="com.hsb.Radiology")

public class RadiologyDepartment implements Radiology {

public void performTest (Holder<String> testDetails, Holder<String> testResults){

System.out.println ("RadiologyDepartment.performTest()- > TestDetails:"+testDetails.value);

System.out.println ("RadiologyDepartment.performTest()- > TestResults:"+testResults.value);

}}

The performTest() method takes two parameters: testDetails andtestResults. As you can see, they are of type Holder <String>. Holder is aclass defined by the Java API for XML-Based Web Services (JAX-WS). CXFSEuses JAX-WS, so it is convenient to use an instance of this class to exchangeinformation with your Java class. The Holder class has methods for inserting datainto and fetching data from its instance. The CXF framework internally populatesdata from the XML request message into the Holder object and passes the Holderobject to the Java class of the Radiology Department application.

I have left the performTest() method empty (except for a few System.outstatements), strictly for brevity. In an actual application, the performTest()method would be hooked into the Radiology Department application's businesslogic.

You need to compile the RadiologyDepartment class. This article's downloadcontains a folder named sample1\RadiologyService, where you'll find both the codefor the RadiologyDepartment class and a compiled form of the class.

You also need to generate Java API for XML Binding (JAXB) files corresponding tothe RadiologyDepartment class. These JAXB files are used by the JAX-WS API,

developerWorks® ibm.com/developerWorks

Using Apache ServiceMix as a Healthcare Service Bus Trademarks© Copyright IBM Corporation 2010. All rights reserved. Page 4 of 22

Page 5: Integrating healthcare services, Part 2: Using Apache ...public.dhe.ibm.com/software/dw/java/j-hsb2-pdf.pdf · 6. The sixth interceptor transforms Java objects into XML format and

so Apache CXF needs them in order to expose your RadiologyDepartment classas a web service. You can use a handy tool named wsgen to generate all therequired files from your RadiologyDepartment class. You'll find wsgen in the..\jdk1.6.0_12\bin folder of your JDK1.6 installation. (See Resources to learn moreabout the wsgen tool.)

For this article's purposes, I've provided a ws.bat file in the download. You can justrun ws.bat to generate the required JAXB files. You can also find these files in bothsource and compiled form in the sample1\RadiologyService folder.

Configuring the RadiologyDepartment class in the Spring framework

Listing 2 shows the Spring XML configuration file for the RadiologyDepartmentclass:

Listing 2. Spring XML configuration for the Radiology Department service

<?xml version="1.0" encoding="UTF-8"?><beans xmlns:cxfse="http://servicemix.apache.org/cxfse/1.0">

<cxfse:endpoint><cxfse:pojo><bean class="com.hsb.RadiologyDepartment" />

</cxfse:pojo></cxfse:endpoint>

</beans>

Note that the root tag in Listing 2 is <beans>, which is part of Spring's XMLnamespace. The <beans> tag's purpose is to hold the different Java beans (orinstances of Java classes) of your application. You configure yourapplication-specific Java beans inside the <beans> tag. Spring handles instantiationof Java classes and makes the classes available to the application that needs to usethem. You needn't worry about who will instantiate your Java classes and how theinstances will become available to one another. This all is Spring's headache. Youjust write the classes and configure them in Spring.

The <beans> tag in Listing 2 contains the namespace declaration for ahttp://servicemix.apache.org/cxfse/1.0 namespace. ServiceMix definesthis namespace, the purpose of which is to specify the behavior of CXFSE accordingto your application requirements. I'll refer to this namespace as the cxfsenamespace.

The cxfse namespace contains tags to specify exactly what you want to useCXFSE for. Several options are available. You can see from Listing 2 that the root<beans> tag contains an <endpoint> tag that belongs to the cxfse namespace.The <endpoint> tag is the start or an end of a communication channel.

To get a full understanding of what an endpoint is, you can refer back to Figure 6 of

ibm.com/developerWorks developerWorks®

Using Apache ServiceMix as a Healthcare Service Bus Trademarks© Copyright IBM Corporation 2010. All rights reserved. Page 5 of 22

Page 6: Integrating healthcare services, Part 2: Using Apache ...public.dhe.ibm.com/software/dw/java/j-hsb2-pdf.pdf · 6. The sixth interceptor transforms Java objects into XML format and

Part 1, in which the Prescription application sends a message to the RadiologyDepartment application. The Prescription application and the Radiology Departmentapplication are the endpoints. The message originates from the Prescriptionapplication, goes through various components of the JBI environment — such as aBinding Component (BC), the Normalized Message Router (NMR), and an SE —and eventually ends up at the Radiology Department application.

You are configuring the Radiology Department application in Listing 2, so you use an<endpoint> tag directly inside a <beans> tag. This tells ServiceMix that you areconfiguring an endpoint.

Endpoints can be of several types. For example, an endpoint can be a chain ofinterceptors doing several jobs in a sequence (such as the chain of interceptors thatyou saw in the Introducing Apache ServiceMix section). But for the sake ofsimplicity, I am using a simple Java class (the RadiologyDepartment class) inthis article. An instance of a simple Java class is commonly referred as a Plain OldJava Object (POJO). The cxfse namespace contains a tag named <pojo>, whichsits inside an <endpoint> tag to specify that this endpoint is just an instance of asimple Java class.

Finally in Listing 2, you can see a <bean> tag, which is part of Spring's namespaceand specifies the bean (instance of a Java class) that will act as the endpoint. The<bean> tag has an attribute named class, which specifies the fully qualified nameof the class (namely, com.hsb.RadiologyDepartment) whose instance will bethe endpoint.

You'll find the Spring XML configuration file shown in Listing 2 as the xbean.xml filein the sample1\RadiologyService\ folder of the download.

Writing the WSDL file for the radiology application

Listing 3 shows the WSDL interface for the Radiology Department application:

Listing 3. WSDL interface for the Radiology Department application

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><definitions targetNamespace="http://hsb.com/" xmlns="http://schemas.xmlsoap.org/wsdl/"xmlns:tns="http://hsb.com/"xmlns:xsd="http://www.w3.org/2001/XMLSchema"><types>

<xsd:schema><xsd:import namespace="http://hsb.com/"

schemaLocation="Radiology_schema1.xsd"/></xsd:schema>

</types><message name="performTest">

<part name="parameters" element="tns:performTest"/></message><message name="performTestResponse">

<part name="parameters" element="tns:performTestResponse"/></message>

developerWorks® ibm.com/developerWorks

Using Apache ServiceMix as a Healthcare Service Bus Trademarks© Copyright IBM Corporation 2010. All rights reserved. Page 6 of 22

Page 7: Integrating healthcare services, Part 2: Using Apache ...public.dhe.ibm.com/software/dw/java/j-hsb2-pdf.pdf · 6. The sixth interceptor transforms Java objects into XML format and

<portType name="Radiology"><operation name="performTest"><input message="tns:performTest"/><output message="tns:performTestResponse"/>

</operation></portType>

</definitions>

Listing 4 shows the WSDL binding for the Radiology Department application:

Listing 4. WSDL binding for the Radiology Department application

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><definitions targetNamespace="http://hsb.org/radiology-department"

name="RadiologyService"xmlns="http://schemas.xmlsoap.org/wsdl/"xmlns:tns="http://hsb.org/radiology-department"xmlns:xsd="http://www.w3.org/2001/XMLSchema"xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">

<import namespace="http://hsb.com/" location="Radiology.wsdl"/><binding name="RadiologyDepartmentPortBinding"

type="ns1:Radiology" xmlns:ns1="http://hsb.com/"><soap:binding transport="http://schemas.xmlsoap.org/soap/http"

style="document"/><operation name="performTest"><soap:operation soapAction=""/><input>

<soap:body use="literal"/></input><output>

<soap:body use="literal"/></output>

</operation></binding><service name="RadiologyService">

<port name="RadiologyDepartmentPort"binding="tns:RadiologyDepartmentPortBinding">

<soap:address location="http://localhost:8092/RadiologyService/ "/></port>

</service></definitions>

You can see that the web service is simple; it just contains an operation namedperformTest with a couple of parameters. WSDL interface and binding details arebeyond this article's scope. See Resources for the link to a developerWorks articlethat explains WSDL in detail.

In the download's sample1\RadiologyService folder, you'll find the WSDL files shownin Listing 3 and Listing 4 as Radiology.wsdl and RadiologyService.wsdl, respectively.

Packaging the Radiology Department application

You now need to package the RadiologyDepartment class and accompanyingJAXB classes, Spring's xbean.xml, and the WSDL files for the RadiologyDepartment application into a .zip file named RadiologyService.zip. You'll find allthese files in the sample1\RadiologyService\ folder of the download. I have already

ibm.com/developerWorks developerWorks®

Using Apache ServiceMix as a Healthcare Service Bus Trademarks© Copyright IBM Corporation 2010. All rights reserved. Page 7 of 22

Page 8: Integrating healthcare services, Part 2: Using Apache ...public.dhe.ibm.com/software/dw/java/j-hsb2-pdf.pdf · 6. The sixth interceptor transforms Java objects into XML format and

prepared the .zip file for you; it's in the sample1\ folder.

Configuring and packaging a service consumer

You have packaged your radiology application, which is a service provider. But youcan't run this application unless you have a service consumer configured in a JBIserver.

Configuring a service consumer in JBI is quite similar to building the providerconfiguration you just saw. You need to write the Spring XML configuration and theWSDL file for the consumer endpoint.

The Spring XML configuration for your service consumer is shown in Listing 5:

Listing 5. XML configuration for a service consumer

<?xml version="1.0" encoding="UTF-8"?><beans xmlns:cxfbc="http://servicemix.apache.org/cxfbc/1.0"

xmlns:radiology="http://hsb.org/radiology-department"><cxfbc:consumer wsdl="classpath:RadiologyService.wsdl"

targetService="radiology:RadiologyService" /></beans>

You can see that Listing 5 is very similar to Listing 2. Listing 5 uses a cxfbcnamespace instead of the cxfse namespace you see in Listing 2. You use a cxfbcnamespace here because the consumer requires a BC rather than an SE. You canrefer back to the six steps accompanying Figure 6 of Part 1, in which you can seethat Prescription application (a service consumer) requires a BC, and the RadiologyDepartment application (an internal service provider) requires an SE. ServiceMixprovides both SE and BC namespaces for CXF applications, allowing you fullflexibility in configuring your application in the way you want.

The WSDL files for the service consumer are very similar to the WSDL files in Listing3 and Listing 4. You'll find these consumer configurations in thesample1\PrescriptionService folder in the download.

You also need to package the Spring's XML configuration and WSDL files for theconsumer into a .zip file named PrescriptionService.zip. I have already done this foryou. Look for PrescriptionService.zip in the download's sample1\ folder.

Assembling the radiology application together with the prescriptionapplication

You have already configured two service units, one for the Radiology Departmentapplication (service provider) and the other for the Prescription application (serviceconsumer). Now you'll assemble the service units into a JBI service assembly.

developerWorks® ibm.com/developerWorks

Using Apache ServiceMix as a Healthcare Service Bus Trademarks© Copyright IBM Corporation 2010. All rights reserved. Page 8 of 22

Page 9: Integrating healthcare services, Part 2: Using Apache ...public.dhe.ibm.com/software/dw/java/j-hsb2-pdf.pdf · 6. The sixth interceptor transforms Java objects into XML format and

To create the service assembly, you just need to write a JBI XML configuration, asshown in Listing 6:

Listing 6. JBI's XML configuration for the Radiology Department applicationservice assembly

<?xml version="1.0" encoding="UTF-8"?><jbi xmlns="http://java.sun.com/xml/ns/jbi" version="1.0"><service-assembly>

<identification><name>radiology-service-assembly</name><description>Radiology Department Service Assembly</description>

</identification><service-unit><identification>

<name>radiology-service</name><description>Radiology Department Service Provider</description>

</identification><target>

<artifacts-zip>RadiologyService.zip</artifacts-zip><component-name>servicemix-cxf-se</component-name>

</target></service-unit><service-unit><identification>

<name>prescription-service</name><description> Prescription Service Consumer</description>

</identification><target>

<artifacts-zip>PrescriptionService.zip</artifacts-zip><component-name>servicemix-cxf-bc</component-name>

</target></service-unit>

</service-assembly></jbi>

The root tag in Listing 6, named <jbi>, belongs to the JBI namespace(http://java.sun.com/xml/ns/jbi). The <jbi> tag contains one childnamed <service-assembly>, which wraps the name and description of the JBIservice being deployed as well as the various service units in the service assembly.

The <service-assembly> tag has two <service-unit> child tags. Each<service-unit> child represents an individual unit of the service. You areconfiguring only a Radiology Department application and a Prescription application,so your service assembly contains only two <service-unit> tags, one for eachapplication.

Each <service-unit> tag wraps the name of the unit, its description, and the ZIPfile of the service unit. You can see that the <artifacts-zip> tag inside each<service-unit> tag contains the name of a ZIP file; they match the filenames forthe two .zip files you created at the end of the Packaging the Radiology Departmentapplication and Configuring and packaging a service consumer sections. TheRadiologyService.zip file is for the Radiology Department application, andPrescriptionService.zip file is for the Prescription application.

ibm.com/developerWorks developerWorks®

Using Apache ServiceMix as a Healthcare Service Bus Trademarks© Copyright IBM Corporation 2010. All rights reserved. Page 9 of 22

Page 10: Integrating healthcare services, Part 2: Using Apache ...public.dhe.ibm.com/software/dw/java/j-hsb2-pdf.pdf · 6. The sixth interceptor transforms Java objects into XML format and

You need to save the configuration in Listing 6 as an XML file named jbi.xml. I havedone this for you, and you can find the file in the download's META-INF\ folder.Finally, package the META-INF\ folder and the two .zip files intoRadiologyAssembly.zip. I have prepared RadiologyAssembly.zip for you; it's in thesample1\ folder of the download.

RadiologyAssembly.zip is the final ZIP file, which contains everything you have doneso far.

Tips for developing ServiceMix applicationsThis article's download includes a Tips.txt file, which provides someuseful tips on:

• Enabling the debugging trace for ServiceMix

• Clearing the ServiceMix cache

• Redeploying a ServiceMix component

You don't need these tips to run this article's sample application, butthey'll be helpful for developing your own ServiceMix applications.

Testing the Radiology Department service

Perform the following steps to test the Radiology Department application:

1. Download and install Apache ServiceMix 3.3.1 on your computer (seeResources).

2. Start ServiceMix by double-clicking on the servicemix.bat file, which you'llfind in the ..\apache-servicemix-3.3.1\bin folder of your ServiceMixinstallation. Wait a few moments for the server to start its services.

3. Copy RadiologyAssembly.zip from the sample1\ folder into the..\apache-servicemix-3.3.1\hotdeploy folder of your ServiceMixinstallation. As soon as you copy the .zip file, ServiceMix will detect that anew application is being deployed. It will start the deployment process,which you'll see on the output console of ServiceMix. Wait for thedeployment to complete.

ServiceMix provides a simple browser-based SOAP client that you can use to testyour ServiceMix applications. This client accompanies several sample applicationsthat come bundled with ServiceMix. You can find it in the form of the client.html filein the ServiceMix installation's ..\apache-servicemix-3.3.1\examples\cxf-wsdl-firstfolder.

Open the client.html file in your browser and type

developerWorks® ibm.com/developerWorks

Using Apache ServiceMix as a Healthcare Service Bus Trademarks© Copyright IBM Corporation 2010. All rights reserved. Page 10 of 22

Page 11: Integrating healthcare services, Part 2: Using Apache ...public.dhe.ibm.com/software/dw/java/j-hsb2-pdf.pdf · 6. The sixth interceptor transforms Java objects into XML format and

http://localhost:8092/RadiologyService in the Target field of the HTMLpage. Then type the SOAP request shown in Listing 7 into the text box just belowthe Target field:

Listing 7. Request SOAP message to test your radiology application

<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"

xmlns:hsb="http://hsb.com/"><soapenv:Header/><soapenv:Body>

<hsb:performTest><arg0>Test1</arg0><arg1>Test2</arg1>

</hsb:performTest></soapenv:Body>

</soapenv:Envelope>

I have provided this SOAP request message as SOAPRequest.txt file in thedownload. You can copy the SOAP request from the SOAPRequest.txt file andpaste into the text box below the Target field. After you enter the address and theSOAP request, the client.html page will look like Figure 1:

Figure 1. The client.html page

ibm.com/developerWorks developerWorks®

Using Apache ServiceMix as a Healthcare Service Bus Trademarks© Copyright IBM Corporation 2010. All rights reserved. Page 11 of 22

Page 12: Integrating healthcare services, Part 2: Using Apache ...public.dhe.ibm.com/software/dw/java/j-hsb2-pdf.pdf · 6. The sixth interceptor transforms Java objects into XML format and

Now click the Send button at the bottom of the page and wait for a few moments.The service consumer of the Radiology Department application receives the request,routes it to the NMR, and then through CXFSE engine to theRadiologyDepartment class. The RadiologyDepartment class then responds.The response travels all the way through back to the SOAP client. You can see theresponse in its text box opposite the request text box, as shown in Figure 2:

developerWorks® ibm.com/developerWorks

Using Apache ServiceMix as a Healthcare Service Bus Trademarks© Copyright IBM Corporation 2010. All rights reserved. Page 12 of 22

Page 13: Integrating healthcare services, Part 2: Using Apache ...public.dhe.ibm.com/software/dw/java/j-hsb2-pdf.pdf · 6. The sixth interceptor transforms Java objects into XML format and

Figure 2. Response shown in your SOAP client

Interconnecting JBI servers

You have seen how you can configure the Radiology Department application as aninternal service provider and invoke it from an external service consumer. Now I willdemonstrate how you can configure two JBI servers so that a service consumerconnected to one JBI server can invoke the services offered by a service providerconnected to another JBI server. This situation is similar to Figure 7 from Part 1,where I discuss the interconnection of JBI servers.

Compare Figures 4 and 7 from Part 1. Figure 4 shows a service consumer and anexternal service provider connected to one JBI server. Figure 7 shows a serviceconsumer connected to one JBI and the provider connected to another JBI server,while the two JBI servers are interconnected to each other.

From JBI's point of view, the two situations are the same. If a service is external to aJBI environment, it doesn't matter whether the external service is directly connectedto the JBI server or it is connected indirectly through another JBI server. This meansthe JBI configuration that you do according to Figure 7 of Part 1 will also work fine incase you want to connect your healthcare providers according to Figure 4 of Part 1.So I'll show only the scenario of Figure 7 in this article and leave the scenario ofFigure 4 to you.

In this section, you need two JBI servers. The first server has a service consumerand an external service provider. The second JBI server has an internal service

ibm.com/developerWorks developerWorks®

Using Apache ServiceMix as a Healthcare Service Bus Trademarks© Copyright IBM Corporation 2010. All rights reserved. Page 13 of 22

Page 14: Integrating healthcare services, Part 2: Using Apache ...public.dhe.ibm.com/software/dw/java/j-hsb2-pdf.pdf · 6. The sixth interceptor transforms Java objects into XML format and

provider. This is shown in Figure 3:

Figure 3. Two JBI servers, one with an external service consumer and anotherwith an internal service provider

The first JBI server will think that the second JBI server is the external service. Thesecond JBI server will think that the first JBI server is a service consumer.

This means you can simply use the configuration of the Radiology Departmentapplication as the second JBI server. All you need to do is to configure an externalservice provider and a consumer in the first JBI server.

Configuring an external service provider simply means telling the first JBI server thatthe second is a web service. You need to do just two things: write a Spring XMLconfiguration file similar to Listings 2 and 5, and WSDL files similar to Listing 3 and4.

Configuring an external service provider for the first JBI server

Listing 8 contains the Spring configuration for an external service provider:

Listing 8. Spring configuration for an external service provider

<?xml version="1.0" encoding="UTF-8"?><beans xmlns:cxfbc="http://servicemix.apache.org/cxfbc/1.0"

xmlns:radiology="http://hsb.org/radiology-department"><cxfbc:provider

service="radiology:RadiologyService"endpoint="RadiologyService"locationURI="http://192.168.10.33:8092/RadiologyService/"wsdl="classpath:RadiologyService.wsdl" />

</beans>

You can see that the <beans> tag in Listing 8 contains the same cxfbc namespacedeclaration that you saw in Listing 5. That's because here in Listing 8, you areconfiguring an external service provider, whereas in Listing 5 you configured anexternal service consumer. Whenever you are configuring an external application(whether a provider of a consumer), you use the cxfbc namespace.

developerWorks® ibm.com/developerWorks

Using Apache ServiceMix as a Healthcare Service Bus Trademarks© Copyright IBM Corporation 2010. All rights reserved. Page 14 of 22

Page 15: Integrating healthcare services, Part 2: Using Apache ...public.dhe.ibm.com/software/dw/java/j-hsb2-pdf.pdf · 6. The sixth interceptor transforms Java objects into XML format and

Also notice that Listing 8 contains a <provider> tag from the cxfbc namespace(just like the <consumer> tag of Listing 5). The <provider> tag has variousattributes that specify details of the external service:

• service: Name of the radiology service provider that is hosted on thesecond JBI server.

• endpoint: WSDL port of the Radiology Department application that islistening for service requests.

• locationURI: Network address of the Radiology Department service.This network address exists on the second JBI server. When I tried thisapplication, my second JBI server was running on a machine whosenetwork address was 192.168.10.33 and the port of second JBI serverwas 8092.

• wsdl: Name and location of the WSDL file. ServiceMix resolves theclasspath to the root of the ZIP file for a service. You can see from thisarticle's download that the WSDL exists in thesampl2\JBI1\RemoteRadiologyService folder. The contents of theRemoteRadiologyService folder form the root of the ZIP file for thisapplication. Therefore, I have simply writtenclasspath:RadiologyService.wsdl as the value of the wsdlattribute.

The WSDL file for this provider service is the same as the WSDL files shown inListing 3 and 4. You'll find Listing 8 as xbean.xml and its accompanying WSDL asRadiologyService.wsdl in the sample2\JBI1\RemoteRadiologyService folder of thedownload. You need to package all the contents of the RemoteRadiologyServicefolder in a .zip file named RemoteRadiologyService.zip. I have already prepared the.zip file for you; you'll find it in the sample2\JBI1 folder.

Configuring a service consumer for the first JBI server

Configuration for a service consumer for the first JBI server is exactly the same asthe configuration you did in Listing 5, so I won't repeat the listing here. You'll find thisconsumer configuration as the xbean.xml file in thesample2\JBI1\PrescriptionService folder.

You also need a WSDL file that accompanies the consumer configuration. It is verysimilar to the WSDL file in Listing 3. You'll find the WSDL file in thesample2\JBI1\PrescriptionService folder. I have also packaged the contents of thePrescriptionService folder into PrescriptionService.zip.

Assembling the provider and consumer for the first JBI server

The two .zip files for the first JBI server are ready. The last step is to assemble the

ibm.com/developerWorks developerWorks®

Using Apache ServiceMix as a Healthcare Service Bus Trademarks© Copyright IBM Corporation 2010. All rights reserved. Page 15 of 22

Page 16: Integrating healthcare services, Part 2: Using Apache ...public.dhe.ibm.com/software/dw/java/j-hsb2-pdf.pdf · 6. The sixth interceptor transforms Java objects into XML format and

.zip files into a service assembly. The JBI configuration file for the completeassembly is shown in Listing 9:

Listing 9. JBI configuration for the complete assembly of the first JBI server

<?xml version="1.0" encoding="UTF-8"?><jbi xmlns="http://java.sun.com/xml/ns/jbi" version="1.0"><service-assembly>

<identification><name>remote-radiology-service-assembly</name><description>Radiology Department Service Assembly</description>

</identification><service-unit><identification>

<name>remote-radiology-service</name><description>Radiology Department Service Provider</description>

</identification><target>

<artifacts-zip>RemoteRadiologyService.zip</artifacts-zip><component-name>servicemix-cxf-bc</component-name>

</target></service-unit><service-unit><identification>

<name>remote-prescription-service</name><description>Prescription Service Consumer</description>

</identification><target>

<artifacts-zip>PrescriptionService.zip</artifacts-zip><component-name>servicemix-cxf-bc</component-name>

</target></service-unit>

</service-assembly></jbi>

You can see that the JBI assembly file of Listing 9 is very similar to Listing 6. You'llfind this JBI configuration in Listing 9 as jbi.xml in the sample2\JBI1\META-INFfolder of the download.

Finally, you need to package jbi.xml along with RemoteRadiologyService.zip andPrescriptionService.zip files into another .zip file calledRemoteRadiologyAssembly.zip. I have prepared this file for you; you'll find it in thesample2\JBI1 folder.

Testing the interconnection of JBI servers

In order to test the interconnection of JBI servers, you'll run the sameRadiologyAssembly application that you saw in the Testing the RadiologyDepartment service section. This will act as your second JBI server.

When I tried this JBI interconnection, my second JBI server was running on amachine whose local network address was 192.168.10.33. As you can guess, theprovider of the first JBI server should know the network address of the second JBIserver. Therefore, this network address occurs at two places in your configuration

developerWorks® ibm.com/developerWorks

Using Apache ServiceMix as a Healthcare Service Bus Trademarks© Copyright IBM Corporation 2010. All rights reserved. Page 16 of 22

Page 17: Integrating healthcare services, Part 2: Using Apache ...public.dhe.ibm.com/software/dw/java/j-hsb2-pdf.pdf · 6. The sixth interceptor transforms Java objects into XML format and

files for the provider of the first JBI server:

• The locationURI attribute in the xbean.xml file

• The address attribute of the <soap> tag in the RadiologyService.wsdlfile

If you are running the second JBI server from a different address, you must makethe appropriate changes in these two places.

To run the first JBI server, perform these steps:

1. Install Apache ServiceMix 3.3.1 on a separate machine. I tried theinterconnection of JBI servers using two machines, one for the first JBIserver and the other for the second JBI server.

2. Start ServiceMix by double-clicking on the servicemix.bat file in the..\apache-servicemix-3.3.1\bin folder of your ServiceMix installation. Waita few moments for the server to start its services.

3. Copy RemoteRadiologyAssembly.zip from the sample2\JBI1 folder intothe ..\apache-servicemix-3.3.1\hotdeploy folder of your ServiceMixinstallation. As soon as you copy the file, ServiceMix will detect that a newapplication is being deployed and start the deployment process, whichyou'll see on the output console of ServiceMix. Wait for the deployment tocomplete.

4. Open the same client.html file that you used earlier while testing theRadiology Department application in your browser. Typehttp://localhost:8092/RadiologyService in the Target field ofthe HTML page. Then type the same SOAP request from Listing 7 intothe text box below the Target field.

5. Click the Send button and wait for a few moments. The request will go tothe first JBI server, travel through its consumer BC, NMR, provider BC,and then to the second JBI server. The consumer BC in the second JBIserver will receive the request, route it through the NMR, then to CXFSE,and eventually to the RadiologyDepartment class, which will respond.The response will travel all the way through the two JBI servers back toyour browser, which will display the response in its text box opposite therequest text box.

Integrating industry-specific standards into ServiceMix

You have seen how to integrate a variety of services into ServiceMix. The service I

ibm.com/developerWorks developerWorks®

Using Apache ServiceMix as a Healthcare Service Bus Trademarks© Copyright IBM Corporation 2010. All rights reserved. Page 17 of 22

Page 18: Integrating healthcare services, Part 2: Using Apache ...public.dhe.ibm.com/software/dw/java/j-hsb2-pdf.pdf · 6. The sixth interceptor transforms Java objects into XML format and

used as an example in this article (the Radiology Department application service) isbased on WSDL. However, as I explained in the XML for interoperable healthcaresection of Part 1, not all services are based on WSDL. They can also be based onindustry-specific standards such as HL7. Whenever you want to integrate a serviceinto JBI, you need a JBI component, whether the service is WSDL-based orindustry-specific.

As a general standard commonly used for defining service interfaces, WSDL can beused across all industries. This is why you'll find many implementations based onWSDL that can be integrated into ServiceMix, and why ServiceMix comes bundledwith Apache CXF. This is not the case with HL7. Support for HL7 is not available inServiceMix at the time of this writing, although the ServiceMix web site hasannounced that the project will integrate HL7 support into ServiceMix sometime inthe future.

You are likely to encounter the problem of integrating industry-specific standards intoServiceMix. So here I will outline a high-level plan for building your own componentsthat can work within ServiceMix.

Whenever you are integrating a component into ServiceMix, you need to control theway it responds to service requests from consumers. ServiceMix has definedinterfaces that allow you to control the behavior of an industry-specific JBIcomponent exactly the way you want:

ServiceMix flexibilityServiceMix provides several interfaces that you can use toimplement your own components' functionality:

• Component

• ComponentContext

• ComponentLifeCycle

• ServiceUnitManager

• InstallationContext

• Bootstrap

See Resources for a link to the official ServiceMix documentation,where you'll find details of these interfaces.

• You can control what your component will do when it is installed. Forexample, you can create database tables during installation so that thecomponent can store application data.

• Similarly, ServiceMix allows you to write the uninstallation code thatundoes or cleans up the things that your component did during

developerWorks® ibm.com/developerWorks

Using Apache ServiceMix as a Healthcare Service Bus Trademarks© Copyright IBM Corporation 2010. All rights reserved. Page 18 of 22

Page 19: Integrating healthcare services, Part 2: Using Apache ...public.dhe.ibm.com/software/dw/java/j-hsb2-pdf.pdf · 6. The sixth interceptor transforms Java objects into XML format and

installation.

• You can implement methods of ServiceMix interfaces to control thestarting and stopping of a component. Starting a component means thecomponent becomes ready to receive messages; stopping means theopposite.

• A ServiceMix interface enables your component to learn and interact withits environment (that is, the JBI environment). For example, you can writecode that tells which communication objects will be used to exchangemessages with your component via the NMR.

Perhaps the most efficient strategy for integrating HL7 support into ServiceMix is touse an open source HL7 implementation as your starting point. One such product,called HAPI (HL7 Application Programming Interface), is already available (seeResources). You can design a lightweight wrapper for HAPI and implement theServiceMix interfaces in your wrapper.

ibm.com/developerWorks developerWorks®

Using Apache ServiceMix as a Healthcare Service Bus Trademarks© Copyright IBM Corporation 2010. All rights reserved. Page 19 of 22

Page 20: Integrating healthcare services, Part 2: Using Apache ...public.dhe.ibm.com/software/dw/java/j-hsb2-pdf.pdf · 6. The sixth interceptor transforms Java objects into XML format and

Downloads

Description Name Size Downloadmethod

Sample code for this article j-hsb2.zip 232KB HTTP

Information about download methods

developerWorks® ibm.com/developerWorks

Using Apache ServiceMix as a Healthcare Service Bus Trademarks© Copyright IBM Corporation 2010. All rights reserved. Page 20 of 22

Page 21: Integrating healthcare services, Part 2: Using Apache ...public.dhe.ibm.com/software/dw/java/j-hsb2-pdf.pdf · 6. The sixth interceptor transforms Java objects into XML format and

Resources

Learn

• JBI: Get the Java Business Integration specification from the Java CommunityProcess site.

• Apache ServiceMix documentation: Learn more about ServiceMix, an agileopen source ESB.

• Apache CXF: Check out the CXF service framework.

• Spring framework: Apache ServiceMix comes bundled with Spring, a popularplatform for building and running enterprise Java applications. Spring is installedautomatically when you install ServiceMix.

• HL7: Learn about standards for interoperability of health information technology.

• "Deploying Web services with WSDL, Part 2: Simple Object Access Protocol(SOAP)" (Bilal Siddiqui, developerWorks, March 2002): Read a thoroughdiscussion of the SOAP protocol and its syntax.

• "Describe REST Web services with WSDL 2.0" (Lawrence Mandel,developerWorks, May 2008): Learn how to describe your web services usingWSDL 2.0.

• Java API for XML-Based Web Services (JAX-WS): Visit the JAX-WS projectpage to learn about developing SOAP-based Java web services with JAX-WS.

• wsgen: Learn more about the wsgen tool.

• "Design and develop JAX-WS 2.0 Web services" (Naveen Balani and RajeevHathi, developerWorks, September 2007): Check out this tutorial on developingand deploying web services using JAX-WS.

• Browse the technology bookstore for books on these and other technical topics.

• developerWorks Java technology zone: Find hundreds of articles about everyaspect of Java programming.

Get products and technologies

• Apache ServiceMix: Download ServiceMix.

• HAPI: Download and try this open source HL7 implementation.

Discuss

• Get involved in the My developerWorks community.

ibm.com/developerWorks developerWorks®

Using Apache ServiceMix as a Healthcare Service Bus Trademarks© Copyright IBM Corporation 2010. All rights reserved. Page 21 of 22

Page 22: Integrating healthcare services, Part 2: Using Apache ...public.dhe.ibm.com/software/dw/java/j-hsb2-pdf.pdf · 6. The sixth interceptor transforms Java objects into XML format and

About the author

Bilal SiddiquiBilal Siddiqui is an electronics engineer, an XML consultant, and theco-founder of WaxSys, a company focused on simplifying e-business.After graduating in 1995 with a degree in electronics engineering fromthe University of Engineering and Technology, Lahore, Pakistan, hebegan designing software solutions for industrial control systems. Later,he turned to XML and used his experience programming in C++ to buildWeb- and WAP-based XML processing tools, server-side parsingsolutions, and service applications. Bilal is a technology evangelist anda frequently published technical author.

Trademarks

Java and all Java-based trademarks are trademarks of Sun Microsystems, Inc. in theUnited States, other countries, or both.

developerWorks® ibm.com/developerWorks

Using Apache ServiceMix as a Healthcare Service Bus Trademarks© Copyright IBM Corporation 2010. All rights reserved. Page 22 of 22