Using the Resource Adapter

After configuring the weblogic-ra.xml descriptor file and deploying the resource adapter, client components (servlet, JSP, EJB, etc.) can look up the connection factory either using the global JNDI name or via a resource reference to the connection factory. For instance, if a JSP page were to request a connection from Sun’s XADataSource Connector, it could look up the connection factory using the global JNDI name it was bound to:

javax.naming.InitialContext ic = new javax.naming.InitialContext ( );
javax.resource.cci.ConnectionFactory cf = 
   (javax.resource.cci.ConnectionFactory) ic.lookup("myapp.XADsWithTx");

Alternatively, you could define a reference to the resource adapter in the XML descriptors for the web application that holds the JSP:

<!-- web.xml entry -->
<webapp>
  ...
  <resource-ref>
    <res-ref-name>jca/xads</res-ref-name>
    <res-type>javax.resource.cci.ConnectionFactory</res-type>
    <res-auth>Container</res-auth>
    <res-sharing-scope>Shareable</res-sharing-scope>
  </resource-ref>
  ...
</webapp>

<!-- weblogic.xml entry -->
<reference-descriptor>
  <resource-description>
    <res-ref-name>jca/xads</res-ref-name>
    <jndi-name>myapp.XADsWithTx</jndi-name>
</resource-description>
   ...
</reference-descriptor>

Here we’ve defined a resource reference jca/xads that points to the connection factory instance bound to the global JNDI name myapp.XADsWithTx. When you redeploy the web application, the connection factory will then be available to the JSP under the local ENC for the ...

Get WebLogic: The Definitive Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.