Sun ONE logo      Previous      Contents      Index      Next     

Sun ONE Application Server 7 Developer's Guide to Web Services

Chapter 4
Clients Using JAXR

Application Server provides the ability for the clients to publish, discover, and manage content within XML registries using the implementation of JavaTM API for XML Registry (JAXR).

This chapter describes the procedure to develop clients that can interact with the registry to perform various operations on the registry. This chapter contains the following sections:


Developing a JAXR Client

This section describes the steps required to implement a JAXR client that can perform queries and update a registry.

Before you develop a JAXR client, make sure to setup your client environment. For detailed information on setting up your client environment, see "Setting Up the Client Environment".

Implementing a JAXR client involves the following steps:

Getting Access to a Registry

You must obtain permission from the registry to access the registry. A JAXR client can then perform queries, add data to registry, or update registry data. To register with one of the public UDDI version 2 registries, go to one of the following Web sites and follow the instructions:

http://uddi.microsoft.com/ (Microsoft)

https://uddi.ibm.com/ubr/registry.html (IBM)

When you register, you will obtain a user name and password. To run samples bundled with Sun ONE Application Server, you may register with IBM’s UDDI registry.

Accessing an ebXML Registry

An ebXML registry allows you to publish and discover Web services. Unlike a UDDI registry, an ebXML registry can store the metadata about a service and arbitrary content such as, the actual Web service description, that is the WSDL document.

For more information on ebXML, visit the following URL:

http://www.ebxml.org

Sun ONE Application Server supports JAXR clients to access an ebXML registry through a third-party JAXR provider. The ebxmlrr-client is a package that provides an implementation of the JAXR API that is compatible with the OASIS ebXML Registry V2.x (version 2.0 and 2.1) standard. The ebxmlrr-client package also includes a Registry Browser application that can graphically browse any OASIS ebXML V2.x registry.

For more information, visit the following URL:

http://ebxmlrr.sourceforge.net

Establishing a Connection

The first task a JAXR client must perform is, to establish a connection to a registry. This connection contains the client state and preference information used when the JAXR provider invokes methods on the registry provider.


Note

In order to add data to the registry or to update registry data, the client must set authentication information on the connection. The establishment of this authentication information with the registry provider is specific to that registry provider.


Create a connection from a connection factory. A JAXR provider may supply one or more pre configured connection factories that clients can look up using the JNDI API.

The following code illustrates how to establish a connection to a JAXR provider:

import javax.xml.registry.*;

...

public void makeConnection(String queryURL, String publishURL)

{

ConnectionFactory factory = ConnectionFactory.newInstance();

.....

}

In the code above, queryURL and publishURL are the URL of the query and publish registries respectively.

Setting Properties

The implementation of JAXR API in Sun ONE Application Server allows you to set a number of properties on a JAXR connection. The following table list the standard JAXR connection properties and properties specific to implementation of JAXR in Sun ONE Application Server. The first column shows the name of the property and the description of that property, the second column shows the data type that you can use with the property, and the third column shows the default value associated with the property.

Table 4-1  Standard JAXR Connection Properties

Property Name and Description

Data type

Default Value

javax.xml.Registry.queryManagerURL

Specifies the URL of the query manager service within the target registry provider

String

None

javax.xml.registry.lifeCycleManagerURL

Specifies the URL of the life cycle manager service within the target registry provider (for registry updates)

String

Same as the specified queryManagerURL value

javax.xml.registry.semanticEquivalences

Specifies semantic equivalences of concepts as one or more tuples of the ID values of two equivalent concepts separated by a comma; the tuples are separated by vertical bars: id1,id2|id3,id4

String

None

javax.xml.registry.security.
authenticationMethod

Provides a hint to the JAXR provider on the authentication method to be used for authenticating with the registry provider

String

None;

UDDI_GET_AUTHTOKEN is the only supported value

javax.xml.registry.uddi.maxRows

