• No results found

Tafc Calljee&Mdb

N/A
N/A
Protected

Academic year: 2021

Share "Tafc Calljee&Mdb"

Copied!
12
0
0

Loading.... (view fulltext now)

Full text

(1)

TAFC CALLJEE

And

Message Driven Beans

Version No. 2.0

Version

(2)

Message Driven Beans 2010-04-12

Document Owner

This document is subject to change control. Each change must be agreed, annotated and signed by the owners of the document listed below: -

The owners of this document are listed below:

TEMENOS Helpdesk Manager Sriraman Ganesan

Revision History

Version Revision Date Revision Description Author

1.0 12 Apr 2010 TAFC CALLJEE and MDBs Sheryl Rahman

1.1 21 Nov 2013 Updated with CALLJEE HA

changes and error codes

Sheryl Rahman

Sign Off History

Version Date TEMENOS Authorization Client Authorization

(3)

Message Driven Beans 2010-04-12

Introduction

This document aims to explain how to deploy Message Driven Beans (MDBs), a special type of Enterprise Java Beans (EJBs) which utilizes the inbound connection feature of the TAFC Resource Adapter. It can be invoked from a jBC program using the CALLJEE or JEEActivate functions and enables T24 applications to place messages on JMS queues. These remote calls are achieved by using a TCP/IP connection from the TAFC process to a Java Enterprise Edition Application Server – such as JBoss. The only configuration necessary in TAFC is a host and a port.

(4)

Message Driven Beans 2010-04-12

Deploying a Simple Bean

JBoss has three deployment descriptors for declaring the deployment properties for enterprise beans:

ejb-jar.xml - This is the standard EJB deployment descriptor, declaring the available enterprise beans, their logical names, interfaces, and other deployment properties (security, transactions, etc.).

jboss.xml - This optional file is used to specify a different JNDI name for a bean's home interface. The default JNDI name for a bean is the ejb-jar.xml ejb-name element value.

jaws.xml - This file is necessary only for CMP entity bean deployment. We are concerned with only the ejb-jar.xml and jboss.xml files.

Deployment Process

Ultimately, enterprise beans are packaged in a JAR file with the appropriate XML files in the META-INF folder. Most J2EE app servers require the deployment of an EJB JAR within a WAR file, and even within an EAR file. The process of packaging up an enterprise bean with deployment descriptors into a larger archive with its deployment descriptors can become rather complex. This process may be necessary in a production environment, but in

development, you need quick, efficient deployment. JBoss provides the best of both worlds. All you do to deploy EJBs in JBoss is drop the archive into the deploy directory. The JBoss engine immediately inspects the contents of the archive and attempts to deploy the bean(s). Undeploying is as easy as deleting the archive from the deploy directory.

To access the bean so created we will have to write the client code. Let us try to understand this using a simple example. Our T24 program will communicate to the MDB that prints a message to standard output and returns an ‘All OK’ response to the basic program if everything goes well. CALLJEE is the TAFC statement that we use to invoke EJB from our T24 basic routine/ program.

(5)

Message Driven Beans 2010-04-12

Enhanced high availability for JEE inbound connections

The jBC CALLJEE statement enables application developers to send messages to the application server and therefore provide connectivity to other systems. The environment variables

• JREMOTE_INBOUND_HOST=<host> • JREMOTE_INBOUND_PORT=<port>

Used to connect to the JEE application server are still supported for backwards compatibility. In order to provide connectivity and failover to secondary servers, application developers were required to use the JEEOpen/JEEActivate/JEEClose statements, manage connection handles and optionally provide a retry mechanism for failover.

New environment variables

• JEE_HOSTS=<host1>, <host2>, ... • JEE_PORTS=<port1>, <port2>, ...

are now available to provide the jBC CALLJEE statement with connectivity to multiple servers.

This mechanism

- Does NOT load balance requests between multiple servers. CALLJEE establishes only one connection to a single application server.

- CALLJEE always attempts to first establish a connection to host 1 if available, otherwise to host2, and so on.

- CALLJEE does not fail-over at runtime – a JBC application needs to provide the retry mechanism, i.e. re-send the request in case of failure. See CALLJEE error codes for

identifying connection errors.

Enhanced high availability for JEE inbound connections

The inbound listener now uses the TOCF framework library (tocfframework.jar) which provides an enhanced event pipeline based on the Netty serialization library.

Note: The Netty library - included in TOCF(EE) pack (R12.0.0.2 onwards) - must be made available to the application server’s system classloader in case the application server does not already ship this library. This is only required when enabling the inbound listener.

