3.8 Perspectives

3.8.1 Highlights

  • Web Service is an emerging technology to address integration and proprietary technology silos .

  • Java , XML, SOAP, and UDDI are the typical technologies used.

  • There is much market hype surrounding Web Services.

  • Many technology vendors and vertical solutions have already embedded Web Services into their products and solutions.

  • Web Services provides a service-based infrastructure with intelligent and reusable components .

  • Web Services addresses technology issues of high implementation cost, legacy systems integration, and cross-platform interoperability.

  • There are competitive advantages to implementing Web Services. Web Services technology provides a low-cost alternative to integrating with multiple trading partners using open standards. It is platform independent, and provides better flexibility to customers and trading partners, because it can accommodate local data formats, and can reuse existing infrastructure and business functionality from the legacy systems.

3.8.2 Best Practices and Pitfalls

Best Practices

Select a reasonably rich set of functionality that can be implemented within three to six months.

The candidate should be able to demonstrate the benefits immediately. A Total Cost of Ownership (TCO) model is required.

Involve leading Web Services vendors for technology skill transfer, for example:

  • Customize a Web Services training workshop using the pilot requirements.

  • Assess the Web Services solution architecture.

Pitfalls

Do not be too ambitious with too many dependencies or items that require longer lead time (for example, SOAP-enabling a mainframe platform).

Do not start implementation without support from senior management.

Do not start a pilot using a mission-critical functionality.

Do not involve a big team in the pilot. Start with a small team.

3.8.3 Challenge

A medium-size listed financial institution in Hong Kong wants to reduce its operating costs associated with supporting legacy systems on the mainframe. The corporation has been innovative and reputable in providing securities trading, retail banking, and credit card services to the local market.

The CEO is concerned about implementing new technology for technology's sake and believes that not all legacy systems need to be migrated to Unix, as they are fairly stable.

Is it relevant to introduce Web Service technology to meet its challenge?

3.8.4 Paper and Pencil

Study Questions

What are the architectural differences between CORBA and XML Web Services in terms of exposing the services, method invocation, and security? What problems does each technology intend to resolve?

What are the principles or guidelines to consider when choosing the Web Services developer tools and platform, say, for an IT shop with an established J2EE application platform?

What are the prerequisites to Web Services-enable an application? For instance, can we expose a business service from a legacy mainframe application with only a CICS program name ?


Lab Exercises

Exercise 1 XML to DTD

Your trading partner, XYZ investment bank, provides you with an XML document with real data. They support DTD, not an XML Schema, but they do not have a DTD.

The following XML document (an fpML example) describes an FX option bought by XYZ from ABC traded on January 15, 2002.

Exercise 1.1 Could you check whether this is a well- formed XML? You may use XMLSpy 4.3 Suite (evaluation copy) to validate it.

Note: What information (for example, attributes) do you need before you can validate a well-formed XML document?

Exercise 1.2 Could you reverse-engineer the XML into a DTD? If you generate a sample XML from the DTD, could you get the identical XML?

 
 <?XML version="1.0" " encoding = "UTF-8"?> <!DOCTYPE trade PUBLIC "-//FpML//DTD 3-0//EN" "" > [   <!- DTD declarations omitted --> ]> <trade>   <tradeHeader>     <partyTradeIdentifier>       <partyReference href="#XYZ"/>     </partyTradeIdentifier>     <partyTradeIdentifier>       <partyReference href="#ABC"/>     </partyTradeIdentifier>     <tradeDate>2002-01-15</tradeDate>    </tradeHeader>    <fxSimpleOption>       <productType>Nondeliverable Option</productType>       <buyerPartyReference href="#XYZ"/>       <sellerPartyReference href="#ABC"/>       <expiryDateTime>          <expiryDate>2002-04-09</expiryDate>          <hourMinuteTime>1000</hourMinuteTime>          <businessCenter>USNY</businessCenter>       </expiryDateTime>       <exerciseStyle>European</exerciseStyle>    </fxSimpleOption>    <party id = "XYZ">       <partyId>CHASUS33</partyId>       <partyName>XYZ BUYER BANK</partyName>    </party>    <party id = "ABCN">       <partyId>ABCANL2A</partyId>       <partyName>ABC Seller Bank</partyName>    </party> </trade> <!- end of DTDs > 

