Web application developers must deal with a number of distributed registries, each with its own API or protocol. Sometimes specifications overlap; this is the case with Electronic Business using Extensible Markup Language (ebXML), eCo Framework, and Universal Description, Discovery, and Integration (UDDI). The Java API for XML Registries (JAXR) aims to unify these approaches so that each may be used as needed in an automatic fashion.
JAXR defines a standard API for Java platform applications to access and programmatically interact with various kinds of metadata registries. The JAXR API was developed under the Java Community Process as JSR 93. JAXR standardizes approaches for accessing any kind of XML-based registry.
This is very important for me because, in my early experiences with XML applications, I used UDDI as a metadata registry for my applications, along with a self-written UDDI reading/writing engine. I had problems when the registry changed its structure or the environment stopped supporting my engine, and no third-party UDDI engines helped because they all had the same problems.
Current implementations of JAXR support ebXML Registry version 2.0 and UDDI version 2.0. JAXR provides an API for the clients to interact with XML registries and a service provider interface (SPI) for the registry providers so they can plug in their registry implementations. The JAXR API insulates application code from the underlying registry mechanism. When writing a JAXR-based client to browse or populate a registry, the code does not have to change if the registry changes, for instance from UDDI to ebXML.
What is a registry?
Typically, an XML registry is an infrastructure that enables the building, deployment, and discovery of Web services. A registry is available to organizations as a shared resource, often also in the form of a Web-based service.
Popular specifications for XML registries are the ebXML Registry and Repository standard sponsored by OASIS, and the UDDI, which is being developed by a consortium of vendors.
A registry provider is an implementation of a business registry that conforms to a specification for XML registries. A registry is a key component in any Web services architecture because it provides the ability for parties to publish, discover, and use Web services.
Registries provide the following functionality:
- Electronic yellow pages: An independent online information exchange service that allows Web service providers to advertise their product and Web service consumers to discover these products. The registry can classify these Web services in arbitrary and flexible ways, such as the industry it belongs to, its geographic location, the product it sells, and so on.
- Database of static data: The registry essentially allows applications to store relatively static data reliably and to share it easily with other applications.
- A registry also provides a way to exchange dynamic content between parties, such as price changes, discounts, promotions, and so on.
Discover how JAXR works
The high-level architecture of JAXR consists of the following parts:
- A JAXR client: A client program that uses the JAXR API to access a business registry via a JAXR provider.
- A JAXR provider: An implementation of the JAXR API that provides access to a specific registry provider or to a class of registry providers that are based on a common specification.
Two main packages must be implemented by a JAXR provider:
- javax.xml.registry, which consists of the API interfaces and classes that define the registry access interface.
- javax.xml.registry.infomodel, which consists of interfaces that define the information model for JAXR. These interfaces define the types of objects that reside in a registry and how they relate to each other. The basic interface in this package is the RegistryObject interface. Its subinterfaces include Organization, Service, and ServiceBinding.
The most basic interfaces in the javax.xml.registry package are:
- Connection: The Connection interface represents a client session with a registry provider. The client must create a connection with the JAXR provider in order to use a registry.
- RegistryService: The client obtains a RegistryService object from its connection. The RegistryService object enables the client to obtain the interfaces it uses to access the registry.
In the same package javax.xml.registry, there are two main interfaces: BusinessQueryManager and BusinessLifeCycleManager.
- BusinessQueryManager allows the client to search a registry for information in accordance with the javax.xml.registry.infomodel interfaces. An optional interface, DeclarativeQueryManager, allows the client to use SQL syntax for queries. (The implementation of JAXR in the J2EE SDK does not implement DeclarativeQueryManager.)
- BusinessLifeCycleManager allows the client to modify the information in a registry by saving it (updating it) or deleting it.
When an error occurs, JAXR API methods throw a JAXRException or one of its subclasses.
Many methods in the JAXR API use a Collection object as an argument or a returned value. Using a Collection object allows operations on several registry objects at a time.
Let's look at a simple JAXR example provided in the Java Web Services Developer Pack 1.5 and 2.0 to show how the JAXR API can be used by a Java client application to access a business registry in the Internet.A client must establish the connection to registry. As shown in Listing A, establishing a connection has three steps. First, it creates an instance of abstract class ConnectionFactory. Next, the client creates a set of properties that specify the URL or URLs of the registry or registries being accessed. In Listing A, the code provides the URLs of the query service and publishing service for the IBM test registry. A client can also specify proxy host and port information for the network on which the client is running if needed (for example, if it's behind a firewall). For queries, the client might need to specify only the HTTP proxy host and port. For updates, the client typically also needs to specify a HTTPS proxy host and port. The client then sets the properties for the ConnectionFactory and creates the connection with the createConnection() method of ConnectionFactory. When the connection is created and established, the client uses the connection to obtain a RegistryService object. It then uses the RegistryService to get objects that implement the appropriate query interfaces, as shown in Listing B. If a client needs to read and write data to a registry, it should obtain a BusinessQueryManager object and a BusinessLifeCycleManager object from the RegistryService object. If the client is only performing simple queries, it typically needs only a BusinessQueryManager object.
After getting a registry service object, the client application can start querying a registry. The simplest way for a client to use a registry is to query it for information about the organizations that have submitted data to it. The BusinessQueryManager interface supports a number of find methods that allow clients to search for data using the JAXR information model. Many of these methods return a BulkResponse (a collection of objects) that meets a set of criteria specified in the method arguments. The most useful of these methods are findOrganizations(),findServices(), and findServiceBindings(). Here's more information about these methods:
- findOrganizations() returns a list of organizations that meet the specified criteria -- often a name pattern or a classification within a classification scheme.
- findServices() returns a set of services offered by a specified organization.
- findServiceBindings() returns the service bindings (information about how to access the service) that are supported by a specified service.
There's a lot more than you do using JAXR, such as authorizing within registries and managing registry data (creating organizations and services, adding classifications, adding and removing services, and service bindings to an organization, etc.).
JAXR enables Java programmers to use a single, easy-to-use abstraction API to access a variety of XML registries. Simplicity and ease of use are facilitated within JAXR by a unified JAXR information model, which describes content and metadata within XML registries. JAXR provides rich metadata capabilities for classification and association, as well as rich query capabilities. As an abstraction-based API, JAXR gives developers the ability to write registry client programs that are portable across different target registries.
The JAXR API is included, along with other Web services technologies, in the open-source Java EE5-compliant application server at Project GlassFish. The JAXR project at java.net lets developers download the implementation and participate in ongoing development. Other resources include an Apache implementation of JAXR called Apache Scout and a free ebXML implementation of JAXR.
Peter V. Mikhalenko is a Sun certified professional who works as a business and technical consultant for several top-tier investment banks.
---------------------------------------------------------------------------------------Get weekly development tips in your inbox Keep your developer skills sharp by signing up for TechRepublic's free Web Developer newsletter, delivered each Tuesday. Automatically subscribe today!