Welcome!

PowerBuilder Authors: Dan Joe Barry, Carmen Gonzalez, Ian Thain, Yakov Werde, Paul Slater

Related Topics: PowerBuilder

PowerBuilder: Article

AXIS Third-Generation Web Services Implementation

AXIS Third-Generation Web Services Implementation

Web services is an emerging technology driven by the will to securely expose business logic beyond the firewall. Through Web services you can encapsulate existing business processes, publish them as services, search for and subscribe to other services, and exchange information throughout and beyond the enterprise. Web services will enable application-to-application interaction without the need to know anything about application implementations (languages, operating systems, tools) and without the need to write connectors to each new application.

Gartner defines a Web service as "a software component that represents a business function (or a business service) and can be accessed by another application (a client, a server, or another Web service) over public networks using generally available ubiquitous protocols and transports (i.e., SOAP over HTTP)."

What Is SOAP?
SOAP is an XML-based communication protocol and encoding format for interapplication communication. Originally conceived by Microsoft and UserLand software, it has evolved through several generations and the current spec, SOAP 1.1, is growing fast in popularity and usage. The W3C's XML Protocol Working Group is in the process of turning SOAP into a true open standard. As of this writing they have released a working draft of SOAP 1.2, which cleans up some of the more confusing areas of the 1.1 spec. SOAP is widely viewed as the backbone of a new generation of cross-platform, cross-language distributed computing applications termed Web services.

SOAP is a lightweight protocol for the exchange of information in a decentralized, distributed environment. It's an XML-based protocol that consists of three parts

  1. An envelope that defines a framework for describing what is in a message and how to process it
  2. A set of encoding rules for expressing instances of application-defined datatypes
  3. A convention for representing remote procedure calls and responses
