SAS 9.1.3 Integration Technologies » Developer's Guide


Developing Java Clients
Installation and JRE Requirements
Security
Using the IOM Server
Using the Java Connection Factory
Connecting with Directly Supplied Server Attributes
Connecting with Server Attributes Read from a SAS Metadata Server
Connecting with Server Attributes Read from an LDAP Server
Connecting with Server Attributes Read from the Information Service
Language Service Example
Logging Java Connection Factory Activities
Using Failover
Using Load Balancing
Using Connection Pooling
Pooling with Directly Supplied Server Attributes
Pooling with Server Attributes Read from a Metadata Server
Pooling with Server Attributes Read from the Information Service
Returning Connections to the Java Connection Factory
Using Java CORBA Stubs for IOM Objects
Getting a JDBC Connection Object
Using the Java Workspace Factory
Using SAS Foundation Services
IOM and CORBA Class Documentation
Java Clients

Connecting with Server Attributes Read from a SAS Metadata Server

Note: You can read the metadata by either connecting to the metadata server directly, or by using the Information Service. For details about using the Information Service, see Connecting with Server Attributes Read from the Information Service.

The Java Connection Factory enables you to obtain the server connection information from a SAS Metadata Server using indirect logical server names. The main advantage of this method is that you can maintain and update the IOM server and connection information without changing your client programs. This method also provides additional security features if you are using connection pooling.

To use this method, you must provide the client program with instructions for connecting to the metadata server, the name of the information you want to search for, and the repository within the metadata server for performing the search. To connect to the metadata server, you must first create an instance of BridgeServer containing the appropriate attributes for the metadata server. For a complete list of the attributes that you can provide, refer to the documentation for the BridgeServer class.

Example

The following example code shows how to initialize and use the Java Connection Factory with information from a SAS Metadata Server directory. For information about how to use the object reference, see Language Service Example. The example code performs the following steps:
  1. Creates a connection factory configuration (ManualConnectionFactoryConfiguration) to connect to a SAS Metadata Server.
  2. Creates a connection factory that matches the connection factory configuration for the SAS Metadata Server.
  3. Creates a connection to the metadata server.
  4. Narrows the connection from the metadata server.
  5. Uses the server metadata from the SAS Metadata Server to create a new connection factory configuration (ConnectionFactoryConfiguration) for the server with the logical name login015Logical.
  6. Creates a new connection factory for the connection factory configuration (ConnectionFactoryConfiguration).
  7. Sets up logging.
  8. Creates a connection to the server with logical name login015Logical.
  9. Narrows the connection from the server.
  10. Closes the connection.
  11. Shuts down the connection factory.

The last three statements in the example code show how to dispose of object references. For details about this procedure, see Returning Connections to the Java Connection Factory.

import com.sas.iom.SAS.IWorkspace;
import com.sas.iom.SAS.IWorkspaceHelper;
import com.sas.meta.SASOMI.IOMI;
import com.sas.meta.SASOMI.IOMIHelper;
import com.sas.services.connection.BridgeServer;
import com.sas.services.connection.ConnectionFactoryAdminInterface;
import com.sas.services.connection.ConnectionFactoryConfiguration;
import com.sas.services.connection.ConnectionFactoryInterface;
import com.sas.services.connection.ConnectionFactoryManager;
import com.sas.services.connection.ConnectionInterface;
import com.sas.services.connection.ManualConnectionFactoryConfiguration;
import com.sas.services.connection.omr.OMRConnectionFactoryConfiguration;
import com.sas.services.connection.Server;

String classID = Server.CLSID_SASOMI;
String host = "omr.pc.abc.com";
int port = 8561;

// Set the credentials for the metadata server connection. If connecting to
// a pooled server, these should be the credentials for the pooling
// administrator.
String userName_omr = "Adm1";
String password_omr = "Adm1pass";

// Step 1. Create a connection factory configuration for the metadata server
// and get a connection factory manager.
Server omrServer = new BridgeServer(classID,host,port);
ConnectionFactoryConfiguration cxfConfig_omr =
   new ManualConnectionFactoryConfiguration(omrServer);

ConnectionFactoryManager cxfManager = new ConnectionFactoryManager();

// Step 2. Create a connection factory for the metadata server connection
// factory configuration.
ConnectionFactoryInterface cxf_omr = cxfManager.getFactory(cxfConfig_omr);

// Step 3. Get a connection to the metadata server.
ConnectionInterface cx_omr = cxf_omr.getConnection(userName_omr,password_omr);

// Step 4. Narrow the connection from the metadata server.
org.omg.CORBA.Object obj_omr = cx_omr.getObject();
IOMI iOMI = IOMIHelper.narrow(obj_omr);

String reposID = "A0000001.A1234567";
String name= "login015Logical";

// Step 5. Create a connection factory configuration for the server by passing
// the server logical name to the metadata server.
ConnectionFactoryConfiguration cxfConfig =
   new OMRConnectionFactoryConfiguration(iOMI,reposID,name);

// Step 6: Get a connection factory that matches the server's connection
// factory configuration.
ConnectionFactoryInterface cxf = cxfManager.getFactory(cxfConfig);

// Set the credentials for the server connection.
String userName = "citynt\\use1";
String password = "use1pass";
String domain = "citynt";

// Step 7: Get a connection to the server.
ConnectionInterface cx = cxf.getConnection(userName,password,domain);

// Step 8: Narrow the connection from the server.
org.omg.CORBA.Object obj = cx.getObject();
IWorkspace iWorkspace = IWorkspaceHelper.narrow(obj);

< insert iWorkspace workspace usage code here >

// Step 9: Close the workspace connection and shutdown the connection factory.
cx.close();
cxf.shutdown();

// Step 10: Close the metadata server connection and shutdown the connection
// factory.
cx_omr.close();
cxf_omr.shutdown();

In an effort to make the previous example more readable, we have removed most of the code structuring elements. The example will not compile as it is shown.