For z/OS platforms

Using the optimized local adapters to connect to an application in an external address space from a Liberty application

Use the WebSphere® optimized local adapters (WOLA) APIs to connect to an application in an external address space from an application that is deployed on the Liberty server.

Before you begin

Register the external address space with the WOLA group. For more information, see Registering an external address space with a local Liberty server using optimized local adapters.

Set up the application in the external address space as an optimized local adapters server task by calling either the Receive Request Any, Receive Request Specific, or Host Service APIs. For more information, see Optimized local adapters APIs on Liberty for z/OS.

Procedure

  1. Enable the Liberty application to access the connection factory by using either resource injection or a JNDI lookup.

    The following example uses an Enterprise JavaBeans (EJB) application. You can use the same code in a web application or servlet.

    • For resource injection, use the @Resource annotation to reference the connection factory that you defined in the server.xml file. The following example references the eis/ola connection factory:
      @Resource(lookup = "eis/ola",
                          authenticationType = Resource.AuthenticationType.APPLICATION,
                          shareable = false)
          private ConnectionFactory cf;
    • For JNDI lookup, create a resource reference in your application that you then look up in the enterprise bean.
      1. Create a resource reference in the META-INF/ibm-ejb-jar-bnd.xml file for the application, where the binding-name matches the JNDI name of the connection factory in the server.xml file.
        <session name="HSCBC016Bean">
            <resource-ref name="eis/ola" binding-name="eis/ola"/>
        </session>
      2. In the EJB implementation, create a connection factory object that looks up the resource reference that you defined. Prefix the name of the resource reference with java:comp/env/ as shown in the following example:
        Context ctx = new InitialContext();
        ConnectionFactory cf = ctx.lookup("java:comp/env/eis/ola");
  2. Create a connection specification by creating a ConnectionSpecImpl object. Provide the register name of the external address space that you want to connect to in either of the following ways:
    • Add the register name as an attribute on the connection factory
    • Call the ConnectionSpecImpl method, setRegisterName, with the register name
    The following example creates the ConnectionSpecImpl object and provides the MyRES1 register name:
    ConnectionSpecImpl csi = new ConnectionSpecImpl();
    csi.setRegisterName ("MyRES1");
  3. Create a connection with the connection factory, as shown in the following example:
    Connection con = cf.getConnection(csi);

Results

The Liberty application is connected to an external address space and can call services that are hosted on the external address space. For more information, see Using the Liberty optimized local adapters APIs to call services in an external address space.

Icon that indicates the type of topic Task topic

File name: twlp_dat_connect2wlpapp.html