8.7 Code Customization and Deployment

8.7.1 Environment Set-up

The demo system assumes the installation and configuration of J2SE, JWSDP, TSIK, and jSAML. The environment set-up of these components is recapitulated in Appendix C, Demo Environment Set-up of this book. The demo program files should be installed under C:\opt\myFX, and the jSAML demo program files should be installed under %JWSDP_ HOME%\webapps (something similar to the following figure).

You should have the following directories set up for the demo system (see Figure 8-23):

Figure 8-23 Environment Set-up for Directories
 C:\opt\myFX D:\Dev\jSAML D:\Dev\TSIK D:\Dev\WSDP D:\Dev\WSDP with the sub-directories ContentProvider, CreditReports, MMC, OtherCo, SomeCo 

After these components are installed, you may want to verify the set-up to ensure all components are working before you install the demo codes (see Figure 8-24).

Figure 8-24. Demo Program Files Installed under %JWSDP_HOME%\webapps

graphics/08fig19.jpg

The demo code files are zipped under the file name "myFX.zip" in the CD-ROM accompanying this book under /labs/ch8. Extract the files under / opt/myFX of your local drive (or / opt/myFX on your Unix machine). If you choose to install under a different directory, then you need to modify all the file locations in the properties files and some program codes (with program comments).

To make use of the ANT scripts, it is essential to understand that these scripts assume a specific directory structure (with the subdirectories build, dist, src, web) for the program files (also refer to Appendix C, Demo Environment Set-up).

8.7.2 Customizing ANT Scripts

If we need to modify the file location or change the build directory, we do not need to modify the ANT scripts. We can modify the property file "build.properties" in each subdirectory. The ANT script will read in the "build.properties" and substitute the macro or variables into the " build.xml " of the same directory.

For instance, the " build.properties " (see Figure 8-25) for the FX Price Provider specifies the source file location ("src"), class library ("clib" and "elib"), and the service end-point ("endpoint"). Most of these variables can be reusable for similar Web Services development. This also does not require developers to modify these parameters for software migration and deployment.

Figure 8-25 Sample build.properties File
[View full width]
  build  =build  src  =src/com/sun/webservicedemo  url  =http://localhost:8080/manager  docs.path  =c:  example.path  =${docs.path}/myFX/provider  endpoint  =http://localhost:8080/jaxrpc-fx-provider/provider/FXProviderIF  web.inf.config  =FXProvider_Config.properties  context.path  =jaxrpc-fx-provider  war.file  =${context.path}.war  build.path  =${docs.path}/myFX/provider/${build}  client.jar  =provider-client.jar  jaxr.org.jar  =jaxr-org.jar clib=${jwsdp.home}/common/lib elib=${jwsdp.home}/common/endorsed clib-jars=${clib}/activation.jar:${clib}/castor-0.9.3.9-xml.jar:${clib}/commons-JXPath-0 graphics/ccc.gif .1-dev.jar:${clib}/commons-collections.jar:${clib}/commons-dbcp.jar:${clib}/commons-logging graphics/ccc.gif .jar:${clib}/commons-pool.jar:${clib}/dom4j.jar:${clib}/fscontext.jar:${clib}/jaas.jar graphics/ccc.gif :${clib}/jasper-compiler.jar:${clib}/ jasper-runtime.jar:${clib}/jaxm-api.jar:${clib} graphics/ccc.gif /jaxm-runtime.jar:${clib}/jaxp-api.jar:${clib}/jaxr-api.jar:${clib}/jaxr-ri.jar:${clib} graphics/ccc.gif /jaxrpc-api.jar:${clib}/jaxrpc-ri.jar:${clib}/jcert.jar:${clib}/jdbc2_0-stdext.jar:${clib} graphics/ccc.gif /jnet.jar:${clib}/jsse.jar:${clib}/jta-spec1_0_1.jar:${clib}/mail.jar:${clib}/naming-common graphics/ccc.gif .jar:${clib}/naming-factory.jar:${clib}/naming-resources.jar:${clib}/openorb.jar:${clib} graphics/ccc.gif /providerutil.jar:${clib}/saaj-api.jar:${clib}/saaj-ri.jar:${clib}/servlet.jar:${clib}/soap graphics/ccc.gif .jar:${clib}/xindice.jar:${clib}/xmldb-xupdate.jar:${clib}/xmldb.jar elib-jars=${elib}/dom.jar:${elib}/sax.jar:${elib}/xalan.jar:${elib}/xercesImpl.jar:${elib} graphics/ccc.gif /xsltc.jar jwsdp-jars=${elib-jars}:${clib-jars} 

8.7.3 Running ANT Scripts

Step 1: Compile FX Quote Provider

