Java Clients
Connecting with Server Attributes Read from a SAS Metadata ServerNote: 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 ExampleThe 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:
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. |