Contacting a Registry Using JAXR

To begin working with a registry using JAXR, you first need a connection to the registry. This connection is represented by an implementation of the javax.xml.registry.Connection interface. As a first step toward obtaining a connection, you need an instance of javax.xml.registry.ConnectionFactory:

Context context = new InitialContext();
ConnectionFactory factory = (ConnectionFactory)context.lookup("eis/JAXR");

You then need to tell the factory the location of your preferred registry server. This is done through properties:

Properties riRegistryProperties = new Properties();

riRegistryProperties.setProperty("javax.xml.registry.queryManagerURL",
            "http://uddi.ibm.com/testregistry/inquiryapi");

riRegistryProperties.setProperty("javax.xml.registry.lifeCycleManagerURL",
            "http://uddi.ibm.com/testregistry/publishapi");

factory.setProperties(riRegistryProperties);

Now that the factory is targeted at a particular registry, you can use it to create a connection to that registry:

Connection connection = factory.createConnection();

Authentication credentials must also be supplied before the registry service is used. Credentials will almost certainly be required to update information in the registry and may even be required for access to information. The credentials are contained in an instance of java.net.PasswordAuthentication:

String user = ...
String password = ...

char[] passwordArray = password.toCharArray();

PasswordAuthentication pwdAuthentication =
                               new PasswordAuthentication(user, passwordArray);

These credentials are then stored in a java.util.HashSet (there may be more than one set of credentials) and associated with the connection:

Set credentials = new HashSet();
credentials.add(pwdAuthentication);

connection.setCredentials(credentials);

At this point you are ready to interact with the registry. You can either store or retrieve information through this connection.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.165.62