## Multi-lingual Headline News Service

#### Try it out

#### Introduction

This is a web service that, given a language preference, looks up the latest news from Yahoo! and displays it in the language of choice. So what's so special about it?

The key is that this web service has been developed as a composition of other web services, using the recently released Business Process Execution Language for Web Services (BPEL4WS) specification. Stated simply, BPEL4WS is a new standard for composing Web services and exposing such compositions as Web services. For introductions to the BPEL4WS language, take a look at the references section of this document. This example makes use of two Web services available at xmethods.com. The first is the Headline News service, available from SQLData, and the second is the BabelFish service, available from XMethods.

#### Basics

The basic idea behind the example is that we would like to combine the functionality of these two service to create a composite service that provides the latest news in a language of the user's choosing. To do this, we write a BPEL4WS process, describing how we receive the input parameter (language preference) from the user, invoke the news service to get the latest news, then use BabelFish to translate this into the language of choice. One complication here is that the Headline News service delivers the news as HTML text, while BabelFish translates plain English text. So we wrote a utility java class that strips off HTML tags from text input. We then invoke this class to convert HTML-ized text into plain English text. The output of this invocation is fed to BabelFish, and the result obtained from BabelFish is returned to the user of our composite Web service. The flow of data and control is illustrated below. The entire process is offered to the user as a Web service with a single operation, getNews, that takes a language preference as input and returns the translated news as output.

#### Interesting points demonstrated

There are two points worth highlighting:

1. A BPEL4WS process uses services through their abstract interface, independent of binding and endpoint information. This means that when we write our composite service, we don't care about how the services it uses are implemented.
2. The service that converts HTML to text is a simple java class that is treated as a Web service. Note that it is not exposed as a SOAP service, but the java class is described in WSDL and made available to the client (which in this case is the BPEL4WS process) which then invokes it as a Web service using WSIF. This can be done because WSIF supports a WSDL binding extension (described here) that allows java classes to be treated as Web services directly, rather than as SOAP services - clients using WSIF APIs or stubs (which is what the BPEL4WS process runtime does) wouldn't know the difference. In fact, WSIF also supports viewing EJBs, programs using JMS and java connectors as Web services directly, by defining WSDL bindings for those protocols/APIs.

#### Details

This example works by using IBM's alphaworks implementation of the BPEL4WS specification, BPWS4J as the runtime engine. This engine can executes BPEL4WS processes, given the process definition, the definition of the process' external interface (how clients view it) and the WSDLs for all the Web services that the process uses. In our example, here are the relevant files:

- The process definition (a file conforming to the BPEL4WS specification)
- The process' external interface (a WSDL file that describes how the process is viewed by its partners)
- The definition of the Headline News service
- The definition of the conversion service - note the java binding in this WSDL file
- The definition of the BabelFish service

Note that the Headline News service and BabelFish service descriptions come from external sources. The HTML2Text service is a local java class deployed on the same server running the BPWS4J engine (which also serves up this web page) but has been developed completely independently.

#### Try it out

Choose the language in which you would like to see the latest headline news:

#### References

- The BPEL4WS column on developerworks, a good source of articles of an introductory as well an advanced nature.
- The BPWS4J engine, a prototype implementation that supports deployment and execution of processes described using BPEL4WS.
- Automating business processes and transactions in Web services; this described BPEL4WS along with WS-Coordination and WS-Transaction specifications, giving the reader a higher-level perspective.
- Business Processes in a Web Services World looks at the basic elements in the BPEL4WS language.