Discover and publish Web services with JAXR

The Java API for XML Registries allows registry operations over diverse registry providers

1 2 3 Page 3
Page 3 of 3
public void getOrganizationDetail(BulkResponse bulkResponse) 
throws JAXRException { 
    // Get a collection of Organizations from BulkResponse
    Collection organizations = bulkResponse.getCollection();
    // Iterate through the collection to get an individual Organization
    Iterator orgIter = organizations.iterator();
    while (orgIter.hasNext()) {
         Organization organization = (Organization);
         // Get a collection of Services from an Organization
         Collection services = organization.getServices();
         // Iterate through the collection to get an individual Service
         Iterator serviceIter = services.iterator();
         while (serviceIter.hasNext()) {
              Service service = (Service);
              // Get a collection of ServiceBindings from a Service
              Collection serviceBindings = service.getServiceBindings();
              // Iterate through the collection to get an individual ServiceBinding
              Iterator sbIter = serviceBindings.iterator();
              while (sbIter.hasNext()) {
                   ServiceBinding serviceBinding = (ServiceBinding); 
                   // Get URI of the service.  You can access the service through this URI.
                   String accessURI = serviceBinding.getAccessURI();
                   System.out.println("Access the service "  + 
service.getName().getValue() + " at this URI " + accessURI);
                   // Get a collection of SpecificationLinks from a ServiceBinding. 
                   // SpecificationLinks provide further technical details needed to access the 
                   Collection specificationLinks = serviceBinding.getSpecificationLinks();
                   // Iterate through the collection to get an individual SpecificationLink
                   Iterator linkIter = specificationLinks.iterator();
                   while (linkIter.hasNext()) {
                         SpecificationLink specificationLink = (SpecificationLink); 
                        // Get a collection of ExternalLinks from SpecificationLink 
                        // An ExternalLink points to technical detail necessary to invoke the service
                        Collection externalLinks = specificationLink.getExternalLinks();
                        // Iterate through the collection to get an ExternalLink
                        Iterator elinkIter = externalLinks.iterator();
                        while (elinkIter.hasNext()) {
                             ExternalLink externalLink = (ExternalLink);
                             // The externalURI is the pointer to the technical details 
                             // necessary to invoke the service
                             String externalURI = externalLink.getExternalURI();
                             System.out.println(" Use the technical detail at this URI, 
" + externalURI + " to invoke the service, " + service.getName().getValue());
                         // Obtain usage description
                         InternationalString usageDescription = specificationLink.getUsageDescription();
                         // Any parameters necessary to invoke service are in usageParameter collection
                         Collection usageParameters = specificationLink.
                         // Get the specification concept from the specification link
                         // This specificationConcept is equivalent to the tModel registered as the technical specification
                         Concept specificationConcept = (Concept) specificationLink.getSpecificationObject();

Registry operation: Publishing

The JAXR client also publishes Web services, another important registry operation. In addition to discovering partner organization information and services, an organization will want to register its information and services in the registry for partner use. If a JAXR client wishes to publish an organization and its services to a registry, the client uses the LifeCycleManager or the more focused BusinessLifeCycleManager. Clients familiar with UDDI should use the BusinessLifeCycleManager, which provides methods for saving information to the registry provider. Since this is a privileged operation, the user must set authentication information on the JAXR connection. Note that the JAXR provider, not the JAXR client, performs authentication with the registry provider. The JAXR provider negotiates this authentication with the registry provider on an as-needed basis, and the authentication is completely transparent to the JAXR client.

Suppose the organization Fly Away Airline Travel Agents has a Web-based airline reservation service that its partner travel agencies must be able to use. The following code creates such a business and saves it to the registry. The business has contact information, a set of services it offers, and technical information for accessing those services:

public void saveOrganization() 
throws JAXRException {
    // Create Organization in memory
    Organization org = businessLifeCycleManager.createOrganization
("Fly Away Airline Travel Agents");
   // Create User -- maps to Contact for UDDI
   User user = businessLifeCycleManager.createUser();
   PersonName personName = businessLifeCycleManager.createPersonName("Marie A Traveler");
   TelephoneNumber telephoneNumber = businessLifeCycleManager.createTelephoneNumber();
   Collection numbers = new ArrayList();
   EmailAddress email = 
   Collection emailAddresses = new ArrayList();
   Collection telephoneNumbers = new ArrayList();
   // Create service with service name and description
   Service service =  businessLifeCycleManager.createService("Fly Away Airline Reservation Service");
   service.setDescription(businessLifeCycleManager.createInternationalString("Flight Reservation Service"));
   // Create serviceBinding
   ServiceBinding serviceBinding = businessLifeCycleManager.createServiceBinding();
("Information for airline reservation service access"));
   //Turn validation of URI off
   // Create the SpecificationLink information
   SpecificationLink specificationLink = businessLifeCycleManager.createSpecificationLink();
   // Set usage description
createInternationalString("Search for Reservations when prompted"));
   String usageParameter = "Enter travel agent id when prompted"; 
   Collection usageParameters = new ArrayList();
   // Set usage parameters
   // Set specificationConcept on the specificationLink
   Concept httpSpecificationConcept = (Concept) businessLifeCycleManager.createObject(businessLifeCycleManager.CONCEPT);
   Key httpSpecificationKey = businessLifeCycleManager.createKey("uuid:68de9e80-ad09-469d-8a37-088422bfbc36");
   // Add the specificationLink to the serviceBinding
   // Add the serviceBinding to the service
   // Add the service to the organization
   // Add classifications to the organization
   ClassificationScheme naics = businessQueryManager.findClassificationSchemeByName(null, "ntis-gov:naics");
   Classification classification = businessLifeCycleManager.createClassification
(naics, "Air Transportation", "481");
   Collection orgs = new ArrayList();
   BulkResponse br = businessLifeCycleManager.saveOrganizations(orgs);
   if (br.getStatus() == JAXRResponse.STATUS_SUCCESS) {
       System.out.println("Successfully saved the " + " organization 
to the registry provider .");

JAXR implementations

We know you will want to get started developing Web service applications using JAXR, perhaps using the programming examples shown above. How do you get JAXR implementations? A typical JAXR implementation comes with three software modules: a registry provider designed for a particular registry specification, like UDDI or ebXML; a JAXR provider for a particular registry provider; and a registry browser.

Currently two JAXR provider implementations are available for use with current UDDI and ebXML registry providers. The JWSDP 1.0 includes the JAXR 1.0 reference implementation that consists of a UDDI Version 2.0 JAXR provider, a UDDI 2.0 RegistryServer, and registry browser. As mentioned previously, the open source community is currently developing an ebXML 2.0 JAXR provider and an ebXML 2.0 registry. Figure 3 shows the registry browser that comes with the JAXR reference implementation; you can use the browser to add organizations and their categorized services to a UDDI registry provider.

Figure 3. Registry browser

Get started developing Web services

JAXR provides a standard Java API and unified information model for performing registry operations over diverse registry providers, especially over the UDDI and ebXML registry providers. Typical registry operations include publication and discovery of Web services. To accommodate various functionalities from different registry providers, JAXR offers a layered architecture, where capabilities are grouped as a capability profile. A level 0 capability profile provides a simple, yet focused and high-level business API, while a level 1 capability profile provides a flexible, low-level, and generic API. You should familiarize yourself with JAXR, as it will become an important part of J2EE 1.4, the Java-based platform for Web services development and deployment.

Sang Shin is a Java technology evangelist for Sun Microsystems. He frequently talks about important Java technologies such as Jini, J2EE, EJB, JMS (Java Message Service), J2ME (Java 2 Platform, Micro Edition), Java and XML, and Web services technologies. He also teaches several software engineering courses at Brandeis University in Waltham, Mass. Kathy Walsh is a member of the technical staff in the XML Web services group and the implementation lead for JAXR at Sun. In her previous life, she was involved in EAI (enterprise application integration) and OSS (operation support system) development, network management, and network application programming development.

Learn more about this topic

1 2 3 Page 3
Page 3 of 3