To assist your understanding, the fxOption XML is depicted in Figure 3-34:

Figure 3-34. xOption XML

graphics/03fig32.gif

Answer Key
 
 <! Name:         'trade.dtd'            > <! Description:  sample fpML FX option  > <!ELEMENT trade                (tradeHeader, fxSimpleOption, party) > <!ELEMENT tradeHeader           (partyTradeIdentifier) > <!ELEMENT fxSimpleOption       (productType,                                  buyerPartyReference,                                  sellerPartyReference,                                  expiryDateTime,                                  exerciseStyle) > <!ELEMENT party                 (partyID, partyName) > <!ELEMENT partyTradeIdentifier (partyReference) > <!ELEMENT partyReference       EMPTY > <!ATTLIST partyReference                                href CDATA #REQUIRED > <!ELEMENT productType          (#PCDATA) > <!ELEMENT buyerPartyReference  EMPTY > <!ATTLIST buyerPartyReference                                href CDATA #REQUIRED > <!ELEMENT sellerPartyReference EMPTY > <!ATTLIST sellerPartyReference                                href CDATA #REQUIRED > <!ELEMENT expiryDateTime         (expiryDate,                                   hourMinuteTime,                                   businessCenter) > <!ELEMENT expiryDate           (#PCDATA) > <!ELEMENT hourMinuteTime       (#PCDATA) > <!ELEMENT businessCenter       (#PCDATA) > <!ELEMENT exerciseStyle        (#PCDATA) > <!ELEMENT partyID              (#PCDATA) > <!ELEMENT partyName            (#PCDATA) > 

Figure 3-35 shows an example using XMLSPy to validate the DTD in this exercise.

Exercise 2 Writing the First JAXM Program

You are going to install Java Web Services Developer Pack and write your first JAXM-SOAP program.

Exercise 2.1 Download the Java Web Services Developer Pack from http://java.sun.com . Install and configure it according to the Installation Guide.

Exercise 2.2 Based on the sample sniplet in the text, write your first JAXM-SOAP program to send the following XML message:

 
 <?XML version="1.0" " encoding = "UTF-8"?> <!DOCTYPE trade PUBLIC "-//FpML//DTD 3-0//EN" "" > [   <!- DTD declarations omitted --> ]> <trade>   <tradeHeader>     <partyTradeIdentifier>       <partyReference href="#XYZ"/>     </partyTradeIdentifier>     <partyTradeIdentifier>       <partyReference href="#ABC"/>     </partyTradeIdentifier>     <tradeDate>2002-01-15</tradeDate>    </tradeHeader>    <fxSimpleOption>       <productType>Nondeliverable Option</productType>       <buyerPartyReference href="#XYZ"/>       <sellerPartyReference href="#ABC"/>       <expiryDateTime>          <expiryDate>2002-04-09</expiryDate>          <hourMinuteTime>1000</hourMinuteTime>          <businessCenter>USNY</businessCenter>       </expiryDateTime>       <exerciseStyle>European</exerciseStyle>    </fxSimpleOption>    <party id = "XYZ">       <partyId>CHASUS33</partyId>       <partyName>XYZ BUYER BANK</partyName>    </party>    <party id = "ABCN">       <partyId>ABCANL2A</partyId>       <partyName>ABC Seller Bank</partyName>    </party> </trade> <!- end of DTDs > 

Exercise 3 Creating a New Web Service With JWSDP

You are going to expose an existing Foreign Exchange currency rate conversion functionality as a Web Services call using JWSDP. The following sections show the procedures to define, implement, and deploy a new Web Services call using JWSDP. The procedures can be found in section "Four Steps to Web Services-Enable Your Applications" found previously in this chapter. The sample code in this exercise can be found on the CD-ROM accompanying this book under Chapter 3 labs. They are also reusable for Chapter 8 Web Services in Action: Case Study chapter.