Go to /opt.myFX/provider and run the command "ant build." You should see the compilation result as follows . This process will compile all Java code into classes and generates stubs and ties for the Web Services (see Figure 8-26).

Figure 8-26 Step 1 ”Compile FX Quote Provider
 C:\opt\myFX\provider>  ant build  Buildfile: build.xml clean:    [delete] Deleting directory C:\opt\myFX\provider\build    [delete] Deleting directory C:\opt\myFX\provider\dist prepare:      [echo] Creating the required directories....     [mkdir] Created dir: C:\opt\myFX\provider\build\client     [mkdir] Created dir: C:\opt\myFX\provider\build\server     [mkdir] Created dir: C:\opt\myFX\provider\build\service-class     [mkdir] Created dir: C:\opt\myFX\provider\build\registry     [mkdir] Created dir: C:\opt\myFX\provider\dist compile-jaxr:      [echo] Compiling the JAXR source code....     [javac] Compiling 4 source files to C:\opt\myFX\provider\build\registry jar-jaxr:      [echo] Building the jaxr-org.jar  file....      [copy] Copying 1 file to C:\opt\myFX\provider\build\registry\com\sun\webservice demo       [jar] Building jar: C:\opt\myFX\provider\dist\jaxr-org.jar set-xrpcc: compile-server:      [echo] Compiling the server-side source code....     [javac] Compiling 2 source files to C:\opt\myFX\provider\build\service-class xrpcc-server:      [echo] Running xrpcc for the server: xrpcc-client:      [echo] Running xrpcc for the client: compile-client:      [echo] Compiling the client source code.... jar-client:      [echo] Building the provider-client.jar file....       [jar] Building jar: C:\opt\myFX\provider\dist\provider-client.jar copy-to-web-inf:      [echo] Setting up build/WEB-INF....     [mkdir] Created dir: C:\opt\myFX\provider\build\WEB-INF\classes      [copy] Copying 14 files to C:\opt\myFX\provider\build\WEB-INF\classes      [copy] Copying 1 file to C:\opt\myFX\provider\build\WEB-INF      [copy] Copying 1 file to C:\opt\myFX\provider\build\WEB-INF build: BUILD SUCCESSFUL Total time: 23 seconds 

Please note that the ANT script has used xrpcc to generate the appropriate stubs and ties with a given config.xml for the client and the server modules respectively.

Step 2: Set up FX Quote Service

Go to /opt/myFX/provider and issue the command "ant set-up-service." You should see the compilation result as in Figure 8-27. This process will publish the FX Quote Service to the UDDI Service Registry.

Figure 8-27 Step 2 ”Set Up FX Quote Service
 C:\opt\myFX\provider>  ant set-up-service  Buildfile: build.xml install:      [echo] Installing the application....   [install] OK - Installed application at context path /jaxrpc-fx-provider   [install] run-jaxr-publish:      [echo] Running OrgPublisher.      [echo] Note: Remember to start the registry server before running this prog ram.      [java] uname,pwd,endpoint:testuser:testuser:http://localhost:8080/jaxrpc-fx -provider/provider/FXProviderIF      [java] Created connection to registry      [java] Got registry service, query manager, and life cycle manager      [java] Established security credentials      [java] Before binding, endpoint is: http://localhost:8080/jaxrpc-fx-provide r/provider/FXProviderIF      [java] Organization saved      [java]  Organization key is efa5c6ac-a7ef-a5c6-48d8-563b22d11005  set-up-service: BUILD SUCCESSFUL Total time: 16 seconds 

Please note that the set-up service step will check security credentials, publish the provider to the UDDI Service Registry, and render an organization key efa5c6ac-a7ef-a5c6-48d8-563b22d11005.

Step 3: Compile the Message Provider

Go to /opt/myFX/provider-tsik, and issue the command "ant build." You should see the compilation result as in Figure 8-28.

Figure 8-28 Compile the Message Provider
 C:\opt\myFX\provider-tsik>  ant build  Buildfile: build.xml clean:    [delete] Deleting directory C:\opt\myFX\provider-tsik\build    [delete] Deleting directory C:\opt\myFX\provider-tsik\dist prepare:      [echo] Creating the required directories....     [mkdir] Created dir: C:\opt\myFX\provider-tsik\build\client     [mkdir] Created dir: C:\opt\myFX\provider-tsik\build\server     [mkdir] Created dir: C:\opt\myFX\provider-tsik\dist compile-server:      [echo] Compiling the server-side source code....     [javac] Compiling 1 source file to C:\opt\myFX\provider-tsik\build\server compile-client:      [echo] Compiling the client source code.... jar-client:      [echo] Building the jaxm-client.jar file....       [jar] Building jar: C:\opt\myFX\provider-tsik\dist\jaxm-client.jar setup-web-inf:      [echo] Setting up build/WEB-INF....     [mkdir] Created dir: C:\opt\myFX\provider-tsik\build\WEB-INF\classes      [copy] Copying 1 file to C:\opt\myFX\provider-tsik\build\WEB-INF\classes      [copy] Copying 1 file to C:\opt\myFX\provider-tsik\build\WEB-INF build: BUILD SUCCESSFUL Total time: 44 seconds 
