Oracle’s product portfolio contains the Technology Adapters. A set of JCA Connectors that provide a bridge between various technologies – such as JMS, AQ, Database (SQL and PL/SQL), FTP and File System – on the one hand and the world of JEE on the other. The SOA Suite 11g and Oracle Service Bus leverage these adapters to connect to and from these technologies. For example: through the adapters, instances of composite applications can be instantiated through the appearance of a file on the file system or a new record in a database table. And, in the outbound direction: OSB and SOA Suite can call out to PL/SQL procedures, send messages to JMS Topics or an AQ queue and write files to an FTP server.
The technology adapters comply with the JEE standard specification of JCA (Java Connector Architecture). They are deployed as a special type of resource – JCA Adapter – on WebLogic Server. And they can be connected to custom Java components – in addition to their better known usage with SOA Suite and Oracle Service Bus.
I have tried to use the File Adapter in an inbound fashion to trigger a Message Driven Bean when a new file is received in a specific directory. This article describes my findings. And I have to warning: the story is not yet complete(ly successful).
JCA Connectors can deliver their inbound messages to message driven beans (MDBs). Starting with the EJB 2.1 specification, MDBs can have a JCA Resource Adapter configured as their source of messages, instead of a JMS Topic or Queue. In addition to a reference to JCA Adapter, the MDB should be accompanied by the configuration of the Activation Configuration for the Resource Adapter. This is the set of property values that determine the behavior of the Adapter on behalf of the Message Driven Bean:
In this example, the FileAdapterClientMDBBean is configured in the ejb-jar.xml file. The activation-config element contains a collection of activation-config-properties. These properties are described in the documentation for the File Adapter (http://docs.oracle.com/cd/E21764_01/integration.1111/e10231/adptr_propertys.htm#CHDEDJEA) and they correspond with the bean properties for the class FileActivationSpec that can be found in the RAR file MW_HOME\soa\connectors\FileAdapter.rar that is used to deploy the File Adapter:
The rar file contains the fileAdapter.jar file that contains the FileActivationSpec class:
This class has the following bean properties:
These properties can be set – presumably at least, because I have not been able to try it out successfully or find confirmation anywhere – in the ejb-jar.xml file as shown above – and below.
<?xml version = '1.0' encoding = 'windows-1252'?> <ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/j2ee/ejb-jar_3_0.xsd" version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"> <enterprise-beans> <message-driven> <description>EJB 3.0 Message Driven Bean (MDB) that acts as client for the File Adapter</description> <display-name>FileAdapterClientMDBBean</display-name> <ejb-name>FileAdapterClientMDBBean</ejb-name> <ejb-class>nl.amis.jca.FileAdapterListener</ejb-class> <messaging-type>javax.resource.cci.MessageListener</messaging-type> <transaction-type>Container</transaction-type> <activation-config> <activation-config-property> <activation-config-property-name>physicalDirectory</activation-config-property-name> <activation-config-property-value>d:\temp\custom</activation-config-property-value> </activation-config-property> <activation-config-property> <activation-config-property-name>deleteFile</activation-config-property-name> <activation-config-property-value>true</activation-config-property-value> </activation-config-property> <activation-config-property> <activation-config-property-name>pollingFrequency</activation-config-property-name> <activation-config-property-value>10</activation-config-property-value> </activation-config-property> <activation-config-property> <activation-config-property-name>includeFiles</activation-config-property-name> <activation-config-property-value>.*\.txt</activation-config-property-value> </activation-config-property> <activation-config-property> <activation-config-property-name>minimumAge</activation-config-property-name> <activation-config-property-value>0</activation-config-property-value> </activation-config-property> </activation-config> </message-driven> </enterprise-beans> </ejb-jar>
The class that implement the Message Driven Bean is referenced in this ejb-jar.xml through the ejb-class property: nl.amis.jca.FileAdapterListener. This class is just a regular MDB – at this point without any useful functionality, just logging of the messages that get received.
package nl.amis.jca; import java.util.logging.Logger; import javax.ejb.ActivationConfigProperty; import javax.ejb.MessageDriven; import javax.resource.cci.MessageListener; import javax.resource.cci.Record; /** * EJB 3.0 Message Driven Bean (MDB) that acts as client for the File Adapter JCA Resource * Adapter. * * @author Lucas Jellema (heavily leaning on Ronald van Luttikhuizen) */ @MessageDriven(activationConfig = { @ActivationConfigProperty(propertyName = "resourceAdapterJndiName", propertyValue = "eis/FileAdapter") }, mappedName = "weblogic.wsee.DefaultQueue") public class FileAdapterListener implements MessageListener { /** * Logger. */ private Logger logger = Logger.getLogger(FileAdapterListener.class.getName()); /** * Default constructor. */ public FileAdapterListener() { System.out.println("File Adapter Listener started"); logger.info("[START] FileAdapterListener()"); // Do nothing logger.info("[END] FileAdapterListener()"); } /* * @see javax.resource.cci.MessageListener#onMessage(javax.resource.cci.Record) */ public Record onMessage(Record record) { System.out.println("File Adapter Listener received record!!!"); logger.info("[START] onMessage()"); logger.info("\t" + "New record: " + record); // JCA record information logger.info("\t" + "Record name: " + record.getRecordName()); logger.info("\t" + "Record short description: " + record.getRecordShortDescription()); logger.info("[END] onMessage()"); return record; } }
Note how the class has annotations that contain the reference to the JCA Resource Adapter that is the source of messages for the MDB:
Instead of using this EJB 3.0 annotation, the application can also use a WebLogic Server specific deployment descriptor file – weblogic-ejb-jar.xml – with the identification of the Message Driven Bean and the descriptor with the resource-adapter-jndi-name property:
<?xml version = '1.0' encoding = 'windows-1252'?> <weblogic-ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bea.com/ns/weblogic/weblogic-ejb-jar.xsd" xmlns="http://www.bea.com/ns/weblogic/weblogic-ejb-jar"> <weblogic-enterprise-bean> <ejb-name>FileAdapterClientMDBBean</ejb-name> <message-driven-descriptor> <resource-adapter-jndi-name>eis/FileAdapter</resource-adapter-jndi-name> </message-driven-descriptor> </weblogic-enterprise-bean> </weblogic-ejb-jar>
Note: since the thing is not working right now, I cannot be sure that my reference to eis/FileAdapter is the correct one. However, when checking the WebLogic Server Administration Console for the File Adapter deployment, this seems the correct JNDI name:
Note that this same name is used in the JCA configuration files created in SOA Composite applications that make use of the File Adapter.
Deployment Challenges
After I completed the application – MDB and ejb-jar.xml file – I defined an EAR deployment profile and tried to build and deploy it (to WebLogic Server 10.3.4, aka 11g PS3). Unfortunately, deployment failed with the following output:
This message: “The ResourceAdapterJNDIName configuration attributes cannot be mixed with any of the following settings:” does not seem justified, because only the ResourceAdapterJNDIName property is set and none of the other properties mentioned is available in either the MDB itself or any of the associated descriptors. Even the code described by Ronald van Luttikhuizen – apparently successfully tested – does not deploy successfully on my local WLS instance.
I have thusfar not been able to resolve the problem. Googling with the messages in the console resulted in a promising hit:
http://forums.oracle.com/forums/thread.jspa?threadID=2136029
Unfortunately, Oracle’s Discussion Forums (OTN) are down because of maintenance:
I am stuck for the moment. It feels like I have done what one should do in order to have one’s Message Driven Beans triggered by the File Adapter.
Right now, I will quit and hope for the Forums to come available again or some helpful and knowledgeable reader to post a comments that helps me out. Note: I will complement this article with the solution when I have found one.
Resources
Documentation: Fusion Middleware User’s Guide for Technology Adapters
11g Release 1 (11.1.1.5.0) – http://docs.oracle.com/cd/E21764_01/integration.1111/e10231/intro.htm
Article on OTN by Ronald van Luttikhuizen on the development and deployment of a custom (inbound) JCA Resource Adapter and the creation and deployment of a Java Client to be triggered by the adapter –
The OTN Discussion Forum thread that hopefully provides an answers to my problem: http://forums.oracle.com/forums/thread.jspa?threadID=2136029
Develop inbound connectors with JCA 1.5 (Article on JavaWorld, 2005) – http://www.javaworld.com/javaworld/jw-06-2005/jw-0606-jca.html
Fusion Middleware Programming Message-Driven Beans for Oracle WebLogic Server 11g Release 1 (10.3.4) -Deployment Elements and Annotations for MDBs http://docs.oracle.com/cd/E17904_01/web.1111/e15493/summary.htm
Hi Lucas,
Thanks for the good post, it is very helpful for me.
I am trying to do the similar thing: interact with File Adapter from EJB, so I wonder if you have finally make it work? I wish I am running on the right direction, thanks in advanced.
The user guide of the Oracle JCE adapter only introduces the adapter usage in SOA composite application. Do you know any document that introduces the adapter usage in EJB? I have searched but with no luck. Thanks for your help.
Hi Michel,
Â
Thanks for your reaction. However, I am not trying to configure the adapter here, I am trying to deploy an application that registers with the inbound adapter in order to get notified by the adapter. To that end, a message driven bean is hooked into the adapter, instead of a JMS destination (Topic or Queue) as is normally the case. The configuration applies to the MDS – not to the adapter!
Â
Lucas
Hi Lucas
Have you considered using a weblogic-ra.xml as an additional descriptor? This contains parameters that are specific to configuring and deploying resource adapters in WebLogic Server. As I can see you are now using the ejb-jar.xml for you ra config and it seems it gives conflicts with your EJB specific settings
kind regards
Michel