IMS からコールアウト要求を受信するためのサンプル MDB

MDB は InboundListener インターフェースを実装するため、同期処理に使用される onMessage() メソッドと非同期処理に使用される onNotification() メソッドを実装する必要があります。

図形記述の開始。IMS TM リソース・アダプター バージョン 10.3 以降。図形記述の終了。次のサンプルは、IMS から同期と非同期の両方のコールアウト・メッセージを listen するように構成された MDB (IMSCalloutIVPMDBBean) の Bean 実装クラスを示しています。

package ejbs;

import java.io.IOException;
import javax.resource.ResourceException;
import javax.resource.cci.Record;
import com.ibm.connector2.ims.ico.IMSInputStreamRecord;
import commonj.connector.runtime.InboundInteractionSpec;

/**
 * Bean implementation class for Enterprise Bean: IMSInboundMessage
 */
public class IMSCalloutIVPMDBBean
	implements
		javax.ejb.MessageDrivenBean,
		com.ibm.j2ca.base.ExtendedInboundListener {

	private javax.ejb.MessageDrivenContext fMessageDrivenCtx;

	/**
	 * getMessageDrivenContext
	 */
	public javax.ejb.MessageDrivenContext getMessageDrivenContext() {
		return fMessageDrivenCtx;
	}

	/**
	 * setMessageDrivenContext
	 */
	public void setMessageDrivenContext(javax.ejb.MessageDrivenContext ctx) {
		fMessageDrivenCtx = ctx;
	}

	/**
	 * ejbCreate
	 */
	public void ejbCreate() {
	}

	/**
	 * onMessage
	 */
	public void onMessage(javax.jms.Message msg) {
	}

	/**
	 * ejbRemove
	 */
	public void ejbRemove() {
	}

	/**
	  * onMessage
	  */
	public javax.resource.cci.Record onMessage(
		javax.resource.cci.Record arg0,
		javax.resource.cci.InteractionSpec arg1)
		throws javax.resource.ResourceException {
		
		return processSyncMessageReceived(arg1);
	}

	/**
	 * onNotification
	 */
	public void onNotification(
		javax.resource.cci.Record arg0,
		javax.resource.cci.InteractionSpec arg1)
		throws javax.resource.ResourceException {
		
		processAsyncMessageReceived(arg0);	
	}

	public void onNotification(Record arg0) throws ResourceException {
		processAsyncMessageReceived(arg0);	
	}

	public Record onMessage(Record arg0) throws ResourceException {
		return processSyncMessageReceived(arg0);
	}

	public Record onMessage(InboundInteractionSpec arg0, Record arg1) 
throws ResourceException {
		return processSyncMessageReceived(arg1);
	}

	public void onNotification(InboundInteractionSpec arg0, Record arg1) 
throws ResourceException {
		processAsyncMessageReceived(arg1);	
	}
	
	/*
	 * Process synchronous callout requests from IMS and return a response
	 */
	public Record processSyncMessageReceived(Object event) {
		
        SYNCCALLOUTREQUEST request = new SYNCCALLOUTREQUEST();
		SYNCCALLOUTRESPONSE response = new SYNCCALLOUTRESPONSE();
    	
    	try {
    		// Request
    		request.setBytes(((IMSInputStreamRecord)event).getBytes());
			
			System.out.println("Synchronous callout request from IMS: " +
					request.getSync__callout__request__str());

			// Response
			response.setSync__callout__response__str("HELLO FROM WEBSPHERE MDB");

			System.out.println("Synchronous callout response from WAS MDB: " + 
					response.getSync__callout__response__str());

    	} catch (IOException e) {
        	System.err.println(e);
       }
        		
		return response;
	}
	
	/*
	 * Receive asynchonrous callout requests from IMS
	 */
	public void processAsyncMessageReceived(Object event) {
        ASYNCCALLOUTREQUEST request = new ASYNCCALLOUTREQUEST();
    	
    	try {
    		request.setBytes(((IMSInputStreamRecord)event).getBytes());
			
			System.out.println("Asynchronous callout request from IMS: " + 
				request.getAsync__callout__request__str());
			
        } catch (IOException e) {
        	System.err.println(e);
        }
	}
}

フィードバック