Configuring and deploying a basic JCA ResourceAdapter
You can configure and deploy a basic Java™ EE Connector Architecture (JCA) ConnectionFactory and Resource Adapter.
About this task
Procedure
- Enable the JCA feature in your server.xml file. The server.xml file is found at [path_to_liberty\wlp\usr\servers\server_name]
<server> <featureManager> <feature>jca-1.6</feature> <feature>servlet-3.0</feature> </featureManager> </server>
- Place the resource adapter RAR file (ExampleRA.rar) into
the dropins folder of your server. If your server is running, you will the following message in your console log indicating that
the resource adapter has been installed:
[AUDIT ] J2CA7001I: Resource adapter ExampleRA installed in 1.306 seconds.
- Inspect the deployment descriptor, annotations, and other
documentation from the resource adapter to identify
which types of resources the adapter provides and the
configuration properties that each adapter accepts. The
example resource adapter, ExampleRA.rar, has this information in the ra.xml deployment
descriptor. The ra.xml file is found at [path_to_ExampleRA\ExampleRA\META-INF.] The
deployment descriptor identifies 3 types of resources you can configure.
<connection-definition> <managedconnectionfactory-class>com.ibm.example.jca.adapter.ManagedConnectionFactoryImpl</managedconnectionfactory-class> <config-property> <config-property-name>tableName</config-property-name> <config-property-type>java.lang.String</config-property-type> </config-property> <connectionfactory-interface>javax.resource.cci.ConnectionFactory</connectionfactory-interface> ... </connection-definition> <adminobject> <adminobject-interface>javax.resource.cci.ConnectionSpec</adminobject-interface> <adminobject-class>com.ibm.example.jca.adapter.ConnectionSpecImpl</adminobject-class> <config-property> <config-property-name>readOnly</config-property-name> <config-property-type>java.lang.Boolean</config-property-type> <config-property-value>false</config-property-value> </config-property> </adminobject> <adminobject> <adminobject-interface>javax.resource.cci.InteractionSpec</adminobject-interface> <adminobject-class>com.ibm.example.jca.adapter.InteractionSpecImpl</adminobject-class> <config-property> <description>Function name. Supported values are: ADD, FIND, REMOVE</description> <config-property-name>functionName</config-property-name> <config-property-type>java.lang.String</config-property-type> </config-property> </adminobject>
- In the server.xml file, configure
instances of the available resource types.
<server> <featureManager> <feature>jca-1.6</feature> <feature>servlet-3.0</feature> </featureManager> <connectionFactory jndiName="eis/conFactory"> <properties.ExampleRA tableName="TABLE1"/> </connectionFactory> <adminObject jndiName="eis/conSpec"> <properties.ExampleRA.ConnectionSpec/> </adminObject> <adminObject jndiName="eis/iSpec_ADD"> <properties.ExampleRA.InteractionSpec functionName="ADD"/> </adminObject> <adminObject jndiName="eis/iSpec_FIND"> <properties.ExampleRA.InteractionSpec functionName="FIND"/> </adminObject> </server>
- Use resource injection to access the resources in your
servlet; for example:
@Resource(lookup = "eis/conFactory") private ConnectionFactory conFactory; @Resource(lookup = "eis/conSpec") private ConnectionSpec conSpec; @Resource(lookup = "eis/iSpec_ADD") private InteractionSpec iSpec_ADD; @Resource(lookup = "eis/iSpec_FIND") private InteractionSpec iSpec_FIND; ... MappedRecord input = conFactory.getRecordFactory().createMappedRecord("input"); input.put("city", "Rochester"); input.put("state", "Minnesota"); input.put("population", 106769); Connection con = conFactory.getConnection(conSpec); try { Interaction interaction = con.createInteraction(); interaction.execute(iSpec_ADD, input); interaction.close(); } finally { con.close(); }
Note: You must enable the JNDI feature in the server.xml file if you want to look up the resources from the namespace rather than using injection.
Subtopics
- Overview of JCA configuration elements
The Java Platform, Enteprise Edition Connector Architecture (JCA) feature provides configuration elements to define instances of connection factories, administered objects, and activation specifications, and to associate these instances with an installed resource adapter. Each of the JCA configuration elements consists of two basic parts, a top-level element and a subelement, both of which are required for the configured instance.
Parent topic: Administering Liberty manually


http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-libcore-mp&topic=twlp_jca_config_dep
File name: twlp_jca_config_dep.html