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(). getCarPartRequestIFPort()); 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\ jaxrpc-api.jar; d:\jwsdp-1_0\common\lib\activation.jar; d:\jwsdp-1_0\common\lib\dom4j.jar; d:\jwsdp-1_0\common\lib\jaxm-api.jar; d:\jwsdp-1_0\common\lib\jaxm-client.jar; d:\ jwsdp-1_0\common\lib\log4j.jar; d:\jwsdp-1_0\common\lib\mail.jar; d:\jwsdp-1_0\common\lib\ xalan.jar; d:\jwsdp-1_0\common\lib\xerces.jar; d:\jwsdp-1_0\common\lib\jaxp-api.jar -d . *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\ jaxrpc-api.jar; d:\jwsdp-1_0\common\lib\activation.jar; d:\jwsdp-1_0\common\lib\dom4j.jar; d:\jwsdp-1_0\common\lib\jaxm-api.jar; d:\jwsdp-1_0\common\lib\jaxm-client.jar; d:\ jwsdp-1_0\common\lib\log4j.jar; d:\jwsdp-1_0\common\lib\mail.jar; d:\jwsdp-1_0\common\lib\ xalan.jar; d:\jwsdp-1_0\common\lib\xerces.jar; d:\jwsdp-1_0\common\lib\jaxp-api.jar; d:\ jwsdp-1_0\common\endorsed\dom.jar; d:\jwsdp-1_0\common\endorsed\sax.jar; d:\jwsdp-1_0\ common\endorsed\xalan.jar; d:\jwsdp-1_0\common\endorsed\xercesImpl.jar; d:\jwsdp-1_0\ common\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: 8080/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/ CarPartRequestIF 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. |