(6)

Message Driven Beans 2010-04-12 - Make sure you have the attached netty library inside <profile>\lib location.

For eg: D:\R12.GA.ModelBank.Win64.SCU\Temenos\ModelBank-R12\3rdParty\jboss\server\default\lib

- Ensure “inbound listener” is configured inside the resource adapter (tocfT24ra-ra.rar). Enable the port as shown below:

<resourceadapter>

<resourceadapter-class>com.temenos.tocf.t24ra.T24ResourceAdapter</resourceadapter-class> <!-- Inbound listener properties -->

<config-property>

<description>Inbound listener server name (empty = bind to all addresses)</description> <config-property-name>listenHost</config-property-name> <config-property-type>java.lang.String</config-property-type> <!-- <config-property-value>10.92.7.91</config-property-value> --> </config-property> <config-property>

<description>Inbound listener port number (0 = inbound listener disabled)</description>

<config-property-name>listenPort</config-property-name> <config-property-type>java.lang.Integer</config-property-type>

<!-- Inbound listener is disabled by default (port=0). Set to e.g. 55006 to enable inbound listener -->

<config-property-value>55006</config-property-value> </config-property>

CALLJEE Error Codes

0 Action successful

1 Connection error (i.e. connection error between T24 and App server) 2 Transaction error (i.e. transaction related error)

3 Error attempting to close a connection while a transaction is active

4 Activation error (i.e. endpoint is not activated or is unable to process request) 101 Invalid host

(7)

Message Driven Beans 2010-04-12

The Programs

PROGRAM TEST_PRINT_MESSAGE INCLUDE JBC.h

TRANSTART ELSE CRT "Unable to start the transaction."

ACTIVATION = "PRINTMESSAGE" INFO = "Hello folks!"

ERROR.CODE = CALLJEE (ACTIVATION,INFO) CRT ERROR.CODE

CRT "response received: >>>>":INFO:"<<<<"

TRANSEND ELSE CRT "Unabel to commit the transaction."

In order to be callable, a message driven bean must implement the JRemoteMessageListener interface and activate the JRemote JCA (jremote-ra.rar). Once activated the JRemote JCA will listen for incoming requests on the configured IP address and port (see the ra.xml inside jremote-ra.rar).

package com.jbase.mytutorial.mdb; import com.jbase.jremote.JDynArray; import com.jbase.jremote.jca.inflow.JRemoteMessageListener; import java.io.PrintStream; import java.lang.reflect.Method; import java.util.logging.Level; import java.util.logging.Logger; import javax.ejb.EJBException; import javax.naming.NamingException; import javax.resource.ResourceException; import javax.ejb.MessageDrivenBean; import javax.ejb.MessageDrivenContext; import javax.naming.InitialContext;

public class myMessageBean implements MessageDrivenBean, JRemoteMessageListener {

private static final Logger logger = Logger.getLogger(myMessageBean.class.getName()); private InitialContext _context;

public myMessageBean(){ this._context=null; }

public void setMessageDrivenContext(MessageDrivenContext ctx) throws EJBException{ }

(8)

Message Driven Beans 2010-04-12 public void ejbCreate() throws EJBException{

try{

this._context= new InitialContext(); } catch (NamingException e){

logger.log(Level.SEVERE,"Failed to create initial context",e); }

}

public void ejbRemove() {}

public JDynArray onMessage(JDynArray myArray){ logger.info("incoming message [" + myArray + "]"); if(this._context!=null){

String myMessage=myArray.get(1);

System.out.println("myMessageBean confirming the receipt of the following message:\n" + ">>>>"+ myMessage +"<<<<");

return new JDynArray("All is well"); } else{

return new JDynArray("ERROR"); }

}

public void beforeDelivery(Method method) throws NoSuchMethodException, ResourceException {} public void afterDelivery() throws ResourceException {}

public void release() {} }

Dissection of myMessageBean.java

The MDB class must implement the javax.jms.MessageListener [or use the Temenos supplied JRemoteMessageListener] and the javax.ejb.MessageDrivenBean interfaces. In addition to the onMessage method, the following must be implemented:

 A public constructor with no argument.

public void ejbCreate(): with no arguments, called at the bean instantiation time. It

may be used to allocate some resources, such as connection factories, for example if the bean sends messages, or datasources or if the bean accesses databases.

public void ejbRemove(): usually used to free the resources allocated in the ejbCreate

method.

public void setMessageDrivenContext(MessageDrivenContext mdc): called by the

