background image

Obtaining a Connection Factory

<< Installing Java WSDP | Setting Connection Properties >>
<< Installing Java WSDP | Setting Connection Properties >>
E
STABLISHING A
C
ONNECTION
177
Obtaining a Connection Factory
A client creates a connection from a connection factory. A JAXR provider can
supply one or more preconfigured connection factories. Clients can obtain these
factories by using resource injection.
At this release of the Application Server, JAXR supplies a connection factory
through the JAXR RA, but you need to use a connector resource whose JNDI
name is
eis/JAXR
to access this connection factory from a Java EE application.
To inject this resource in a Java EE component, use code like the following:
import javax.annotation.Resource;.*;
import javax.xml.registry.ConnectionFactory;
...
@Resource(mappedName="eis/JAXR")
public ConnectionFactory factory;
Later in this chapter you will learn how to create this connector resource.
To use JAXR in a stand-alone client program, you must create an instance of the
abstract class
ConnectionFactory
:
import javax.xml.registry.ConnectionFactory;
...
ConnectionFactory connFactory =
ConnectionFactory.newInstance();
Creating a Connection
To create a connection, a client first creates a set of properties that specify the
URL or URLs of the registry or registries being accessed. For example, the fol-
lowing code provides the URLs of the query service and publishing service for a
hypothetical registry. (There should be no line break in the strings.)
Properties props = new Properties();
props.setProperty("javax.xml.registry.queryManagerURL",
"http://localhost:8080/RegistryServer/");
props.setProperty("javax.xml.registry.lifeCycleManagerURL",
"http://localhost:8080/RegistryServer/");
With the Application Server implementation of JAXR, if the client is accessing a
registry that is outside a firewall, it must also specify proxy host and port infor-
mation for the network on which it is running. For queries it may need to specify