Welcome!

Microservices Expo Authors: Liz McMillan, Todd Matters, Pat Romanski, Elizabeth White, Stefana Muller

Related Topics: Microservices Expo

Microservices Expo: Article

Developing J2EE 1.4 Web Services on the Fly

Developing J2EE 1.4 Web Services on the Fly

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
Remote Procedure Call (RPC) is a mechanism through which you invoke procedures (or services) from a remote client. In the Java world, we have the Java API for XML-based RPC (JAX-RPC) in which service invocation takes place through an XML-based protocol called Simple Object Access Protocol (SOAP) over HTTP transport. Since the J2EE 1.4 platform uses standard technologies such as XML, SOAP, and HTTP, it is easy for developers to create Web services that are platform independent and interoperable.

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
The steps that are involved in building and deploying the service are:

  1. Define the interface class for the service.
  2. Implement the interface class.
  3. Compile the classes and generate WSDL.
  4. Package the classes as an EAR file.
  5. Deploy the service.
Service Interface
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
The service implementation StockQuoteImpl implements the interface StockQuote IF. This connects to an Axis stock quote service that is running on the www. xmethods.net server. The getQuote request made to this service returns an XML document that contains the value of the stock. If you are behind a firewall, you need to specify the proxyHost and proxyPort properties in order to access the service. The implementation for the stock quote service is shown in Listing 2.

Generating the WSDL File
J2EE 1.4 provides a tool called wscompile.bat, which generates the WSDL file for the service. The Ant target generate-wsdl does this for you and runs this tool as follows:

wscompile.bat -define -d build/server -nd build/server
-classpath build/server service-config.xml

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
To package the service, use the ant target package-service, which packages the service and its dependent files in a stockquote.ear file. This EAR file bundles the stockquote-jaxrpc.war file in it. The contents of these WAR and EAR files are:

stockquote-jaxrpc.war
META-INF/
META-INF/MANIFEST.MF
WEB-INF/
WEB-INF/classes/
WEB-INF/classes/stockquote/
MyHelloService.wsdl
WEB-INF/classes/stockquote/StockQuoteIF.class
WEB-INF/classes/stockquote/StockQuoteImpl.class
WEB-INF/mapping.xml
WEB-INF/web.xml
WEB-INF/webservices.xml

stockquote.ear
META-INF/
META-INF/MANIFEST.MF
stockquote-jaxrpc.war
META-INF/application.xml
META-INF/sun-j2ee-ri.xml

Deploying the Service
J2EE 1.4 provides a tool called deploytool.bat for deploying Web applications. The developed EAR file is deployed in the server using this tool. This can be done with the help of the Ant target deploy-service. As a precondition, you need to start the database server from the command prompt by typing

%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
-deployModule stockquote.ear

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
The steps involved in building and running the client are:

  1. Generate the stubs.
  2. Code the client class.
  3. Compile the client class.
  4. Package the classes as a JAR file.
  5. Run the client.
Generate the Stubs
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
-classpath build/server client-config.xml

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
Once the service is defined, implemented, and deployed, it is ready for access by the clients. The client uses the generated stubs to interact with the service. This is a static client as it was created before runtime. The client takes the service endpoint as the input argument, and invokes the getQuote method by passing the symbol "HPQ". The service returns the value of the symbol to the system console. This is the real-time quote of the symbol with a delay of 20 minutes. The client for accessing the stock quote service is shown in Listing 5.

Compiling and Packaging the Client
The Client sources along with the stubs are compiled and packaged as a JAR file by the Ant targets compile-client and package-client. This generates a file - client.jar that is used in invoking the stock quote service.

