Use 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.
Register the external address space with the WOLA group.
See Register 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.
- Enable the Liberty application to access
the connection factory using either resource injection or a JNDI lookup.
The following example uses an Enterprise JavaBeans (EJB) application. We 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 server.xml. The following example references the eis/ola connection factory:
@Resource(lookup = "eis/ola", authenticationType = Resource.AuthenticationType.APPLICATION, shareable = false) private ConnectionFactory cf;
- For resource injection, use the @Resource annotation to reference the connection factory that you defined in server.xml. The following example references the eis/ola connection factory:
- For JNDI lookup, create a resource reference in the application that you then look up in the enterprise bean.
- 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 server.xml.
<session name="HSCBC016Bean"> <resource-ref name="eis/ola" binding-name="eis/ola"/> </session>
- 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");
- 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 server.xml.
- Create a connection specification by creating a ConnectionSpecImpl object. Provide the register name of the external address space we 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");
- Create a connection with the connection factory, as shown in the following example:
Connection con = cf.getConnection(csi);
See Use the Liberty optimized local adapters APIs to call services in an external address space.