The maximum number of rows to be returned by find operations. Specific to UDDI providers

Integer

None

javax.xml.registry.postalAddressScheme

The ID of a ClassificationScheme to be used as the default postal address scheme.

String

None

Table 4-2  Sun ONE-specific JAXR Implementation Connection Properties

Property Name and Description

Data type

Default Value

com.sun.xml.registry.http.proxyHost

Specifies the HTTP proxy host to be used for accessing external registries.

String

Proxy host value specified in <which file>?

com.sun.xml.registry.http.proxyPort

Specifies the HTTP proxy port to be used for accessing external registries; usually 8080

String

Proxy port value specified in <which file>?

com.sun.xml.registry.https.proxyHost

Specifies the HTTPS proxy host to be used for accessing external registries

String

Same as HTTP proxy host value

com.sun.xml.registry.https.proxyPort

Specifies the HTTPS proxy port to be used for accessing external registries; usually 8080

String

Same as HTTP proxy port value

com.sun.xml.registry.http.proxyUserName

Specifies the user name for the proxy host for HTTP proxy authentication, if one is required

String

None

com.sun.xml.registry.http.proxyPassword

Specifies the password for the proxy host for HTTP proxy authentication, if one is required

String

None

com.sun.xml.registry.useCache

Tells the JAXR implementation to look for registry objects in the cache first and then to look in the registry if not found

Boolean, passed in as String

True

com.sun.xml.registry.useSOAP

Tells the JAXR implementation to use Apache SOAP rather than the Java API for XML Messaging; may be useful for debugging

Boolean, passed in as String

False

You can set these properties as shown in the code below:

String queryURL = "http://www-3.ibm.com/services/uddi/v2beta/inquiryapi";

String publishURL= "https://www-3.ibm.com/services/uddi/v2beta/protect/publishapi";

Properties props = new Properties();

props.setProperty("javax.xml.registry.queryManagerURL", queryUrl);

props.setProperty("javax.xml.registry.lifeCycleManagerURL", publishUrl);

Creating a Connection

A client first creates a set of properties that specify the URL or URLs of the registry or registries being accessed.

The client then sets the properties for the connection properties and creates the connection.

factory.setProperties(props);

Connection connection = factory.createConnection();

Obtaining the RegistryService and Managers

The client uses the connection to obtain a RegistryService object and then the interface or interfaces it will use. The following code illustrates how to obtain the registry service:

RegistryService rs = connection.getRegistryService();

BusinessQueryManager bqm = rs.getBusinessQueryManager();

BusinessLifeCycleManager blcm = rs.getBusinessLifeCycleManager();

Setting Client Authentication Information

The following code illustrates how to set the client authorization information for privileged registry operations:

PasswordAuthentication passwdAuth = new PasswordAuthentication(username, password.toCharArray());

Set creds = new HashSet();

creds.add(passwdAuth);

Querying a Registry

The client uses the registry by querying it for information about the organization that have submitted data to it. The client can query the registry based on one or more of the following criterion:

This section describes the procedure to query a registry based on the following criterion:

Finding Organizations by Name

To find an organization by name, you use a combination of find qualifiers (which affect sorting and pattern matching) and name patterns (which specify the strings to be searched). The findOrganizations method takes a collection of findQualifier as its first argument and a collection of namePattern objects as its second argument.

The following code illustrates the use of findOrganizations method to search for an organization whose name begins with a specific string qString, and to sort them in alphabetical order:

Collection findQualifiers = new ArrayList();

findQualifiers.add(FindQualifier.SORT_BY_NAME_DESC);

namePatterns.add(qString);

The above code lines define the find qualifiers and name patterns.

To find an organization using the name, use the findOrganizations() method as shown in the code illustration below:

BulkResponse response = bqm.findOrganizations(findQualifiers, namePatterns, null, null, null, null);

Collection orgs = response.getCollection();

