October 31, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Working with JAX-RPC

  • March 13, 2003
  • By Sams Publishing
  • Send Email »
  • More Articles »

Deploying the Web Service

Next you need to install the Web service on the Web server. To do so, create a folder called CarPartRequestApp. In the CarPartRequestApp folder, create a folder called WEB-INF. Inside the WEB-INF folder, copy over the web.xml and the CarPartRequest_Config.properties files and create a folder called classes. In the classes folder, copy over the CarPartReq folder that was created when you compiled the Web service interface and definition files and ran the xrpcc tool. Your directory structure should now look like the one shown in Figure 11.3.


Figure 11.3
The directory structure for the CarPartRequest Web service.

After the files are copied over, you will create a Web application archive WAR file and deploy it with Tomcat. To create the WAR file, go to the CarPartRequestApp folder and enter the following command at the command prompt:

jar cvf CarPartRequest.war *

This will create the Tomcat-deployable Web application archive for you. To run the Web service, copy the CarPartRequest.war file into the webapps folder.

Now start up Tomcat. Next launch a Web browser and go to http://localhost:8080/CarPartRequest/jaxrpc to verify the installation.

The browser should show the contents as displayed in Figure 11.4.


Figure 11.4
The CarPartRequest Web service.

Let's summarize what has been done so far. You created the Web service endpoint interface and its implementation class. Then you created the configuration file for the xrpcc tool. After that, you compiled the service endpoint interface and its implementation class, and ran the xrpcc tool to generate the stubs, ties, and WSDL document. Finally, you created the Web application archive for the CarPartRequest Web service and deployed it in the Tomcat Web server.

Now you will create the client application for the CarPartRequest Web service.

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();
    }
  }
}

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.

Summary

In this chapter, you learned about the JAX-RPC mechanism, and the classes that enable you to build and deploy JAX-RPC-based Web services and clients. You also created a JAX-RPC-based Web service and its client.


About the Authors

Aoyon Chowdhury is a senior member of the technical staff at Cadence Design Systems, Inc. He has more than seven years of experience in systems analysis and design, programming, systems administration, and technical writing.

Parag Choudhary has been consulting on software architectures for over 10 years with international consulting firms and independently. He has experience in a variety of application domains, from banking and insurance applications to electronic design automation software. He has skills in networking software and databases across different platforms including Unix, IBM Mainframe, and AS/400. He has expertise in object-oriented distributed application architectures and Internet technologies. He currently works in R&D at Cadence Design Systems, Inc.

Source of this material

This is Chapter 11: Working with JAX-RPC from the book Java APIs for XML Kick Start (ISBN:0-672-32434-2) written by Aoyon Chowdhury and Parag Choudhary, published by Sams Publishing.

To access the full Table of Contents for the book


Other Chapters from Sams Publishing:

Web Services and Flows (WSFL)
Overview of JXTA
Introduction to EJBs





Page 4 of 4



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel