The CarPartRequestClient Application

printer-friendly version of this section  Print  e-mail this section  E-Mail  add a public, group or private note  Add Note  add a bookmark about this section  Add Bookmark    

Java APIs for XML Kick Start
By Aoyon Chowdhury, Parag Choudhary

Table of Contents
Chapter 11.  Working with JAX-RPC


The CarPartRequestClient Application

The CarPartRequestClient application will connect to the Web service and execute the remote procedure getPartRequest. The CarPartRequestClient will call the getPartRequest method through the stub. Remember that when you ran the xrpcc tool, it created the stub, CarPartRequestIF_Stub.class, and the implementation of the service, CarPartRequest_Impl.class. You can get a reference to the stub by using the getCarPartRequestIFPort method of the CarPartRequest_Impl class.

After obtaining the reference to the stub, you will use the _setProperty method to provide the URI of the service to the client application. The URI to the service will be provided as a command-line parameter.

To create the client application, create a file called CarPartRequestClient.java. In this file, enter the following lines of code:

package CarPartReq; public class CarPartRequestClient {     public static void main(String[] args) {         try {             CarPartRequestIF_Stub stub =                 (CarPartRequestIF_Stub) (new CarPartRequest_Impl(). graphics/ccc.gifgetCarPartRequestIFPort());             stub._setProperty(                 javax.xml.rpc.Stub.ENDPOINT_ADDRESS_PROPERTY,                 args[0]);             System.out.println(stub.getCarPartRequest("Engine 2"));         } catch (Exception ex) {             ex.printStackTrace();         }     } } 

NOTE

The code discussed so far is available in the MyJAXRPCExample folder.


Next you need to compile the client. To do so, enter the following at the command prompt:

javac -classpath .;d:\jwsdp-1_0\common\lib\jaxrpc-ri.jar; d:\jwsdp-1_0\common\lib\ graphics/ccc.gifjaxrpc-api.jar; d:\jwsdp-1_0\common\lib\activation.jar; d:\jwsdp-1_0\common\lib\dom4j.jar; graphics/ccc.gif d:\jwsdp-1_0\common\lib\jaxm-api.jar; d:\jwsdp-1_0\common\lib\jaxm-client.jar; d:\ graphics/ccc.gifjwsdp-1_0\common\lib\log4j.jar; d:\jwsdp-1_0\common\lib\mail.jar; d:\jwsdp-1_0\common\lib\ graphics/ccc.gifxalan.jar; d:\jwsdp-1_0\common\lib\xerces.jar; d:\jwsdp-1_0\common\lib\jaxp-api.jar -d .  graphics/ccc.gif*Client.java 

This creates CarPartRequestClient.class in the CarPartReq folder.

NOTE

To build the client, you can also use the buildclient.bat batch file, available in the MyJAXRPCExample folder. The syntax to run the buildclient.bat file is as follows:

buildclient CarPartRequestClient.java 

Running the CarPartRequestClient Application

To run the CarPartRequestClient application, enter the following lines of code:

java -classpath .;d:\jwsdp-1_0\common\lib\jaxrpc-ri.jar; d:\jwsdp-1_0\common\lib\ graphics/ccc.gifjaxrpc-api.jar; d:\jwsdp-1_0\common\lib\activation.jar; d:\jwsdp-1_0\common\lib\dom4j.jar; graphics/ccc.gif d:\jwsdp-1_0\common\lib\jaxm-api.jar; d:\jwsdp-1_0\common\lib\jaxm-client.jar; d:\ graphics/ccc.gifjwsdp-1_0\common\lib\log4j.jar; d:\jwsdp-1_0\common\lib\mail.jar; d:\jwsdp-1_0\common\lib\ graphics/ccc.gifxalan.jar; d:\jwsdp-1_0\common\lib\xerces.jar; d:\jwsdp-1_0\common\lib\jaxp-api.jar; d:\ graphics/ccc.gifjwsdp-1_0\common\endorsed\dom.jar; d:\jwsdp-1_0\common\endorsed\sax.jar; d:\jwsdp-1_0\ graphics/ccc.gifcommon\endorsed\xalan.jar; d:\jwsdp-1_0\common\endorsed\xercesImpl.jar; d:\jwsdp-1_0\ graphics/ccc.gifcommon\endorsed\xsltc.jar; d:\jwsdp-1_0\common\lib\saaj-api.jar; d:\jwsdp-1_0\common\lib\saaj-ri.jar; CarPartReq.CarPartRequestClient http://localhost: graphics/ccc.gif8080/CarPartRequest/jaxrpc/CarPartRequestIF 

NOTE

To run the client, you can also use the runclient.bat batch file, available in the MyJAXRPCExample folder. The syntax to run the buildclient.bat file is as follows:

runclient CarPartReq.CarPartRequestClient http://localhost:8080/CarPartRequest/jaxrpc/ graphics/ccc.gifCarPartRequestIF 

Because you had sent the parameter value of getCarPartRequest method as Engine 2, the output should be as follows:

Your requested engine is in stock. It will be shipped shortly. 

printer-friendly version of this section  Print  e-mail this section  E-Mail  add a public, group or private note  Add Note  add a bookmark about this section  Add Bookmark    
Top

[0672324342/ch11lev1sec8]

 
 


JavaT APIs for XML Kick Start
JAX: Java APIs for XML Kick Start
ISBN: 0672324342
EAN: 2147483647
Year: 2002
Pages: 133

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