|
Comments
Did you read today's front page stories & breaking news?
SYS-CON.TV
|
Service-Oriented Architecture Developing J2EE 1.4 Web Services on the Fly
Developing J2EE 1.4 Web Services on the Fly
May. 23, 2003 12:00 AM
As Web services technology becomes pervasive, the beta release of Java 2 Enterprise Edition (J2EE) 1.4, which focuses primarily on Web services, flags a milestone in the Web services developer community. Sun's J2EE Reference Implementation (RI) helps developers to easily understand the technology through its robust implementation of the specification. The J2EE 1.4 specification (JSR-151) adds a lot of functionality to the platform. The core theme of J2EE 1.4 circumvents Web services. It has incorporated most of the Web services-related JSRs in its specification, including JSR-109 (Implementing Enterprise Web Services), JSR-101 (Java APIs for XML-based RPC), JSR-67 (Java APIs for XML Messaging 1.0), and JSR-93 (Java API for XML Registries 1.0). Basically, a Web service client can access J2EE applications in two ways. First, the client can access a Web service created with JAX-RPC. Second, the client can access an EJB Web service (only stateless session beans) through its Web service endpoints. The bottom line is that JAX-RPC uses a servlet to implement the Web service. This helps in exposing the existing stateless session beans as Web services. In this article, I'll deal with the development of a Web service using the J2EE 1.4 platform. I'll use the JAX-RPC APIs that form the basis for developing J2EE 1.4 Web services on the fly. Creating a Web Service with JAX-RPC The typical life cycle of a Web service has three stages: develop the Web service, deploy the Web service, and invoke the Web service. We'll follow this life cycle in developing our Web services using J2EE 1.4. We will consider the familiar stock quote application for our illustration. A stock quote service is deployed in the server. The client invokes the service by passing a stock symbol. Here, the service and the client are developed using the JAX-RPC APIs. Figure 1 shows the interactions between the Stock quote Web service and the stock quote client. Stubs are the client-side proxies used to communicate with the service. Ties are the classes the server needs to communicate with a remote client. Stubs and ties are low-level classes that perform similar functions, i.e, stubs on the client side and ties on the server side.
![]() Building and Deploying the Service
Our stock quote service has one method, getQuote, which takes the symbol as the argument and returns the value of the stock symbol. The interface definition for the stock quote service is shown in Listing 1. Service Implementation Generating the WSDL File wscompile.bat -define -d build/server -nd build/server The generated WSDL file MyStock QuoteService.wsdl is shown in Listing 3. The Ant target build-service compiles the service classes and the generation of the WSDL file for the service. Packaging the Service stockquote-jaxrpc.war Deploying the Service %J2EE_HOME%/bin/cloudscape.bat -start Start the J2EE server from the command prompt by typing %J2EE_HOME%/bin/j2ee.bat -verbose to start the server in verbose mode. The Ant target runs the deploy tool as follows: deploytool.bat -id stockquote-jaxrpc This deploys the stock quote service in the server. To verify that the service has been successfully deployed, execute the Ant target "list", which lists all the applications that are deployed on the server. You can verify the successful service deployment by typing the following URL in your browser: http://localhost:8000/stockquote-jaxrpc/mystockquote?WSDL If you can see the WSDL file on your browser, the service is deployed successfully. Building and Running the Client
Stubs are the client-side proxies for the service. J2EE 1.4 provides a tool called wscompile.bat for generating these stubs. The Ant target generate-stubs, defined in our build.xml, does this task for you. This target runs the tool as follows: wscompile.bat -gen:client -d build/client The wscompile.bat tool generates files based on the information that it reads from the MyStockQuoteService.wsdl. The -gen: client option instructs the tool to generate the client-side classes called stubs. The -d option instructs the tool in which directory the generated stubs are to be placed. The -classpath option instructs the tool where to find the input classes. The tool reads the config file "client-config.xml" which has the information about the location of the WSDL file. The client configuration file client-config. xml is shown in Listing 4. Service Client Compiling and Packaging the Client Setup Instructions for Running the Web Service Setting Up Environment Variables Invoke the Service Using the Web Service Client As a precondition, you need to start the database and J2EE servers by using the following commands: %J2EE_HOME%/bin/cloudscape.bat -start This starts the server in verbose mode. Wait until the command window displays "J2EE server startup complete." Now you are ready to execute the Ant targets that will help you build, deploy, and invoke the Web service. Execute the following targets:
![]() Conclusion References Reader Feedback: Page 1 of 1
Latest Cloud Developer Stories
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
|
SYS-CON Featured Whitepapers
Most Read This Week
Breaking Cloud Computing News
|
|||||||||||||||||||||||||||||||||||||||||||||||||