Setup Instructions for Running the Web Service
Required Software:

  • Download Ant 1.5.3 from http://ant.apache.org
  • Download J2SE 1.4.1 from http://java.sun.com/j2se/1.4.1/download.html
  • Download J2EE 1.4 Beta from http://java.sun.com/j2ee/1.4/download.html#sdk

    Setting Up Environment Variables
    To run the StockQuote application, you need to set the following environment variables:

  • J2EE_HOME=C:\j2sdkee1.4
  • JAVA_HOME=C:\j2sdk1.4.1_02
  • ANT_HOME=H:\apache-ant-1.5.3
  • PATH=%JAVA_HOME%/bin;%J2EE_HOME%\bin;%ANT_HOME%\bin;%PATH%

    Invoke the Service Using the Web Service Client
    Download the source code of the developed Web service. Extract this under "J2EE_HOME\doc\samples". The "build. xml" file bundled with this application defines all of the tasks discussed above as Ant targets. Before proceeding further, you need to change the proxy-related information in the StockQuoteImpl.java class.

    As a precondition, you need to start the database and J2EE servers by using the following commands:

    %J2EE_HOME%/bin/cloudscape.bat -start
    "%J2EE_HOME%/bin/j2ee.bat -verbose

    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:

  • Ant build-service: Compiles the service sources.
  • Ant package-service: Packages the service classes and related files in an EAR file.
  • Ant deploy-service: Deploys the service in the server.
  • Ant list: Lists the deployed service.
  • Ant build-client: Compiles the client sources.
  • Ant package-client: Packages the client classes as a JAR file.
  • Ant run: Invokes the service. Figure 2 shows the output of the client after invoking the service. It returns the value of the symbol with a delay of 20 minutes.
  • Ant undeploy: Undeploys the service from the server.

     

    Conclusion
    Tools always ease the development of application software. With the help of robust tools, developers can spend more time designing the applications than developing the applications. The current release of the J2EE 1.4 platform provides some basic tools that ease the development of Web services. The J2EE 1.4 final release plans to have support for Web Services - Interoperability (WS-I) basic profiles. Developing and deploying Web services on the fly is a reality with the arrival of the J2EE 1.4 platform.

    References

  • J2EE 1.4 Platform Home: http://java.sun.com/j2ee/
  • J2EE 1.4 Specification: http://java.sun.com/j2ee/j2ee-1_4-pfd2-spec.pdf
  • JSR 151: www.jcp.org/en/jsr/detail?id=151
  • The J2EE Tutorial Addendum: http://java.sun.com/j2ee/1.4/docs/tutorial/index.html
  • More Stories By Arulazi Dhesiaseelan

    Arulazi Dhesiaseelan holds Master of Computer Applications degree from PSG College of Technology, India. He has been involved in designing and building Java based applications and SDK for more than three years. He was also involved in the API development of UDDI4j project hosted at http://uddi4j.org. He's working with Hewlett Packard Company (India Software Operations), Bangalore. Currently he is involved in the development of an open service framework for mobile infrastructures. He can be reached at [email protected]

    Comments (0)

    Share your thoughts on this story.

    Add your comment
    You must be signed in to add a comment. Sign-in | Register

    In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


    @MicroservicesExpo Stories
    New competitors, disruptive technologies, and growing expectations are pushing every business to both adopt and deliver new digital services. This ‘Digital Transformation’ demands rapid delivery and continuous iteration of new competitive services via multiple channels, which in turn demands new service delivery techniques – including DevOps. In this power panel at @DevOpsSummit 20th Cloud Expo, moderated by DevOps Conference Co-Chair Andi Mann, panelists examined how DevOps helps to meet the de...
    For most organizations, the move to hybrid cloud is now a question of when, not if. Fully 82% of enterprises plan to have a hybrid cloud strategy this year, according to Infoholic Research. The worldwide hybrid cloud computing market is expected to grow about 34% annually over the next five years, reaching $241.13 billion by 2022. Companies are embracing hybrid cloud because of the many advantages it offers compared to relying on a single provider for all of their cloud needs. Hybrid offers bala...
    "When we talk about cloud without compromise what we're talking about is that when people think about 'I need the flexibility of the cloud' - it's the ability to create applications and run them in a cloud environment that's far more flexible,” explained Matthew Finnie, CTO of Interoute, in this SYS-CON.tv interview at 20th Cloud Expo, held June 6-8, 2017, at the Javits Center in New York City, NY.
    @DevOpsSummit at Cloud Expo taking place Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center, Santa Clara, CA, is co-located with the 21st International Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The widespread success of cloud computing is driving the DevOps revolution in enterprise IT. Now as never before, development teams must communicate and collaborate in a dynamic, 24/7/365 environment. There is ...
    What's the role of an IT self-service portal when you get to continuous delivery and Infrastructure as Code? This general session showed how to create the continuous delivery culture and eight accelerators for leading the change. Don Demcsak is a DevOps and Cloud Native Modernization Principal for Dell EMC based out of New Jersey. He is a former, long time, Microsoft Most Valuable Professional, specializing in building and architecting Application Delivery Pipelines for hybrid legacy, and cloud ...
    Containers, microservices and DevOps are all the rage lately. You can read about how great they are and how they’ll change your life and the industry everywhere. So naturally when we started a new company and were deciding how to architect our app, we went with microservices, containers and DevOps. About now you’re expecting a story of how everything went so smoothly, we’re now pushing out code ten times a day, but the reality is quite different.
    There's a lot to gain from cloud computing, but success requires a thoughtful and enterprise focused approach. Cloud computing decouples data and information from the infrastructure on which it lies. A process that is a LOT more involved than dragging some folders from your desktop to a shared drive. Cloud computing as a mission transformation activity, not a technological one. As an organization moves from local information hosting to the cloud, one of the most important challenges is addressi...
    For organizations that have amassed large sums of software complexity, taking a microservices approach is the first step toward DevOps and continuous improvement / development. Integrating system-level analysis with microservices makes it easier to change and add functionality to applications at any time without the increase of risk. Before you start big transformation projects or a cloud migration, make sure these changes won’t take down your entire organization.
    21st International Cloud Expo, taking place October 31 - November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA, will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud strategy. Me...
    "We are a monitoring company. We work with Salesforce, BBC, and quite a few other big logos. We basically provide monitoring for them, structure for their cloud services and we fit into the DevOps world" explained David Gildeh, Co-founder and CEO of Outlyer, in this SYS-CON.tv interview at DevOps Summit at 20th Cloud Expo, held June 6-8, 2017, at the Javits Center in New York City, NY.
    Microservices are increasingly used in the development world as developers work to create larger, more complex applications that are better developed and managed as a combination of smaller services that work cohesively together for larger, application-wide functionality. Tools such as Service Fabric are rising to meet the need to think about and build apps using a piece-by-piece methodology that is, frankly, less mind-boggling than considering the whole of the application at once. Today, we'll ...
    Cloud Expo, Inc. has announced today that Andi Mann and Aruna Ravichandran have been named Co-Chairs of @DevOpsSummit at Cloud Expo Silicon Valley which will take place Oct. 31-Nov. 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. "DevOps is at the intersection of technology and business-optimizing tools, organizations and processes to bring measurable improvements in productivity and profitability," said Aruna Ravichandran, vice president, DevOps product and solutions marketing...
    In his session at Cloud Expo, Alan Winters, an entertainment executive/TV producer turned serial entrepreneur, presented a success story of an entrepreneur who has both suffered through and benefited from offshore development across multiple businesses: The smart choice, or how to select the right offshore development partner Warning signs, or how to minimize chances of making the wrong choice Collaboration, or how to establish the most effective work processes Budget control, or how to ma...
    SYS-CON Events announced today that CA Technologies has been named "Platinum Sponsor" of SYS-CON's 21st International Cloud Expo®, which will take place October 31-November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. CA Technologies helps customers succeed in a future where every business - from apparel to energy - is being rewritten by software. From planning to development to management to security, CA creates software that fuels transformation for companies in the applic...
    In the decade following his article, cloud computing further cemented Carr’s perspective. Compute, storage, and network resources have become simple utilities, available at the proverbial turn of the faucet. The value they provide is immense, but the cloud playing field is amazingly level. Carr’s quote above presaged the cloud to a T. Today, however, we’re in the digital era. Mark Andreesen’s ‘software is eating the world’ prognostication is coming to pass, as enterprises realize they must be...
    A common misconception about the cloud is that one size fits all. Companies expecting to run all of their operations using one cloud solution or service must realize that doing so is akin to forcing the totality of their business functionality into a straightjacket. Unlocking the full potential of the cloud means embracing the multi-cloud future where businesses use their own cloud, and/or clouds from different vendors, to support separate functions or product groups. There is no single cloud so...
    Both SaaS vendors and SaaS buyers are going “all-in” to hyperscale IaaS platforms such as AWS, which is disrupting the SaaS value proposition. Why should the enterprise SaaS consumer pay for the SaaS service if their data is resident in adjacent AWS S3 buckets? If both SaaS sellers and buyers are using the same cloud tools, automation and pay-per-transaction model offered by IaaS platforms, then why not host the “shrink-wrapped” software in the customers’ cloud? Further, serverless computing, cl...
    Hybrid IT is today’s reality, and while its implementation may seem daunting at times, more and more organizations are migrating to the cloud. In fact, according to SolarWinds 2017 IT Trends Index: Portrait of a Hybrid IT Organization 95 percent of organizations have migrated crucial applications to the cloud in the past year. As such, it’s in every IT professional’s best interest to know what to expect.
    The taxi industry never saw Uber coming. Startups are a threat to incumbents like never before, and a major enabler for startups is that they are instantly “cloud ready.” If innovation moves at the pace of IT, then your company is in trouble. Why? Because your data center will not keep up with frenetic pace AWS, Microsoft and Google are rolling out new capabilities. In his session at 20th Cloud Expo, Don Browning, VP of Cloud Architecture at Turner, posited that disruption is inevitable for comp...
    Companies have always been concerned that traditional enterprise software is slow and complex to install, often disrupting critical and time-sensitive operations during roll-out. With the growing need to integrate new digital technologies into the enterprise to transform business processes, this concern has become even more pressing. A 2016 Panorama Consulting Solutions study revealed that enterprise resource planning (ERP) projects took an average of 21 months to install, with 57 percent of th...