Finding Organizations by Classification

To find an organization by classification, you need to establish a classification within a particular classification scheme and specify the classification as a parameter to the findOrganizations() method.

Let us assume that you are browsing the UDDI registry and wish to find an organization that provides services of the NAICS (North American Industry Classification System) type Computer Systems Design and Related Services in the United States. To perform this query with JAXR, invoke a findOrganizations() method with classification listed under the well-known taxonomies NAICS and ISO 3166 Geographic Code System (ISO 3166). As JAXR provides a taxonomy service for these classifications, the client can easily access the classification information needed to be passed as findOrganization() parameters.

ClassificationScheme cScheme = bqm.findClassificationSchemeByName (null, "ntis-gov:naics");

Classification classification = (Classification)blcm.createClassification(cScheme, "Snack and Nonalcoholic Beverage Bars", "722213");

Collection classifications = new ArrayList();

classifications.add(classification);

// make JAXR request

BulkResponse response = bqm.findOrganizations(null, null, classifications, null, null, null);

Collection orgs = response.getCollection();

Finding Organizations by WSDL Descriptions

You can find organizations based on technical specifications that take the form of WSDL documents. In JAXR, a concept is used as a proxy to hold the specification. The client must find the specification concepts first, then the organizations that use those concepts.

The following code illustrates finding an organization based on the WSDL specification instances used within a given registry.

String schemeName = "uddi-org:types";

ClassificationScheme uddiOrgTypes = bqm.findClassificationSchemeByName(null, schemeName);

/*

* Create a classification, specifying the scheme
* and the taxonomy name and value defined for WSDL
* documents by the UDDI specification.

*/

Classification wsdlSpecClassification = blcm.createClassification(uddiOrgTypes, "wsdlSpec", "wsdlSpec");

ArrayList classifications = new ArrayList(); classifications.add(wsdlSpecClassification);

// Find concepts

BulkResponse br = bqm.findConcepts(null, null, classifications, null, null);

Next, you must go through the concepts, find the WSDL documents they correspond to, and display the organizations that use each document:

// Display information about the concepts found

Collection specConcepts = br.getCollection();

Iterator iter = specConcepts.iterator();