Step 4: Install the Message Provider

Go to /opt/myFX/provider-tsik, and issue the command "ant install." You should see the compilation result as in Figure 8-29.

Figure 8-29 Install the Message Provider
 C:\opt\myFX\provider-tsik>  ant install  Buildfile: build.xml clean:    [delete] Deleting directory C:\opt\myFX\provider-tsik\build    [delete] Deleting directory C:\opt\myFX\provider-tsik\dist prepare:      [echo] Creating the required directories....     [mkdir] Created dir: C:\opt\myFX\provider-tsik\build\client     [mkdir] Created dir: C:\opt\myFX\provider-tsik\build\server     [mkdir] Created dir: C:\opt\myFX\provider-tsik\dist compile-server:      [echo] Compiling the server-side source code....     [javac] Compiling 1 source file to C:\opt\myFX\provider-tsik\build\server compile-client:      [echo] Compiling the client source code.... jar-client:      [echo] Building the jaxm-client.jar file....       [jar] Building jar: C:\opt\myFX\provider-tsik\dist\jaxm-client.jar setup-web-inf:      [echo] Setting up build/WEB-INF....     [mkdir] Created dir: C:\opt\myFX\provider-tsik\build\WEB-INF\classes      [copy] Copying 1 file to C:\opt\myFX\provider-tsik\build\WEB-INF\classes      [copy] Copying 1 file to C:\opt\myFX\provider-tsik\build\WEB-INF build: install:      [echo] Installing the application....   [install] OK - Installed application at context path /jaxm-profile-provider   [install] BUILD SUCCESSFUL 

Please note that this process will make the message provider available under the context /jaxm-profile-provider.

Step 5: Compile the Client Requester

Go to /opt/myFX/requester, and issue the command "ant build." You should see the compilation result as in Figure 8-30. This process simply compiles all Java classes into the build directory.

Figure 8-30 Compile the Client Requester
 C:\opt\myFX\requester>  ant build  Buildfile: build.xml init: prepare: build:     [javac] Compiling 6 source files to C:\opt\myFX\requester\build\WEB-INF\classes      [echo] finish compile.... BUILD SUCCESSFUL Total time: 6 seconds 
Step 6: Install the Client Requester

Go to /opt/myFX/requester, and issue the command "ant install." You should see the compilation result as in Figure 8-31.

Figure 8-31 Install the Client Requester
 C:\opt\myFX\requester>  ant install  Buildfile: build.xml init: prepare: build:      [echo] finish compile.... install:      [echo] Installing the application....   [install] OK - Installed application at context path/ myFX   [install] BUILD SUCCESSFUL Total time: 5 seconds 

Please note that this process will make the FX Spot Rate Quote Service available under the context /myFX.

Step 7: Verify the Deployed Services

Go to a browser, and issue the URL http://localhost:8080/manager.list . You should see the compilation result as in Figure 8-32. You will be prompted for login as the admin id during the first-time login. Alternatively, you can issue the command "ant list" from any one of the previous ANT script. Please also refer to the next section "Verifying Set-up and Remote Services."

Figure 8-32. Verifying Deployment

graphics/08fig20.jpg

Step 8: Invoke the Client

Go to a browser, and issue the URL http://localhost:8080/MMC/docs/index.html . You should see the same screens as in the " User Experience" section. If you just want to invoke the FX Spot Rate Quote screen, you may choose to issue the URL http://localhost:8080/myFX/getFXQuote .

8.7.4 Modifying the Remote FX Quote Engine

If you would like to build a local FX Spot Rate Quote engine, you may wish to replace the FXPriceImpl.java file under the subdirectory C:\opt\myFX\ provider. The program in Figure 8-33 shows a sample implementation of the local engine.

Figure 8-33 Modifying the Remote FX Quote Engine
 package com.sun.webservicedemo; 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 } // class 

There may be times when you want to provide a more personalized service instead of using the remote Web Services or to enhance the performance. Then you can replace your own codes under the method "getPrice." You simply rerun the ANT script to compile and install the services again. There will be no change in the user experience.

8.7.5 Verifying Set-up and Remote Services

