- XML Reference Guide
- Overview
- What Is XML?
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- Table of Contents
- The Document Object Model
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- DOM and Java
- Informit Articles and Sample Chapters
- Books and e-Books
- Implementations
- DOM and JavaScript
- Using a Repeater
- Repeaters and XML
- Repeater Resources
- DOM and .NET
- Informit Articles and Sample Chapters
- Books and e-Books
- Documentation and Downloads
- DOM and C++
- DOM and C++ Resources
- DOM and Perl
- DOM and Perl Resources
- DOM and PHP
- DOM and PHP Resources
- DOM Level 3
- DOM Level 3 Core
- DOM Level 3 Load and Save
- DOM Level 3 XPath
- DOM Level 3 Validation
- Informit Articles and Sample Chapters
- Books and e-Books
- Documentation and Implementations
- The Simple API for XML (SAX)
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- SAX and Java
- Informit Articles and Sample Chapters
- Books and e-Books
- SAX and .NET
- Informit Articles and Sample Chapters
- SAX and Perl
- SAX and Perl Resources
- SAX and PHP
- SAX and PHP Resources
- Validation
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- Document Type Definitions (DTDs)
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- XML Schemas
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- RELAX NG
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- Schematron
- Official Documentation and Implementations
- Validation in Applications
- Informit Articles and Sample Chapters
- Books and e-Books
- XSL Transformations (XSLT)
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- XSLT in Java
- Java in XSLT Resources
- XSLT and RSS in .NET
- XSLT and RSS in .NET Resources
- XSL-FO
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- XPath
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- XML Base
- Informit Articles and Sample Chapters
- Official Documentation
- XHTML
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- XHTML 2.0
- Documentation
- Cascading Style Sheets
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- XUL
- XUL References
- XML Events
- XML Events Resources
- XML Data Binding
- Informit Articles and Sample Chapters
- Books and e-Books
- Specifications
- Implementations
- XML and Databases
- Informit Articles and Sample Chapters
- Books and e-Books
- Online Resources
- Official Documentation
- SQL Server and FOR XML
- Informit Articles and Sample Chapters
- Books and e-Books
- Documentation and Implementations
- Service Oriented Architecture
- Web Services
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- Creating a Perl Web Service Client
- SOAP::Lite
- Amazon Web Services
- Creating the Movable Type Plug-in
- Perl, Amazon, and Movable Type Resources
- Apache Axis2
- REST
- REST Resources
- SOAP
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- SOAP and Java
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- WSDL
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- UDDI
- UDDI Resources
- XML-RPC
- XML-RPC in PHP
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- Ajax
- Asynchronous Javascript
- Client-side XSLT
- SAJAX and PHP
- Ajax Resources
- JSON
- Ruby on Rails
- Creating Objects
- Ruby Basics: Arrays and Other Sundry Bits
- Ruby Basics: Iterators and Persistence
- Starting on the Rails
- Rails and Databases
- Rails: Ajax and Partials
- Rails Resources
- Web Services Security
- Web Services Security Resources
- SAML
- Informit Articles and Sample Chapters
- Books and e-Books
- Specification and Implementation
- XML Digital Signatures
- XML Digital Signatures Resources
- XML Key Management Services
- Resources for XML Key Management Services
- Internationalization
- Resources
- Grid Computing
- Grid Resources
- Web Services Resource Framework
- Web Services Resource Framework Resources
- WS-Addressing
- WS-Addressing Resources
- WS-Notifications
- New Languages: XML in Use
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- Google Web Toolkit
- GWT Basic Interactivity
- Google Sitemaps
- Google Sitemaps Resources
- Accessibility
- Web Accessibility
- XML Accessibility
- Accessibility Resources
- The Semantic Web
- Defining a New Ontology
- OWL: Web Ontology Language
- Semantic Web Resources
- Google Base
- Microformats
- StructuredBlogging
- Live Clipboard
- WML
- XHTML-MP
- WML Resources
- Google Web Services
- Google Web Services API
- Google Web Services Resources
- The Yahoo! Web Services Interface
- Yahoo! Web Services and PHP
- Yahoo! Web Services Resources
- eBay REST API
- WordML
- WordML Part 2: Lists
- WordML Part 3: Tables
- WordML Resources
- DocBook
- Articles
- Books and e-Books
- Official Documentation and Implementations
- XML Query
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- XForms
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- Resource Description Framework (RDF)
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- Topic Maps
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation, Implementations, and Other Resources
- Rich Site Summary (RSS)
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- Simple Sharing Extensions (SSE)
- Atom
- Podcasting
- Podcasting Resources
- Scalable Vector Graphics (SVG)
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- OPML
- OPML Resources
- Summary
- Projects
- JavaScript TimeTracker: JSON and PHP
- The Javascript Timetracker
- Refactoring to Javascript Objects
- Creating the Yahoo! Widget
- Web Mashup
- Google Maps
- Indeed Mashup
- Mashup Part 3: Putting It All Together
- Additional Resources
- Frequently Asked Questions About XML
- What's XML, and why should I use it?
- What's a well-formed document?
- What's the difference between XML and HTML?
- What's the difference between HTML and XHTML?
- Can I use XML in a browser?
- Should I use elements or attributes for my document?
- What's a namespace?
- Where can I get an XML parser?
- What's the difference between a well-formed document and a valid document?
- What's a validating parser?
- Should I use DOM or SAX for my application?
- How can I stop a SAX parser before it has parsed the entire document?
- 2005 Predictions
- 2006 Predictions
- Nick's Book Picks
One of the great features designed into Web services has been the notion that you can create a service automatically; in other words, you can type a few commands, and automatically create a client for service you want to access. This single capability is perhaps the greatest reason Web services are taken off as they have; without it, we'd all have to hand code to a fairly complicated specification.
So any tool that makes it easier to create clients is welcome; one that also allows us to easily create services is even more welcome. This month saw the release of Apache Axis2 1.0. The successor to the popular Apache Axis project, Axis2 has been completely rebuilt from the ground up. It includes the following features:
- Support for SOAP 1.1, SOAP 1.2, and REST
- Support for WSDL code generation, and no matter what the encoding/style
- Support for all message exchange patterns
- Support for both synchronous and asynchronous service clients
- Hot deployment of both the application and services
- The ability to obtain a service's WSDL, schema, and even policies easily
- Support for multiple transports, including HTTP, JMS, SMTP, and TCP
Axis2 also includes support for other standards, such as:
- Apache's new object model, AXIOM
- WS-Addressing (both the submission and final versions)
- WS-Policy
- WS-ReliableMessaging
- WS-Coordination
- WS-AtomicTransaction
- WS-Security
- WS-Addressing
Axis2 is built on a modular structure, enabling extension usually modules that can be enabled or disabled at both the application and the service-level. For example, at the time of this writing, modules provide support for the following recommendations:
- WS-ReliableMessaging
- WS-Coordination
- WS-AtomicTransaction
- WS-Security
- WS-Addressing
All right, so how do you actually do something with Axis2? Let's start with how easy it is to create an actual service. Consider, for example, a simple Java class:
package com.informit.xmlguide.candy; public class InventoryService{ public OMElement getInventory(OMElement prodInfo){ //Extract product number from prodInfo element and //return current inventory as an element } public void updateInventory(OMElement invInfo){ //Extract the product number and new inventory //value from invInfo element and act on it. } }
This is a simple class, with just two methods.
The first, getInventory()
, is a traditional
request-response method. You send it
information in the form of an OMElement
-- part of the AXIOM framework, this is
essentially just an XML element -- and it does some processing and returns
another OMElement. The second,
updateInventory()
, is an "in only" request, in that it doesn't
return any information at all.
The process of turning this into a Web service is pretty straightforward.
Once we have a class that
compiles, virtually all we need is a service.xml
file:
<service> <description> This is the inventory service, providing opportunities to both update and request inventory information. </description> <parameter name="ServiceClass" locked="false">com.informit.xmlguide.candy.InventoryService</parameter> <operation name="getInventory"> <messageReceiver class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/> <actionMapping>urn:getInventory</actionMapping> </operation> <operation name="updateInventory"> <messageReceiver class="org.apache.axis2.receivers.RawXMLINOnlyMessageReceiver"/> <actionMapping>urn:updateInventory</actionMapping> </operation> </service>
The service.xml
file tells Axis2 about the
service. It points out the class and the methods to be turned into operations.
It also specifies whether the service should use a "in-out"
receiver, or an "in only" receiver.
To actually deploy the service, you will need a "Axis2 Archive file", or
.aar
. Don't panic, though, it's just a jar file. To
create it, lay out your files as follows:
/service /META-INF service.xml InventoryService.class
You can then execute the following command from the serivce
directory:
jar -cf InventoryService.aar .
Deploying the service is a matter of uploading it to the
Axis2 application. The application,
which comes packaged as the axis2.war
file, must be deployed to a
container such as
Apache Tomcat or Apache Geronimo. From there, access
the Axis2 administration application by pointing your browser to:
http://localhost:8080/axis2
Click the "Administration" link and log in with the default
information, admin/axis2
. The Administration page gives you the opportunity to control many aspects
of the Axis2 application, including service parameters and modules. It also
gives you the opportunity to "hot deploy" a service to the running
application without having to restart the web application server.
Click "Upload service" and browse to the .aar
file you created earlier. Click "Upload". You can see the new service by
clicking on the "Available sources" link:
Notice that not only did Axis2 create the service, it created both a SOAP service and a REST service.
Axis2 also enables you to easily create services and clients from WSDL files. For example, if we had started with a WSDL file instead of a Java class, we could create the service by running the WSDL2Java script, located in the axis2/bin directory:
WSDL2Java -uri InventoryService.wsdl -ss -sd -p com.informit.xmlguide.candy -d xmlbeans -o service
In this case, we are telling the script to take the
inventoryService.wsdl
file and generate both the server side and service
description files, placing the classes in the com.informit.xmlguide.candy
package and using
Apache's xmlbeans
as the data binding method.
The output goes to the service
directory.>
This process can generate over 200 files, but the only one you're worried about is the "skeleton" file, in which you implement the actual service. For example:
package com.informit.xmlguide.candy; public class InventoryServiceSkeleton{ public com.informit.xmlguide.candy.xsd.GetInventoryReturnDocument getInventory (com.informit.xmlguide.candy.xsd.GetInventoryParamDocument param0 ) { //Implement the service here using data binding //and return a GetInventoryReturnDocument object } public void updateInventory (com.informit.xmlguide.candy.xsd.UpdateInventoryParamDocument param2 ) { //Implement the service } }
Once you implement the service, you need to create the .aar
file:
set ANT_HOME=e:\apache-ant-1.6.5 PATH=%PATH%;%ANT_HOME%\bin; set AXIS2_HOME=e:\axis2 cd service ant jar.service
As I said, the generation process creates a large amount of
files, so you wouldn't want to have to compile them by hand.
Fortunately, the generation process also
creates a build.xml
file for Apache Ant to use to compile the service.
The end result is the InventoryService.aar
file, which you deploy as before.
Creating a client can be just a simple. Again, you can use the WSDL2Java script:
WSDL2Java -uri ClassifiedService.wsdl -p com.informit.xmlguide.candy -d xmlbeans -o client
In this case, the important file is the "stub", which you can then use to create a client, as in:
package com.informit.xmlguide.candy; import axis2.apache.org.xsd.*; public class CandyClient{ public static void main(java.lang.String args[]){ try{ InventoryServiceStub stub = new InventoryServiceStub(null, "http://localhost:8080/axis2/services/InventoryService"); GetInventoryRequestDocument invReqDoc = GetInventoryRequestDocument.Factory.newInstance(); GetInventoryRequestDocument.GetInventoryRequest invReq = invReqDoc.addGetInventoryRequest(); invReq.setProductID("THX1138"); GetInventoryResponseDocument invResDoc = stub.getInventory(invReqDoc); System.out.println("Inventory: "+ invResDoc.getGetInventoryResponse().getInventory()); } catch(Exception e){ e.printStackTrace(); } } }
These classes are generated by the WSDL2Java script. The client
can also be compiled by Ant, this time using the jar.client
target.
Of course, this is just a cursory look at what Apache Axis2 can do. For more information, check out the resources that follow.