if (!iter.hasNext()) {

  System.out.println("No WSDL specification concepts found");

  } else {

  while (iter.hasNext()) {

  try{

  Concept concept = (Concept) iter.next();
  String name = getName(concept);
  Collection links = concept.getExternalLinks();
  System.out.println("\nSpecification Concept:\n Name: " +name + "\n Key: " + concept.getKey().getId() + "\n Description: " + getDescription(concept));
  if (links.size() > 0) {

    ExternalLink link =
    (ExternalLink) links.iterator().next();
    System.out.println("URL of WSDL document: ’" link.getExternalURI() + "’");

}

// Find organizations that use this concept

ArrayList specConcepts1 = new ArrayList();

specConcepts1.add(concept);

br = bqm.findOrganizations(null, null, null, specConcepts1, null, null);

Collection orgs = br.getCollection();

// Display information about organizations

... }

Finding Services and Service Bindings

A JAXR client can find an organization’s services and the service bindings associated with those using the getService() and the getServiceBindings() method respectively. The following code illustrates the use of the getServices() and getServiceBindings() method:

Iterator orgIter = orgs.iterator();

while (orgIter.hasNext()) {

  Organization org = (Organization) orgIter.next();

  Collection services = org.getServices();

  Iterator svcIter = services.iterator();

  while (svcIter.hasNext()) {

    Service svc = (Service) svcIter.next();

    Collection serviceBindings = svc.getServiceBindings();  

    Iterator sbIter = serviceBindings.iterator();

    while (sbIter.hasNext()) {

      ServiceBinding sb =

        (ServiceBinding) sbIter.next();

    }

  }

}


Managing Registry Data

A JAXR client can submit data to a registry, modify the existing registry data, and remove data from the registry. A JAXR client must be authorized to manage the registry data. A client that has submitted data to the registry can only remove or modify it.

This section describes the following tasks:

Getting Authorization from the Registry

The JAXR client sends its user name and password to the registry in a set of credentials on the connection. These credentials may be used by the provider to authenticate with the registry.

// Edit to provide your own username and password
String username = "";
String password = "";

// Get authorization from the registry

PasswordAuthentication passwdAuth = new PasswordAuthentication(username, password.toCharArray());

Set creds = new HashSet();
creds.add(passwdAuth);
connection.setCredentials(creds);

Creating an Organization

A JAXR client creates the organization and populates it with the data before saving it. The Organization object is used to create an organization. This object includes the following objects:

The following code illustrates how you can create an organization using the Organization method:

// Create Organization in memory

Organization org = businessLifeCycleManager.createOrganization ("Sun Microsystems");

// Create User -- maps to Contact for UDDI

User user = businessLifeCycleManager.createUser();

PersonName personName = businessLifeCycleManager.createPersonName("Bob");

TelephoneNumber telephoneNumber = businessLifeCycleManager.createTelephoneNumber();

telephoneNumber.setNumber("650-241-8979");

telephoneNumber.setType("office");

Collection numbers = new ArrayList();

numbers.add(telephoneNumber);

EmailAddress email = businessLifeCycleManager.createEmailAddress("bob@sun.com", "office");

Collection emailAddresses = new ArrayList(); emailAddresses.add(email);

user.setPersonName(personName);

Collection telephoneNumbers = new ArrayList();

telephoneNumbers.add(telephoneNumber);

user.setTelephoneNumbers(telephoneNumbers);

user.setEmailAddresses(emailAddresses);

org.setPrimaryContact(user);

Adding Classifications

Organizations commonly belong to one or more classifications within one or more classification schemes or taxonomies. To establish a classification for an organization within a taxonomy, the client first locates the taxonomy using the BusinessQueryManager. The findClassificationSchemeByName method takes a set of FindQualifier objects as its first argument, but this argument can be null.

// Set classification scheme to NAICS

ClassificationScheme cScheme = bqm.findClassificationSchemeByName(null, "ntis-gov:naics");

The client then creates a classification. For example, the following code sets up a classification for the organization within the NAICS taxonomy.

// Create and add classification

Classification classification = (Classification) blcm.createClassification(cScheme, "Snack and Nonalcoholic Beverage Bars", "722213");

Collection classifications = new ArrayList(); classifications.add(classification); org.addClassifications(classifications);

Services also use classifications, so you can use similar code to add a classification to a Service object.

Using Taxonomies

A taxonomy is represented by a ClassificationScheme object. This section describes how to use the implementation of JAXR in:

Defining Taxonomies

The JAXR specification requires a JAXR provider to be able to add user-defined taxonomies that can be used by JAXR clients. The implementation of JAXR in Sun ONE Application Server uses a simple file-based approach to provide taxonomies to the JAXR client. These files are read at run time, when the JAXR provider starts up.

The taxonomy structure is defined by the JAXR Predefined Concepts DTD, which is declared both in the file jaxrconcepts.dtd and in XML schema form in the file jaxrconcepts.xsd. The file jaxrconcepts.xml contains the taxonomies for the implementation of JAXR. All these files are contained in the install_dir/share/lib/jaxr-impl.jar file.

To add a user-defined taxonomy, follow the procedure given below:

Publish the JAXRClassificationScheme element for the taxonomy as a ClassificationScheme object in the registry that you will be accessing. For example, you can publish the ClassificationScheme object to the UDDI Registry Server. In order to publish a ClassificationScheme object, you must set its name. You also give the scheme a classification within a known classification scheme such as uddi-org:types. In the following code line, the name is the first argument of the LifeCycleManager.createClassificationScheme method call.

ClassificationScheme cScheme = blcm.createClassificationScheme("MyScheme", "A Classification Scheme");

ClassificationScheme uddiOrgTypes = bqm.findClassificationSchemeByName(null, "uddi-org:types");

if (uddiOrgTypes != null)

{

Classification classification = blcm.createClassification(uddiOrgTypes,"postalAddress", "categorization" );

postalScheme.addClassification(classification);

ExternalLink externalLink = blcm.createExternalLink("http://www.mycom.com/myscheme.html","My Scheme");

postalScheme.addExternalLink(externalLink);

Collection schemes = new ArrayList();

schemes.add(cScheme);

BulkResponse br = blcm.saveClassificationSchemes(schemes);

}

//The BulkResponse object returned by the saveClassificationSchemes method contains the key for the classification scheme, which you need to retrieve

if (br.getStatus() == JAXRResponse.STATUS_SUCCESS) {

System.out.println("Saved ClassificationScheme");

Collection schemeKeys = br.getCollection();

Iterator keysIter = schemeKeys.iterator();

while (keysIter.hasNext())

{

javax.xml.registry.infomodel.Key key = (javax.xml.registry.infomodel.Key) keysIter.next();

System.out.println("The postalScheme key is " + key.getId());

System.out.println("Use this key as the scheme" + " uuid in the taxonomy file");

}

}

In an XML file, define a taxonomy structure that is compliant with the JAXR Predefined Concepts DTD. Enter the ClassificationScheme element in your taxonomy XML file by specifying the returned key ID value as the id attribute and the name as the name attribute. For example, the opening tag for the JAXRClassificationScheme element looks something like this (all on one line):

<JAXRClassificationScheme id="uuid:nnnnnnnn-nnnn-nnnn-nnnn- nnnnnnnnnnnn" name="MyScheme">

The ClassificationScheme id must be a UUID.

Enter each JAXRConcept element in your taxonomy XML file by specifying the following four attributes, in this order:

    1. id is the JAXRClassificationScheme id value, followed by a / separator, followed by the code of the JAXRConcept element
    2. name is the name of the JAXRConcept element
    3. parent is the immediate parent id (either the ClassificationScheme id or that of the parent JAXRConcept)
    4. code is the JAXRConcept element code value
    5. The first JAXRConcept element in the naics.xml file looks like this (all on one line):

      <JAXRConcept id="uuid:C0B9FE13-179F-413D-8A5B-5004DB8E5BB2/11" name="Agriculture, Forestry, Fishing and Hunting"
      parent="uuid:C0B9FE13-179F-413D-8A5B-5004DB8E5BB2" code="11"></JAXRConcept>

To add the user-defined taxonomy structure to the JAXR provider, specify the system property com.sun.xml.registry.userTaxonomyFilenames when you run your client program. The command line (all on one line) would look like this. A vertical bar (|) is the file separator.

java myProgram -DuserTaxonomyFilenames=c:\myfile\xxx.xml|c:\myfile\xxx2.xml

You can use a <sysproperty> tag to set this property in a build.xml file. Or, in your program, you can set the property as follows:

System.setProperty ("com.sun.xml.registry.userTaxonomyFilenames", "c:\myfile\xxx.xml|c:\myfile\xxx2.xml");

Specifying Postal Address

The JAXR specification defines a postal address as a structured interface with attributes for street, city, country, and so on. The UDDI specification, on the other hand, defines a postal address as a free-form collection of address lines, each of which may also be assigned a meaning. To map the JAXR PostalAddress format to a known UDDI address format, you specify the UDDI format as a ClassificationScheme object and then specify the semantic equivalences between the concepts in the UDDI format classification scheme and the comments in the JAXR PostalAddress classification scheme. The JAXR PostalAddress classification scheme is provided by the JAXR implementation of Sun ONE Application Server. A PostalAddress object has the fields streetNumber, street, city, state, postalCode, and country. These are predefined concepts in the postalconcepts.xml file, within the ClassificationScheme named PostalAddressAttributes.

To specify the mapping between the JAXR postal address format and another format, you need to set two connection properties:

First, you specify the postal address scheme using the id value from the JAXRClassificationScheme element (the UUID).

// Set properties for postal address mapping using my scheme props.setProperty("javax.xml.registry.postalAddressScheme",
uuid:6eaf4b50-4196-11d6-9e2b-000629dc0a2b");

Next, you specify the mapping from the id of each JAXRConcept element in the default JAXR postal address scheme to the id of its counterpart in the IBM scheme:

props.setProperty("javax.xml.registry.semanticEquivalences", urn:uuid:PostalAddressAttributes/StreetNumber," + "urn:uuid:6eaf4b50-4196-11d6-9e2b-000629dc0a2b/StreetAddressNumb er|" +
"urn:uuid:PostalAddressAttributes/Street," + "urn:uuid:6eaf4b50-4196-11d6-9e2b-000629dc0a2b/StreetAddress|" + "urn:uuid:PostalAddressAttributes/City," + "urn:uuid:6eaf4b50-4196-11d6-9e2b-000629dc0a2b/City|" + "urn:uuid:PostalAddressAttributes/State," + "urn:uuid:6eaf4b50-4196-11d6-9e2b-000629dc0a2b/State|" + "urn:uuid:PostalAddressAttributes/PostalCode," + "urn:uuid:6eaf4b50-4196-11d6-9e2b-000629dc0a2b/ZipCode|" + "urn:uuid:PostalAddressAttributes/Country," + "urn:uuid:6eaf4b50-4196-11d6-9e2b-000629dc0a2b/Country");

After you create the connection using these properties, you can create a postal address and assign it to the primary contact of the organization before you publish the organization.

For example,

String streetNumber = “99”;
String street = “Imaginary Ave. Suite 33”;
String city = "Imaginary City";
String state = "NY";
String country = "USA";
String postalCode = "00000";
String type = "";
PostalAddress postAddr =
blcm.createPostalAddress(streetNumber, street, city, state, country, postalCode, type);
Collection postalAddresses = new ArrayList();
postalAddresses.add(postAddr);
primaryContact.setPostalAddresses(postalAddresses);

A JAXR query can then retrieve the postal address using PostalAddress methods, if the postal address scheme and semantic equivalences for the query are the same as those specified for the publication. To retrieve postal addresses when you do not know what postal address scheme was used to publish them, you can retrieve them as a collection of Slot objects. The JAXRQueryPostal.java sample program shows how to do this.

Adding Services and Service Bindings to an Organization

Many organizations add themselves to a registry in order to offer services, so the JAXR API has facilities to add services and service bindings to an organization.

Like an Organization object, a Service object has a name and a description. Also like an Organization object, it has a unique key that is generated by the registry when the service is registered. It may also have classifications associated with it.

A service also commonly has service bindings, which provide information about how to access the service. A ServiceBinding object normally has a description, an access URI, and a specification link, which provides the linkage between a service binding and a technical specification that describes how to use the service using the service binding.

The following code illustrates how to create a collection of services, add service bindings to a service, then add the services to the organization. It specifies an access URI but not a specification link. Because the access URI is not real and because JAXR by default checks for the validity of any published URI, the binding sets the validateURI property to false.

// Create services and service

Collection services = new ArrayList();
Service service = blcm.createService("My Service Name");
InternationalString is = blcm.createInternationalString("My Service Description");
service.setDescription(is);

// Create service bindings

Collection serviceBindings = new ArrayList();
ServiceBinding binding = blcm.createServiceBinding();
is = blcm.createInternationalString("My Service Binding " + "Description");
binding.setDescription(is);

binding.setValidateURI(false);
binding.setAccessURI("http://TheCoffeeBreak.com:8080/sb/");
serviceBindings.add(binding);

// Add service bindings to service
service.addServiceBindings(serviceBindings);

// Add service to services, then add services to organization
services.add(service);
org.addServices(services);


Publishing a Web Service to a UDDI Registry

JAXR provides the facility to publish your Web services to the UDDI registry. This section describes the steps to publish an existing Web service to the registry:

Publishing a service to a registry involves the following steps:

To create a JAXR client that publishes a Web service to the registry, import the following required packages:

import javax.xml.registry.*;
import javax.xml.registry.infomodel.*;
import java.net.*;
import java.security.*;
import java.util.*;

Create a class that consists of a main method, a makeConnection method that establishes the connection to the registry, and an executePublish method, that publishes all the information about the service to the registry. The following code illustrates the creation of the main class JAXRPublish:

public class JAXRPublish {

Connection connection = null;

public JAXRPublish() {}

public static void main(String[] args) {

String queryURL = "http://www-3.ibm.com/services/uddi/v2beta/inquiryapi";

String publishURL = "https://www-3.ibm.com/services/uddi/v2beta/protect/publishapi";

String username = "";

String password = "";

JAXRPublish jp = new JAXRPublish();

jp.makeConnection(queryURL, publishURL);

jp.executePublish(username, password);

}

The JAXR client must establish a connection to the UDDI registry and set the connection configuration properties. For detailed information, see "Establishing a Connection".

Create the connection, passing it the configuration properties. For detailed information, see "Creating a Connection".

Create an organization, its classification, its services, and save it to the registry.

For more information, see the following sections:

The following code illustrates the steps to publish a Web service:

public void executePublish(String username, String password) { RegistryService rs = null;
BusinessLifeCycleManager blcm = null;
BusinessQueryManager bqm = null;

String orgName = "The Coffee Break";
String orgDesc = "Purveyor of the finest coffees. Established 1895"; String contactName = "Jane Doe";
String contactPhone = "(800) 555-1212";
String contactEmail = "jane.doe@TheCoffeeBreak.com";
String serviceName = "My Service Name";
String serviceDesc = "My Service Description";
String serviceBindingDesc = "My Service Binding Description";
String serviceBindingURI = "http://localhost:1024";
String scheme = "ntis-gov:naics";
String conceptName = "Snack and Nonalcoholic Beverage Bars";
String conceptCode = "722213";
try {

java.io.BufferedInputStream bfInput = null;
Properties propTemp = new Properties();
bfInput = new java.io.BufferedInputStream (new java.io.FileInputStream("jaxr.properties"));
propTemp.load(bfInput);
bfInput.close();orgName = propTemp.getProperty("org-name");
orgDesc = propTemp.getProperty("org-desc");
contactName = propTemp.getProperty("contact-name");
contactPhone = propTemp.getProperty("contact-phone");
contactEmail = propTemp.getProperty("contact-email");
serviceName = propTemp.getProperty("service-name");
serviceDesc = propTemp.getProperty("service-desc");
serviceBindingDesc = propTemp.getProperty("service-binding-desc");
serviceBindingURI = propTemp.getProperty("service-binding-uri");
scheme = propTemp.getProperty("scheme");
conceptName = propTemp.getProperty("concept");
conceptCode = propTemp.getProperty("concept-code");
}

try {

rs = connection.getRegistryService();
blcm = rs.getBusinessLifeCycleManager();
bqm = rs.getBusinessQueryManager();
System.out.println("Got registry service, query " + "manager, and life cycle manager");

// Get authorization from the registry

PasswordAuthentication passwdAuth = new PasswordAuthentication(username,password.toCharArray());
Set creds = new HashSet();
creds.add(passwdAuth);
connection.setCredentials(creds);
System.out.println("Established security credentials");

// Create organization name and description

Organization org = blcm.createOrganization(orgName);
InternationalString s = blcm.createInternationalString(orgDesc);
org.setDescription(s);

// Create primary contact, set name

User primaryContact = blcm.createUser();
PersonName pName = blcm.createPersonName(contactName);
primaryContact.setPersonName(pName);

// Set primary contact phone number

TelephoneNumber tNum = blcm.createTelephoneNumber();
tNum.setNumber(contactPhone);
Collection phoneNums = new ArrayList();
phoneNums.add(tNum);
primaryContact.setTelephoneNumbers(phoneNums);

// Set primary contact email address

EmailAddress emailAddress = blcm.createEmailAddress(contactEmail);
Collection emailAddresses = new ArrayList();
emailAddresses.add(emailAddress);
primaryContact.setEmailAddresses(emailAddresses);

// Set primary contact for organization

org.setPrimaryContact(primaryContact);

// Set classification scheme to NAICS

ClassificationScheme cScheme = bqm.findClassificationSchemeByName(null,scheme);

if (cScheme != null) {

// Create and add classification

Classification classification = (Classification)
blcm.createClassification(cScheme, conceptName, conceptCode);
Collection classifications = new ArrayList();
classifications.add(classification);
org.addClassifications(classifications);
}

// Create services and service

Collection services = new ArrayList();
Service service = blcm.createService(serviceName);
InternationalString is = blcm.createInternationalString(serviceDesc);
service.setDescription(is);

// Create service bindings

Collection serviceBindings = new ArrayList();
ServiceBinding binding = blcm.createServiceBinding();
is = blcm.createInternationalString(serviceBindingDesc);
binding.setDescription(is);

// allow us to publish a bogus URL without an error

binding.setValidateURI(false);
binding.setAccessURI(serviceBindingURI);
serviceBindings.add(binding);

// Add service bindings to service

service.addServiceBindings(serviceBindings);

// Add service to services, then add services to organization

services.add(service);
org.addServices(services);

// Add organization and submit to registry

// Retrieve key if successful

Collection orgs = new ArrayList();
orgs.add(org);
BulkResponse response = blcm.saveOrganizations(orgs);
Collection exceptions = response.getExceptions();

if (exceptions == null) {

System.out.println("Organization saved");
Collection keys = response.getCollection();
Iterator keyIter = keys.iterator();

if (keyIter.hasNext()) {

javax.xml.registry.infomodel.Key orgKey = (javax.xml.registry.infomodel.Key) keyIter.next();
String id = orgKey.getId();
System.out.println("Organization key is " + id);
org.setKey(orgKey);

}

}

}

}


Assembling and Deploying a JAXR Client

The following steps describe how you can assemble and deploy a JAXR client:

  1. Execute the default target core to compile Java files and build the .jar file. The .jar file has the JAXR API classes and a wrapper client class.
  2. asant core

  3. Build Javadocs. For example:
  4. Execute the following asant command under install_dir/samples/webservices/jaxr/src/ to create javadocs:

    asant javadoc

  5. Deploy the client.
    1. JAXR can be configured to access various registries. You can use either your own registry server or you can use public registry servers. If you choose to use a public registry server, make certain that you can publish to the registry server. Modify jaxr.properties with the correct parameters. This file contains the following parameters:
      • query-url - Fully qualified inquiry URI for the registry server.
      • publish-url - Fully qualified publish URI for the registry server.
      • username - Username to publish an organization to the registry server.
      • password - Password to publish an organization to the registry server.
      • query-string - The search string to search for in the registry.
      • key-string - The key of the organization to be deleted from the registry server.
    2. If you wish to publish to the registry server, modify the publish organization info section in the jaxr.properties, if required.
  6. Run the client using the following command:
  7. asant run

Sample JAXR Client

You can find various sample applications that demonstrate the use of JAXR API in Sun ONE Application Server environment at the following location:

install_dir/samples/webservices/jaxr/



Previous      Contents      Index      Next     


Copyright 2003 Sun Microsystems, Inc. All rights reserved.