Figure 3-35. DTD Validated by XMLSpy

graphics/03fig33.jpg

Step 1. Define Service Description

Start with the business service you would like to expose. In this example, you are going to define a Web Services call to get a Foreign Exchange rate quote given the Sell and Buy currency codes. You need to define an interface file that defines the method and the parameters (refer to Figure 3-36). This interface file will be used to generate a service description (WSDL) file.

Figure 3-36 FXProviderIF.java Program
 package myws; import java.rmi.Remote; import java.rmi.RemoteException; public interface  FXProviderIF  extends Remote {     public String  getPrice(String sellCurrency, String buyCurrency)  throws RemoteException; } 
Step 2. Implement Web Services Description Language ( WSDL )

A sample implementation of the business service is listed below in Figure 3-37. The getPrice method simply returns an exchange rate in String format, when given a Sell/Buy currency pair (such as USD to HKD). Please note that the "getPrice" method can be a remote Web Services call or functionality abstracted from any legacy backoffice system.

Figure 3-37 FXProviderImpl.java Program
 package myws; import java.math.BigDecimal; import java.util.*; public class FXProviderImpl implements FXProviderIF { //  FX conversion rate     public String  getPrice(String sellCurrency, String buyCurrency)  {          if (sellCurrency.equalsIgnoreCase("HKD")) {                if (buyCurrency.equalsIgnoreCase("USD")) {                        return "0.128";             }  else             if (buyCurrency.equalsIgnoreCase("EUR")) {                    return "0.123";         } else         if (buyCurrency.equalsIgnoreCase("RMB")) {                return "1.25";             }  else             if (buyCurrency.equalsIgnoreCase("SGD")) {                    return "0.22";             } else                 if (buyCurrency.equalsIgnoreCase("MYR")) {                    return "2.85";                 } else return "0.00";         } else         if (sellCurrency.equalsIgnoreCase("USD")) {                 if (buyCurrency.equalsIgnoreCase("HKD")) {                    return "7.78";               }  else               if (buyCurrency.equalsIgnoreCase("EUR")) {                       return "0.92";               } else               if (buyCurrency.equalsIgnoreCase("RMB")) {                    return "8.20";                 }  else                 if (buyCurrency.equalsIgnoreCase("SGD")) {                    return "2.5";               } else                 if (buyCurrency.equalsIgnoreCase("MYR")) {                    return "3.45";                 } else return "0.00";           }  else return "0.00";           // end-if     }  // getPrice } // class0 
There are a few files you need to customize in order to build a Web Services call ” build.xml, config.xml, web.xml, build.properties and jaxrpc -ri.xml. A build.xml template can be used to customize your development environment. Typically, you need to modify the path names (file locations) in the build.properties file, which is used by build.xml . The files build.properties and build.xml reside in the same directory of your program source codes that your "ant" build tool or your favorite IDE developer tool will use to build your work files.

For web.xml , specify the display name of the Web Services and the session time-out parameters (in this case, 60 seconds). Refer to the excerpt in Figure 3-38:

Figure 3-38 web.xml Contents
 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE web-app     PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"     "http://java.sun.com/j2ee/dtds/web-app_2_3.dtd"> <web-app>   <display-name>  FX Currency Exchange Service  </display-name>   <description>FX Currency Exchange Rate Service</description>   <session-config>     <session-timeout>  60  </session-timeout>   </session-config> </web-app> 
The config.xml (Figure 3-39) simply defines the WSDL and the package name. JWSDP 1.01 has a new function to generate WSDL when adding a suffix "?WSDL" to the service end-point. Refer to the following program excerpt:

Figure 3-39 config.xml Contents
 <?xml version="1.0" encoding="UTF-8"?> <configuration     xmlns="http://java.sun.com/xml/ns/jax-rpc/ri/config">   <wsdl location=  "http://localhost:8080/myws/FXProvider?WSDL"  packageName="myws"/> </configuration> 
For jaxrpc-ri.xml (refer to the following program excerpt), specify the interface file and the implementation file (that is, the class names myws.FXProviderIF and myws.FXProviderImpl ) where JWSDP ( wscompile and wsdeploy used in the build.xml script) will generate the stubs and WSDL files. Please note that jaxrpc-ri.xml (Figure 3-40) is a new configuration file introduced in JWSDP 1.01, and is not required in JWSDP 1.0 or Early Access releases. It is not a standard configuration file used in other Web Services tools.

Figure 3-40 jaxrpc-ri.xml Contents
 <?xml version="1.0" encoding="UTF-8"?> <webServices     xmlns="http://java.sun.com/xml/ns/jax-rpc/ri/dd"     version="1.0" targetNamespaceBase="http://www.nextfrontiers.com/wsdl" typeNamespaceBase="http://www.nextfrontiers.com/types"     urlPatternBase="/  myws  ">     <endpoint         name="  myws  "         displayName="FX Currency Exchange Service"         description="FX Currency Exchange Service"         interface="  myws.FXProviderIF  "         implementation="  myws.FXProviderImpl  "/>      <endpointMapping         endpointName="  myws  "         urlPattern="/  FXProvider  "/> </webServices> 
The build.xml script will compile all Java programs (in this case, FXProviderIF.java and FXProviderImpl.java ), generate stubs, and get ready for deploying the Web Services.

The utility wscompile (from JWSDP) will generate the stubs using the config.xml that are necessary to build the client proxy. The WSDL file will be generated during the process, and it will be deleted afterward unless the -keep option is specified. The following excerpt in Figure 3-41 depicts how wscompile is used in the build.xml script:

Figure 3-41 Use of wscompile in build.xml
 <target name="generate-stubs" depends="set-ws-scripts,prepare"       description="Runs wscompile to generate the client stub classes">       <echo message="Running wscompile...."/>     <exec executable="${  wscompile  }">        <arg line="-gen:client"/>        <arg line="-d ${build}/client"/>        <arg line="-classpath ${build}/shared"/>        <arg line="  config.xml  "/>     </exec>   </target> 
Next , you need to deploy the Web Services. You may like to execute the commands as follows :

 
 D:\Dev\mydemo\myws>  ant build  Buildfile: build.xml clean:    [delete] Deleting directory D:\Dev\mydemo\myws\build clean-wars:    [delete] Deleting: D:\Dev\mydemo\myws\dist\myws-portable.war    [delete] Deleting: D:\Dev\mydemo\myws\dist\myws.war prepare:      [echo] Creating the required directories....     [mkdir] Created dir: D:\Dev\mydemo\myws\build\client\myws     [mkdir] Created dir: D:\Dev\mydemo\myws\build\server\myws     [mkdir] Created dir: D:\Dev\mydemo\myws\build\shared\myws     [mkdir] Created dir: D:\Dev\mydemo\myws\build\wsdeploy-generated     [mkdir] Created dir: D:\Dev\mydemo\myws\build\WEB-INF\classes\myws compile-server:      [echo] Compiling the server-side source code....     [javac] Compiling 2 source files to D:\Dev\mydemo\myws\build\shared setup-web-inf:      [echo] Setting up build/WEB-INF....    [delete] Deleting directory D:\Dev\mydemo\myws\build\WEB-INF      [copy] Copying 2 files to D:\Dev\mydemo\myws\build\WEB-INF\classes\myws      [copy] Copying 1 file to D:\Dev\mydemo\myws\build\WEB-INF      [copy] Copying 1 file to D:\Dev\mydemo\myws\build\WEB-INF package:      [echo] Packaging the WAR....       [jar] Building jar: D:\Dev\mydemo\myws\dist\myws-portable.war set-ws-scripts: process-war:      [echo] Running wsdeploy....      [exec] info: created temporary directory: D:\Dev\mydemo\myws\build\wsdeploy -generated\jaxrpc-deploy-de5ada      [exec] info: processing endpoint: myws      [exec] Note: sun.tools.javac.Main has been deprecated.      [exec] 1 warning      [exec] info: created output war file: D:\Dev\mydemo\myws\dist\myws.war      [exec] info: removed temporary directory: D:\Dev\mydemo\myws\build\wsdeploy -generated\jaxrpc-deploy-de5ada build-service: build: BUILD SUCCESSFUL Total time: 16 seconds 
Next, you need to deploy the Web Services under the context "/myws." This enables any remote client to invoke the Web Services via RPC.

 
 D:\Dev\mydemo\myws>  ant deploy  Buildfile: build.xml deploy:    [deploy] OK - Installed application at context path /myws    [deploy] BUILD SUCCESSFUL Total time: 4 seconds 
You may want to ensure that the context (in this example, myws) is not created before. Otherwise, you need to either use a new context name, or to undeploy the context (for example, ant undeploy ).

Upon successful deployment of the Web Services call, you may like to verify the WSDL by entering the URL http://localhost:8080/myws/FXProvider , as in Figure 3-42:

Figure 3-42. Verifying Web Services Deployment With JWSDP

graphics/03fig34.gif

You should be able to validate the WSDL by clicking from the WSDL URL (refer to Figure 3-43).

Figure 3-43. WSDL Generated From JWSDP

graphics/03fig35.gif

Step 3. Publish to Registry

This step is required if you want to publish to a Service Registry. In this example, we do not require the Web Services to publish to the UDDI Service Registry. Please refer to Chapter 8, Web Services in Action: Case Study, for an example of publishing to the UDDI Service Registry with JAXR.

Step 4. Invoke Web Services

SOAP-Lite is used here to illustrate that Web Services can be invoked from a non-Java client. A SOAP-Lite client reads in a Web Services service description (a URI pointing to the WSDL, which is http://localhost:8080/myws/FXProvider?WSDL in this case) and invokes the remote method "getPrice" via RPC. The script is written in Perl and can be executed from a Windows command prompt or a Unix terminal.

 
 #!perl -w #!d:\perl\bin\perl.exe BEGIN { warn "SOAP-Lite is started...\n" } # import interface. All methods from loaded service are imported by default use SOAP::Lite     service =>  'http://localhost:8080/myws/FXProvider?WSDL',  ; warn "Invoking a remote Web Service...\n"; print 'The currency exchange for USD-to-HKD is '; print  getPrice('USD', 'HKD'),  "\n"; 
Execute the SOAP-Lite script (in this example, myFX.pl) as follows:

 
 D:\Dev\mydemo>  perl myFX.pl  SOAP-Lite is started... Invoking a remote Web Service... The currency exchange for USD-to-HKD is 7.78 

3.8.5 References

Some Web Services Resource Web Sites

http://www.webservices.org

http://www.theserverside.com/home/index.jsp

Web Services Overview

John Hagel III and John Seely Brown. "Your Next IT Strategy." Harvard Business Review , October 2001. IBM Web Services Overview Team. "Web Services Architecture Overview" IBM, September 2000. http://www-106.ibm.com/developerworks/library/w-ovr/

Lawrence Wilkes. "Web Services ”Right Here, Right Now." IBM, 2002. http://www-3.ibm.com/software/solutions/webservices/pdf/cbdi.pdf

SOAP Interoperability Organization

SOAP Builders Interoperability Test Lab. http://www.xmethods.net/ilab/

White Mesa ”for SOAP interoperability testing. http://www.whitemesa.net/

Web Services Standards

Business Process Execution Language for Web Services (BPEL4WS). http://www-106.ibm.com/developerworks/webservices/library/ ws-bpel /

Web Services Choreography Interface (WSCI). http://wwws.sun.com/software/xml/developers/wsci/wsci-spec-10.pdf

Others

Alur Deepak, John Crupi, and Dan Malks. Core J2EE Patterns . Prentice Hall, 2001.

Judith M. Myerson. "Web Services Architecture." Tech, 2002. http://www.webservicesarchitect.com/content/articles/webservicesarchitectures.pdf

Sun Professional Services. Dot-com and Beyond: Breakthrough Internet-Based Architectures and Methodologies . Prentice Hall, 2001.



J2EE Platform Web Services
J2EE Platform Web Services
ISBN: 0131014021
EAN: 2147483647
Year: 2002
Pages: 127
Authors: Ray Lai

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net