What Is Axis?
Axis is one of several implementations of SOAP. The best known is Apache SOAP (http://xml.apache.org/soap/), now at version 2.2. (I discussed it in a previous article, "Web Services with PowerJ 4.0 and PB 8.0" [PBDJ, Vol. 9, issue 2]). Axis is also made by the Apache project but it's not part of the Apache SOAP project; it's a complete rewrite. Think of Axis as SOAP version 3. Axis has been under way for a long time. The first beta version was announced on March 15, 2002, and the second on April 29. It's the latter that's the focus of my article. The final version is expected to show up in late summer. You may read more about the Axis project on their Web site, http://xml.apache.org/axis/.

Why Axis?
In late 2000, the committers of Apache SOAP v2 began discussing how to make the engine more flexible, configurable, and able to handle both SOAP and the upcoming XML Protocol specification from the W3C.

After a while, it became clear that a rearchitecture from the ground up was required. Several of the v2 committers proposed very similar designs, all based around configurable "chains" of message "handlers" that would implement small bits of functionality in a very flexible and composable manner.

After months of continued discussion and coding effort in this direction, Axis now delivers the following key features:

  • Speed: Axis uses SAX (event-based) parsing to achieve significantly greater speed than earlier versions of Apache SOAP.
  • Flexibility: The Axis architecture gives the developer complete freedom to insert extensions into the engine for custom header processing, system management, or anything else you can imagine.
  • Stability: Axis defines a set of published interfaces that change relatively slowly compared to the rest of Axis.
  • Component-oriented deployment: You can easily define reusable networks of handlers to implement common patterns of processing for your applications or to distribute to partners.
  • Transport framework: We have a clean and simple abstraction for designing transports (i.e., senders and listeners for SOAP over various protocols such as SMTP, FTP, message-oriented middleware, etc.), and the core of the engine is completely transport-independent.
  • WSDL support: Axis supports the Web Service Description Language (www.w3.org/TR/wsdl), version 1.1, which allows you to easily build stubs to access remote services, and also to automatically export machine-readable descriptions of your deployed services from Axis.

    What's in the Current Release (Beta 2)?
    This release includes the following features:

    • SOAP 1.1-compliant engine (with some SOAP 1.2 support as well)
    • Flexible configuration/deployment system
    • Support for "drop-in" deployment of SOAP services (JWS)
    • Support for all basic types, and a type mapping system for defining new serializers/deserializers
    • Automatic serialization/deserialization of JavaBeans, including customizable mapping of fields to XML elements/attributes
    • Automatic two-way conversions between Java collections and SOAP arrays
    • Providers for RPC and message-based SOAP services
    • Automatic WSDL generation from deployed services
    • WSDL2Java tool for building Java proxies and skeletons from WSDL documents
    • Java2WSDL tool for building WSDL from Java classes
    • Preliminary security extensions that can integrate with Servlet 2.2 security/roles
    • Support for session-oriented services via HTTP cookies or transport-independent SOAP headers
    • Preliminary support for SOAP with attachments specification
    • An EJB provider for accessing EJBs as Web services
    • HTTP servlet-based transport
    • Standalone version of the server (with HTTP support)
    • Examples, including a client and server for the SOAP builders community interoperability tests and experimental TCP and file-based transports
    What's Missing?
  • Full SOAP 1.2 support

    Installing Axis
    First you have to download the Axis distribution from http://xml.apache.org/axis/dist/beta2/xml-axis-beta2.zip and unzip it to C:\Axis.

    Now create a directory called Axis in the Web application folder of your Jaguar installation (%JAGUAR%\Repository\WebApplication\axis). Copy the webapps/axis directory from the xml-axis distribution into this directory. You'll find the file web.xml in the WEB-INF directory, which is in the directory you just copied. Use Jaguar Manager to add a new Web application called axis and configure the two servlets (use web.xml for a description).

    If you download the source code from www.sys-con.com/pbdj/ sourcec.cfm you'll have a complete Web application that you can import to EAServer.

    From the "lib" directory in the WEB-INF directory, copy the JARs associated with the JAXP 1.1 XML-compliant parser of your choice. This generally means either the xerces.jar from the xml-xerces distribution (http://xml.apache.org/dist/xerces-j/), or the crimson.jar and jaxp.jar from the JAXP 1.1 reference implementation (http://java.sun.com/xml/xml_jaxp.html).

    Note that EAServer comes with a distribution of xerces.jar, but this version did not work with the beta 2 of Axis. I recommend downloading the newest version.

    Now try your installation by pointing your browser to http://localhost:8080/axis/servlet/AxisServlet. After a few seconds you should see the screen shown in Figure 1.

    Deploying Your Code as a Web Service
    The Apache people realized that it would be nice to be able to drop some code somewhere and have it become a Web service "just like that." This simplicity is a current trend; Microsoft has it in .NET, and Sybase in EAServer 4.1. But just how easy is it to:

    • Deploy a piece of code?
    • Write a client that accesses the Web service?
    • Obtain the WSDL for the deployed Web service?
    Deploy a PowerBuilder Component as a Web Service
    The first step is to write a simple PowerBuilder component for EAServer. The component will be a simple calculator and should have two functions: one for adding and one for subtracting two long variables and returning the result as long. We'll also add some logging functionality so we can see that there's no trick and it's our component producing the output for the Web service client (see Figure 2).

    The component will be deployed to the package name, Axis. The component name should be calculator.

    Download the finished application from PBDJ's Web site. After deploying the component don't forget to create stubs from within Jaguar Manager.

    Now we need a wrapper class for our PowerBuilder component. This class also has our two functions - add and subtract - and an additional function in which we instantiate our PowerBuilder component (getComponent). The two functions take the passed arguments and route the call to the PowerBuilder component (see Listing 1).

    As you can see, we've added a main function that we can use to test the class from outside EAServer. Before running the examples, you'll need to make sure that your CLASSPATH includes:

    • xml-axis-beta2/lib/axis.jar
    • xml-axis-beta2/lib/jaxrpc.jar
    • xml-axis-beta2/lib/commons-logging.jar
    • xml-axis-beta2/lib/tt-bytecode.jar
    • xml-axis-beta2/lib/wsdl4j.jar
    • A JAXP-1.1-compliant XML parser such as Xerces or Crimson
    • % JAGUAR %/html/classes
    • % JAGUAR %/java/classes
    • %JAGUAR%\java\lib\easclient.jar
    To enable the class (and with it our PowerBuilder component) as a Web service, we copy the Java file into the Axis Web application using the extension .jws instead of .java:

    copy AxisCalculator.java %JAGUAR%
    \Repository\WebApplication\axis\Calculator.jws

    Having the code (with the .jws extension) in the Web application will deploy it and allow us to access it. If we open a browser and access the file (e.g., http://localhost:8080/axis/Calculator.jws) we'll be told that we're talking to a Web service. How easy was that?! A simple copy command and we're done.

    Now that we have a deployed Web service, we need to access it. Let's look at a Java client that allows us to pass in a math operation (add or subtract) and the two amounts to work with (see Listing 2).

    What's happening here? We create new Service and Call objects. These are the standard JAX-RPC objects that are used to store metadata about the service to be invoked. Then we set up our endpoint URL - this is the destination for our SOAP message. Next step is we define the operation (method) name of the Web service. Last but not least, we actually invoke the desired service, passing in an array of parameters - in this case one string.

    You can see what happens to the arguments by looking at the SOAP request that goes out on the wire. The string argument is automatically serialized into XML, and the server responds with an identical string, which we deserialize and print.

    Note: To actually watch the XML flowing back and forth between a SOAP client and server, you can use the included tcpmon tool.

    java org.apache.axis.utils.tcpmon [listenPort targetHost targetPort]
    java org.apache.axis.utils.tcpmon 8090 localhost 8080

    After compiling and running the client we'll see that our PowerBuilder component is doing a good job and returns the right value:

    java CalcClient -p8080 add 15 6
    java CalcClient subtract 2 5

    Note that you may need to replace the "-p8080" with whatever port your EAServer is running on and that the default port is 8080; if you use tcpmon, the port for it is 8090 (see Figure 3).

    We can verify that it's really our PowerBuilder component doing the operation by looking into the Jaguar.log file. You should see an entry like this:

    Jun 06 15:53:51 2002: axiscomponents add 15+6

    A PowerBuilder Client for AXIS
    We'll use PocketSOAP for our PowerBuilder client. PocketSOAP is a SOAP client COM component for the Windows family, originally targeted at the Pocket PC (hence the name). There is also a Win32 version that works on Windows 95/98/Me/NT4/2000/XP. The package includes an HTTP transport for making HTTP-based SOAP requests; however, the transport is separate from the main SOAP core, so any other transport could be easily added. It also includes an XML parser, used for parsing the response SOAP messages.

    PocketSOAP is designed for interoperability and is regularly tested with over 30 of the leading SOAP tools, including:

    • Apache SOAP and Axis
    • Microsoft SOAP Toolkit v2.0
    • Microsoft ASP.NET Web services
    You can download it from www.pocketsoap.com/pocketsoap/PocketSOAP_130.msi, then click on the msi file to install it.

    The core object is the Envelope object. This provides access to all the interesting stuff, like setting the method name and the parameters. Send the request to the Axis server with the HTTPTransport object; it supports redirects, cookies, proxies, authentication, proxy authentication, and SSL. The implementation is very easy, as you can see in Listing 3.

    Conclusion
    Axis is essentially Apache SOAP 3.0. It's a from-scratch rewrite, designed around a streaming model (using SAX internally rather than DOM). The intention is to create a more modular, more flexible, and higher-performing SOAP implementation (relative to Apache SOAP 2.0). It's very easy to deploy Web services using Axis. PowerBuilder developers can use PocketSOAP to call different Web services, including Apache SOAP and Axis.

  • More Stories By Berndt Hamboeck

    Berndt Hamboeck is a senior consultant for BHITCON (www.bhitcon.net). He's a CSI, SCAPC8, EASAC, SCJP2, and started his Sybase development using PB5. You can reach him under admin@bhitcon.net.

    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.