Before invoking the remote Web Services, you may wish to verify whether your Internet (or VPN) connectivity is active and that the remote Service Provider is alive .

Next, you can verify the list of services deployed on your Application Server. Do this by issuing the URL http://localhost:8080/manager/list in your browser. Alternatively, you can issue the command ant list in a Command Prompt (depending upon whether there is a "list" target defined in your build.xml script). Either action will list all deployed Web Services in your Application Server. You should see /myFX and /jaxm-profile-provider services deployed at run time (see Figure 8-34).

Figure 8-34 Verify Set-up and Remote Services
 C:\opt\myFX\provider-tsik>  ant list  Buildfile: build.xml list:      [echo] Listing the application....      [list] OK - Listed applications for virtual host localhost      [list]      [list] /manager:running:0:../server/webapps/manager      [list]      [list] /ContentProvider:running:0:D:\Dev\WSDP\webapps\ContentProvider      [list]      [list] /jaxm-soaprp:running:0:D:\Dev\WSDP\webapps\jaxm-soaprp.war      [list]      [list] /saaj-simple:running:0:D:\Dev\WSDP\webapps\saaj-simple.war      [list]      [list] /jaxm-remote:running:0:D:\Dev\WSDP\webapps\jaxm-remote.war      [list]      [list] /CreditReports:running:0:D:\Dev\WSDP\webapps\CreditReports      [list]      [list] /MMC:running:0:D:\Dev\WSDP\webapps\MMC      [list]      [list] /jaxmtags:running:0:D:\Dev\WSDP\webapps\jaxmtags.war      [list]      [list] /axis:running:0:D:\Dev\WSDP\webapps\axis      [list]      [list] /SomeCo:running:0:D:\Dev\WSDP\webapps\SomeCo      [list]      [list]  /myFX:running:0:c:/myFX/requester/build  [list]      [list] /OtherCo:running:0:D:\Dev\WSDP\webapps\OtherCo      [list]      [list] /jaxm-translator:running:0:D:\Dev\WSDP\webapps\jaxm-translator.war      [list]      [list]  /jaxm-profile-provider:running:0:c:/myFX/provider-tsik/build  [list]      [list] /cocoon:running:0:D:\Dev\WSDP\webapps\cocoon      [list]      [list] /jstl-examples:running:0:D:\Dev\WSDP\webapps\jstl-examples.war      [list]      [list] /registry-server:running:0:D:\Dev\WSDP\webapps\registry-server.war      [list]      [list] /jaxm-simple:running:0:D:\Dev\WSDP\webapps\jaxm-simple.war      [list]      [list] /:running:0:D:\Dev\WSDP\webapps\ROOT      [list]      [list] /admin:running:0:../server/webapps/admin      [list] BUILD SUCCESSFUL Total time: 3 seconds 

8.7.6 Managing Program Changes

To recompile the program codes, you need to undeploy the Web Services from the Application Server with the ANT script shown in Figure 8-35.

Figure 8-35 Managing Program Changes
 C:\opt\myFX\provider>  ant remove  Buildfile: build.xml remove:      [echo] Removing the application....    [remove] OK - Removed application at context path /jaxrpc-fx-provider    [remove] BUILD SUCCESSFUL Total time: 2 seconds 

8.7.7 Unit Testing

Currently, the unit testing is manual. For future extension, it is possible to make use of the JUnit testing tool to write unit testing scripts.

8.7.8 Integration Testing

The integration testing is done manually. Typically, test engineers need to write Use Cases for integration testing to cover both positive and negative test cases. It is also a good time to consider using Web Services stress-testing tools that can randomly generate test cases and benchmark the performance.

8.7.9 Deploying Codes

Running the ANT scripts from the previous sections will not permanently deploy the code. In other words, after the Application Server restarts, you need to rerun all of the ANT scripts again to make the services available. To deploy the Web Services permanently, you need to remove the services (by running "ant remove" under each subdirectory) and to deploy them once and for all (by running "ant deploy" ). The deploy script will generate a myFX.war file and place it in the webapps directory.

Many developer tools (such as IDE, Studio) embed ANT and automate the application code seamlessly. Yet in a real-life deployment situation, these deployment scripts need to be customized for the local operating environment and integrated with the existing software version control and/or software migration tools.

If you use a Windows NT or Linux platform to compile and test code, and deploy on a separate platform, you may need to deploy the war files. You also need to ensure the UDDI Service Registry is being updated on the target deployment platform. Achieve this by replicating the UDDI Service Registry from the development platform to the production platform (for example, using some automated scripts or UDDI Service Registry replication features) or manually enter the business service information (manual data re-entry is undesirable for production owing to potential data entry errors).



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