container after the instance creation, with no transaction context. The JOnAS container provides the bean with a container context that can be used for transaction management, e.g., for calling setRollbackOnly(), getRollbackOnly(), getUserTransaction().

(9)

Message Driven Beans 2010-04-12 The onMessage method is activated on receipt of messages sent by a client application to the corresponding JMS destination.

public JDynArray onMessage(JDynArray myArray){ logger.info("incoming message [" + myArray + "]"); if(this._context!=null){

String myMessage=myArray.get(1);

System.out.println("myMessageBean confirming the receipt of the following message:\n" + ">>>>"+ myMessage +"<<<<");

return new JDynArray("All is well"); } else{

return new JDynArray("ERROR"); }

}

The JDynArray is a jBASE type that implements a dynamic string array where attribute, value, and subvalue delimiters mark the array indices. On successful creation of a transactional context and arrival of a message thereafter, the method returns a response of type jDynArray to the caller.

Deployment descriptors

Jboss.xml:

- Change ejb-name to something identifiable.

- Resource adapter must be jremote-ra.rar. That contains ra.xml with listening port no (55006) for jRemoteResourceAdapter

<?xml version="1.0"encoding="UTF-8"?>

<!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 4.0//EN" "http://www.jboss.org/j2ee/dtd/jboss_4_0.dtd"> <jboss>

<enterprise-beans> <message-driven>

<ejb-name>PrintMessageMDBJRemote</ejb-name>

<resource-adapter-name>jremote-ra.rar</resource-adapter-name>

<depends>jboss.jca:service=RARDeployment,name='jremote-ra.rar'</depends> </message-driven>

</enterprise-beans> </jboss>

(10)

Message Driven Beans 2010-04-12

Ejb-jar.xml:

Multiple instances of the MDBs can be created in the ejb-jar.xml to receive requests for different activation types. The jBC program can determine which MDB instance it needs to call by the ACTIVATION string. The ACTIVATION string that we use in our test program is “PRINTMESSAGE” – specify it under the <activation-config-property-value> tag.

The other thing that needs to be taken care here is the ejb-name (matched in jboss.xml).

<?xml version="1.0"encoding="UTF-8"?>

<ejb-jar id="ejb-jar_ID"version="2.1"xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd">

<display-name>JMS Dispatcher</display-name> <enterprise-beans>

<message-driven>

<display-name>PrintMessageMDB JRemote</display-name> <ejb-name>PrintMessageMDBJRemote</ejb-name>

<ejb-class>com.jbase.mytutorial.mdb.myMessageBean</ejb-class>

<messaging-type>com.jbase.jremote.jca.inflow.JRemoteMessageListener</messaging-type> <transaction-type>Container</transaction-type>

<activation-config>

<activation-config-property>

<activation-config-property-name>handler</activation-config-property-name> <activation-config-property-value>PRINTMESSAGE</activation-config-property-value> </activation-config-property>

</activation-config> </message-driven> </enterprise-beans> </ejb-jar>

(11)

Message Driven Beans 2010-04-12

OUTPUTS

JBOSS Console - during deployment:

Run the T24 program:

(12)

Message Driven Beans 2010-04-12

References

Temenos knowledge base http://knowledgebase.temenosgroup.com/

Java JDK http://java.sun.com

J2EE Connector Architecture (JCA) Specification http://java.sun.com/j2ee/connector/

JBoss http://www.jboss.org/

JBoss JTA Programmers guide

References

Related documents

package packtpub.osw; import java.util.Date; import java.util.Properties; import javax.mail.Message; import javax.mail.Session; import javax.mail.Transport;

package packtpub.osw; import java.util.Map; import org.quartz.Job; import org.quartz.JobExecutionContext; import org.quartz.JobExecutionException;

CODE TO TYPE: MainActivity.java package com.oreillyschool.android2.mediaaudio; import android.app.Activity; import android.media.MediaPlayer;

org.cagrid.indexService; package java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import

Booking.java package com.grasshopper.entity; import java.math.BigDecimal; import java.util.Date; import java.util.HashSet; import java.util.Set; import

APPENDIX A Source Code WelcomeBrainRecorder.java package cpslo.brainrecorder.activity; import android.app.Activity; import android.bluetooth.BluetoothAdapter;

package com.boomgaarden_corney.android.locationnetwork; import android.content.Context; import android.location.Location; import android.location.LocationListener; import

More advanced mechanisms are provided by package templates [KMPS09], which are collections of classes. However, differently from standard Java packages where an import clause