As mentioned in my previous Alerts from adapter modules - the JRA way!! here are few specifics about how to go ahead with your JRA setup and NWDS settings. Some part of this blog is a repetition of content on help.sap.com, with some omissions / additions but this is an effort to give consolidated information about the same. SAP WebAS specific setup

Following link should be referred for more details on effective connection pooling using JRA.

Connection pooling with Resource adapters 




With connection pooling a client application does not connect / disconnect at its own but just picks up a connection from a pre-established pool of connections and releases it to the pool when done with its execution.


For sample code using SAPJRA refer the following link.

 

http://help.sap.com/saphelp_nw04/helpdata/en/ca/a4804258544b76e10000000a155106/content.htm

 

With the setup part complete and having the JNDI name for the connection factory with you, it is possible to write the code based on it. Inside NWDS there are few typical steps you would need to carry out for your EJB and EAR projects which are summarized below.





You need references to connector.jar file which has the classes required at compile time and runtime



Compile time :



  • From the context menu of the EJB project , follow the path Properties -> Java Build Path -> Libraries.

  • Click on Add variable and select TSSAP_JAVAX_HOME and click on Extend and select connector.jar from the list displayed.



Run time :




  1. Navigate to the application-j2ee-engine.xml in your EAR project.

  2. Select References on the General tab and click on Add.

  3. Select Select library/interface/service as shown in the snapshot and select j2eeca as in the next snapshot.




Selection dialog


Library

We had a requirement in our project for raising alerts from adapter modules for receiver file communication channels. The business requirement behind this was to inform the concerned business people about the business data rejected during validation and we chose adapter modules for doing this, it being the last but one piece of code that will be executed before the file would be written by the file adapter.


Though I suspected it would not work, and eventually it didn’t, I thought of initially trying it out with Mapping LookupAPI. And this was the error it threw.


com.sap.aii.mapping.lookup.LookupException: Internal lookup service is not registered.
Invoking the lookup service is only supported in the Integration Builder test environment or in the Integration Server runtime environment.
at com.sap.aii.mapping.lookup.LookupService.getService(LookupService.java:400)
at com.sap.aii.mapping.lookup.LookupService.getChannel(LookupService.java:285)
at com.sap.aii.mapping.lookup.LookupService.getChannel(LookupService.java:318)

And the code line which caused this was

Channel channel = LookupService.getChannel("BS_XXX", "CC_XXXX");


So, we had a tough task of finding a solution for calling this RFC to raise alert from the adapter module environment, in pure J2EE terms, the EJB environment. Again the requirement was to have efficient connectivity mechanism i.e. connection pooling in place so that the client application does not connect / disconnect at its own but just picks up a connection from a pre-established pool of connections and releases it to the pool when done with its execution. Here came SAP JRA into picture which is a SAP recommended way of accessing SAP systems from a J2EE runtime environment and is an add-on for SAP JCo. For more information about SAP JRA refer the following link.


SAP JRA on help.sap.com


For raising alerts from adapter modules, which run inside the adapter engine of XI, the RFC SALERT_CREATE on XI server needs to be executed with the relevant information passed to it. Thanks to Bhavesh Kantilal for his Triggering XI Alerts from a User Defined Function for pointers to this RFC.


The code for raising the alert , or in general calling any RFC using JRA follows a typical pattern of
1. Retrieve the initial context
2. Lookup for the ConnectionFactory by the JNDI name which the administrator will set while configuring SAP JRA. Retrieve a connection from this connection factory.The connectivity parameters i.e. User Credentials,System ID,Client etc. are a part of JRA configuration and need not be passed from the code.
3. Retrieve the metadata for the RFC to be called. Note that NO JCO specific classes are to be used.
4. Set any direct import parameters, tables and call the RFC using interaction and execute the call.


Having your JRA configuration in place you can use the following code for raising alerts from adapter modules. Assuming you have an alert category ALRT_CAT with containers CONT_1 thro' CONT_N, this would be a typical process method of your module.




Watch out for the part II of this blog with specifics about JRA setup and the NWDS project settings you need to do to run this code successfully.