CICS Program Call with Channels and Containers

Sample EJB accessing the WebSphere or JBoss EAP CICS resource adapter using Channel with extended LUW.
Notes:
  • For a list of supported WebSphere and JBoss application server versions, see the Java Application Servers section of the Supported Operating Systems and Third-party Software topic..
  • To enable SSL, include the SSL code snippet shown in bold in the CICS Program Call with Commarea Using SSL sample.
File Container.java:
package com.mypackage.channelEJB ;

public class Container extends com.microfocus.cics.connector.cci.MFECICustomRecord {

    private static String EMPTY_STRING = "";
    private java.lang.String containerData = EMPTY_STRING;

    public Container() {
    }

    public java.lang.String getContainerData() {
        return containerData;
    }

    public void setContainerData(java.lang.String ___p) {
        containerData = ___p ;
    }


    public Object[] getParameters() {        Object[] objs = new Object[1];

        objs[0] = containerData;
        return objs;
    }

    public void setParameters(Object[] objs) {
        containerData = (java.lang.String) objs[0];
    }

}
File Channel.java:
package com.mypackage.channelEJB ;

public class Channel extends com.microfocus.cics.connector.cci.MFECICustomRecord {

    private static String EMPTY_STRING = "";
    private Container2 container2;
    private Container1 container1;

    public class Container2 extends com.microfocus.cics.connector.cci.MFECICustomRecord {

        private java.lang.String containerData = EMPTY_STRING;

        public Container2() {
        }

        public java.lang.String getContainerData() {
            return containerData;
        }

        public void setContainerData(java.lang.String ___p) {
            containerData = ___p ;
        }


        public Object[] getParameters() {
            Object[] objs = new Object[1];
            objs[0] = containerData;
            return objs;
        }

        public void setParameters(Object[] objs) {
            containerData = (java.lang.String) objs[0];
        }

    }
    public class Container1 extends com.microfocus.cics.connector.cci.MFECICustomRecord {

        private java.lang.String containerData = EMPTY_STRING;

        public Container1() {
        }

        public java.lang.String getContainerData() {
            return containerData;
        }

        public void setContainerData(java.lang.String ___p) {
            containerData = ___p ;
        }


        public Object[] getParameters() {
            Object[] objs = new Object[1];
            objs[0] = containerData;
            return objs;
        }

        public void setParameters(Object[] objs) {
            containerData = (java.lang.String) objs[0];
        }

    }
    public Channel() {
        container2 = new Container2();
        container1 = new Container1();
    }

    public Container2 getContainer2() {
        return container2;
    }

    public void setContainer2(Container2 ___p) {
        container2 = ___p ;
    }

    public Container1 getContainer1() {
        return container1;
    }

    public void setContainer1(Container1 ___p) {
        container1 = ___p ;
    }


    public Object[] getParameters() {        Object[] objs = new Object[2];

        objs[0] = container2;
        objs[1] = container1;
        return objs;
    }

    public void setParameters(Object[] objs) {
        container2.setParameters(((Container2)objs[0]).getParameters());
        container1.setParameters(((Container1)objs[1]).getParameters());
    }

}
File ChannelEJB.java:
package com.mypackage.channelEJB ;


import javax.ejb.Remote;
import javax.ejb.EJBException;

@Remote
public interface ChannelEJB {
    public com.mypackage.channelEJB.Channel First(com.mypackage.channelEJB.Channel channel);
    public int getCobolReturnCode();
    public void removeSF() throws EJBException;
    public void passivate() throws EJBException;
    public void activate() throws EJBException;
}
WebSphere - File ChannelEJBBean.java:
package com.mypackage.channelEJB ;

import javax.ejb.Stateless;
import javax.ejb.Stateful;
import javax.ejb.EJB;
import javax.ejb.Init;
import javax.ejb.Remove;
import javax.ejb.PostActivate;
import javax.ejb.PrePassivate;
import javax.ejb.EJBException;
import javax.annotation.Resource;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.ejb.Remote;
import com.microfocus.cics.connector.ccl.CCLExtendMode;
import com.microfocus.cics.connector.ccl.CCLChannel;
import com.microfocus.cics.connector.ccl.CCLContainer;
import com.microfocus.cics.connector.ccl.ContainerData;
import com.microfocus.cics.connector.ccl.AbendException;
import com.microfocus.cics.connector.ccl.AbendCodeType;

import java.util.List;

@Stateful(name="channelEJB", mappedName="ejb/channelEJB")
@Remote(com.mypackage.channelEJB.ChannelEJB.class)

public class ChannelEJBBean implements ChannelEJB, java.io.Serializable {

     @Resource (name="CCIMFCICS_v1.5", authenticationType=Resource.AuthenticationType.CONTAINER, shareable=false)
    private transient javax.resource.cci.ConnectionFactory cf;
    private boolean disposed = false;
    private String sessionId = null;
    private transient javax.resource.cci.Connection lastConnectionHandle = null;
    private boolean doInitialize = true;
    public static final int DEFAULT_COBOL_RETURN_CODE = 2147483647;
    private int cobolReturnCode = DEFAULT_COBOL_RETURN_CODE;
    com.microfocus.cics.connector.cci.MFECIInteractionSpec interactionSpec = new com.microfocus.cics.connector.cci.MFECIInteractionSpec();

    public javax.resource.cci.ConnectionFactory getConnectionFactory() {
          return cf ;
    }

    @PostConstruct
    public void create() {           
	    disposed = false;
            sessionId = null;
	    interactionSpec.setFunctionName("CASA_ECI_Function");
            interactionSpec.setArgument(0, com.microfocus.cobol.lang.Pointer.class,
		        	 com.microfocus.cobol.RuntimeProperties.OUTPUT_ONLY);
            interactionSpec.setArgument(1, com.microfocus.cobol.lang.Pointer.class,
		        	com.microfocus.cobol.RuntimeProperties.BY_VALUE);
	    interactionSpec.setUserName("SYSAD");
            interactionSpec.setPassword("SYSAD");
	    interactionSpec.setProgramName("EC03");
    }


     @TransactionAttribute(TransactionAttributeType.NEVER)
    public com.mypackage.channelEJB.Channel First(com.mypackage.channelEJB.Channel channel) throws javax.ejb.EJBException {
        javax.resource.cci.Connection con = null;
        disposed = false;
        con = getCobolConnection();
        javax.resource.cci.RecordFactory rf = null;
        javax.resource.cci.Interaction ix = null;
        try {
            if(doInitialize) {
                initialize(false, con);
                doInitialize = false;
            }
            ix = con.createInteraction();

	    interactionSpec.setExtendMode(CCLExtendMode.CCL_EXTENDED);
            ix = con.createInteraction();
	    
            CCLChannel cclChannel = new CCLChannel("GenChannel");
	    CCLContainer cclContainer1 = new CCLContainer("GenCon1");
	    CCLContainer cclContainer2 = new CCLContainer("GenCon2");
	    byte[] cData1 = channel.getContainer1().getContainerData().getBytes();
	    byte[] cData2 = channel.getContainer2().getContainerData().getBytes();
	    ContainerData cd1 = new ContainerData(cData1);
            ContainerData cd2 = new ContainerData(cData2);
	    cclContainer1.setContainerData(cd1);
            cclContainer2.setContainerData(cd2);
            cclChannel.addContainer(cclContainer1);
            cclChannel.addContainer(cclContainer2);
	    interactionSpec.setChannel(cclChannel);
            rf = cf.getRecordFactory();
            javax.resource.cci.IndexedRecord oRec = rf.createIndexedRecord("FirstOut");
            javax.resource.cci.IndexedRecord iRec = interactionSpec.getInputRecord();	    
            ix.execute(interactionSpec, iRec, oRec);
            ix.close();
            cobolReturnCode = interactionSpec.getReturnCode();
            CCLChannel returnChannel = interactionSpec.getReturnChannel();
	    com.mypackage.channelEJB.Channel retFromEJBChannel = new com.mypackage.channelEJB.Channel();
	    if(returnChannel != null) {
		    List<CCLContainer> containers = returnChannel.getContainers();
		    int count = 0;
		    for(CCLContainer container: containers) {
                        if(count == 0) {
				retFromEJBChannel.getContainer1().setContainerData(new String(container.getContainerData().getContainerData()));
				count++;
			}
			if(count == 1) {
				retFromEJBChannel.getContainer2().setContainerData(new String(container.getContainerData().getContainerData()));
				count++;
			}
	            }
	    }
	    return retFromEJBChannel;
		    

        } catch(javax.resource.ResourceException __ex) {
            cobolReturnCode = interactionSpec.getReturnCode();
	    Exception linkedEx = __ex.getLinkedException();
	    if(linkedEx instanceof AbendException) {
		AbendException aex = (AbendException) linkedEx;    
		System.out.println("AbendCode = " + aex.getAbendCode());
		System.out.println("Abend Code Type = " + aex.getAbendCodeType());
	    }
            throw new javax.ejb.EJBException("First threw a resource Exception", __ex);
        } catch(java.io.UnsupportedEncodingException __ex) {
            cobolReturnCode = interactionSpec.getReturnCode();
            throw new javax.ejb.EJBException("First threw a resource Exception", __ex);
        }
        finally {
            closeCobolConnection(con);
            ix = null; rf = null;
        }
    }

        @TransactionAttribute(TransactionAttributeType.NEVER)
    public  com.mypackage.channelEJB.Channel commit() throws javax.ejb.EJBException {
        javax.resource.cci.Connection con = null;
        disposed = false;
        con = getCobolConnection();
        javax.resource.cci.RecordFactory rf = null;
        javax.resource.cci.Interaction ix = null;
        try {
            if(doInitialize) {
                initialize(false, con);
                doInitialize = false;
            }
            ix = con.createInteraction();
	    interactionSpec.setExtendMode(CCLExtendMode.CCL_COMMIT);
	    rf = cf.getRecordFactory();
            javax.resource.cci.IndexedRecord iRec = interactionSpec.getInputRecord();	    
            javax.resource.cci.IndexedRecord oRec = rf.createIndexedRecord("FirstOut");
            ix.execute(interactionSpec, iRec, oRec);
            ix.close();
            cobolReturnCode = interactionSpec.getReturnCode();
            CCLChannel returnChannel = interactionSpec.getReturnChannel();
	    com.mypackage.channelEJB.Channel retFromEJBChannel = new com.mypackage.channelEJB.Channel();
	    if(returnChannel != null) {
		    List<CCLContainer> containers = returnChannel.getContainers();
		    int count = 0;
		    for(CCLContainer container: containers) {
                        if(count == 0) {
				retFromEJBChannel.getContainer1().setContainerData(new String(container.getContainerData().getContainerData()));
				count++;
			}
			if(count == 1) {
				retFromEJBChannel.getContainer2().setContainerData(new String(container.getContainerData().getContainerData()));
				count++;
			}
	            }
	    }
	    return retFromEJBChannel;
        } catch(javax.resource.ResourceException __ex) {
            cobolReturnCode = interactionSpec.getReturnCode();
	    Exception linkedEx = __ex.getLinkedException();
	    if(linkedEx instanceof AbendException) {
		AbendException aex = (AbendException) linkedEx;    
		System.out.println("AbendCode = " + aex.getAbendCode());
		System.out.println("Abend Code Type = " + aex.getAbendCodeType());
	    }
            throw new javax.ejb.EJBException("First threw a resource Exception", __ex);
        } catch(java.io.UnsupportedEncodingException __ex) {
            cobolReturnCode = interactionSpec.getReturnCode();
            throw new javax.ejb.EJBException("First threw a resource Exception", __ex);
        }
        finally {
            closeCobolConnection(con);
            interactionSpec = null; ix = null; rf = null;
        }
    }

             @TransactionAttribute(TransactionAttributeType.NEVER)
    public  com.mypackage.channelEJB.Channel rollback() throws javax.ejb.EJBException {
        javax.resource.cci.Connection con = null;
        disposed = false;
        con = getCobolConnection();
        javax.resource.cci.RecordFactory rf = null;
        javax.resource.cci.Interaction ix = null;
        try {
            if(doInitialize) {
                initialize(false, con);
                doInitialize = false;
            }
            ix = con.createInteraction();
	    interactionSpec.setExtendMode(CCLExtendMode.CCL_BACKOUT);
            rf = cf.getRecordFactory();
            javax.resource.cci.IndexedRecord iRec = interactionSpec.getInputRecord();
            javax.resource.cci.IndexedRecord oRec = rf.createIndexedRecord("FirstOut");
            ix.execute(interactionSpec, iRec, oRec);
            ix.close();
            cobolReturnCode = interactionSpec.getReturnCode();
             CCLChannel returnChannel = interactionSpec.getReturnChannel();
	    com.mypackage.channelEJB.Channel retFromEJBChannel = new com.mypackage.channelEJB.Channel();
	    if(returnChannel != null) {
		    List<CCLContainer> containers = returnChannel.getContainers();
		    int count = 0;
		    for(CCLContainer container: containers) {
                        if(count == 0) {
				retFromEJBChannel.getContainer1().setContainerData(new String(container.getContainerData().getContainerData()));
				count++;
			}
			if(count == 1) {
				retFromEJBChannel.getContainer2().setContainerData(new String(container.getContainerData().getContainerData()));
				count++;
			}
	            }
	    }
	    return retFromEJBChannel;

        } catch(javax.resource.ResourceException __ex) {
            cobolReturnCode = interactionSpec.getReturnCode();
	    Exception linkedEx = __ex.getLinkedException();
	    if(linkedEx instanceof AbendException) {
		AbendException aex = (AbendException) linkedEx;    
		System.out.println("AbendCode = " + aex.getAbendCode());
		System.out.println("Abend Code Type = " + aex.getAbendCodeType());
	    }
            throw new javax.ejb.EJBException("First threw a resource Exception", __ex);
        } catch(java.io.UnsupportedEncodingException __ex) {
            cobolReturnCode = interactionSpec.getReturnCode();
            throw new javax.ejb.EJBException("First threw a resource Exception", __ex);
        } 
        finally {
            closeCobolConnection(con);
            interactionSpec = null; ix = null; rf = null;
        }
    }

    @Remove
    public void removeSF() {
            cleanup();
    }

    void cleanup() throws javax.ejb.EJBException {
       try {
            if(!disposed) {
                if(lastConnectionHandle != null) {
                  com.microfocus.cics.connector.cci.MFECIConnection.dispose(sessionId);
                  closeCobolConnection(lastConnectionHandle);
                }
                else {
                  com.microfocus.cics.connector.cci.MFECIConnection.dispose(sessionId);
                }
              disposed = true ;
            }
       } catch(javax.resource.ResourceException ex) {
            throw new javax.ejb.EJBException("Error disposing a Cobol Connection: ", ex);
       }
       finally {
           lastConnectionHandle = null;
           cf = null;
       }
    }

    public int getCobolReturnCode() throws javax.ejb.EJBException {
         return cobolReturnCode;
    }

    @PrePassivate
    public void passivate() throws javax.ejb.EJBException {
    }

    @PostActivate
    public void activate() throws javax.ejb.EJBException {
    }

    private void initialize(boolean isInitial, javax.resource.cci.Connection con) throws javax.ejb.EJBException {
        try {
            javax.resource.cci.Interaction ix = con.createInteraction();
            com.microfocus.cics.connector.cci.MFECIInteractionSpec interactionSpec = new com.microfocus.cics.connector.cci.MFECIInteractionSpec();
            interactionSpec.setFunctionName("initialize");
            javax.resource.cci.RecordFactory rf = cf.getRecordFactory();
            javax.resource.cci.IndexedRecord irec = rf.createIndexedRecord("beanArgs");
            irec.add(new Boolean(isInitial));
            javax.resource.cci.Record orec = ix.execute(interactionSpec, irec);
            ix.close();
            rf = null ; ix = null ; interactionSpec = null ; irec = null ;
        } catch(javax.resource.ResourceException ex) {
            throw new javax.ejb.EJBException("initialize threw ResourceException: ", ex);
        }
    }

    private javax.resource.cci.Connection getCobolConnection() throws javax.ejb.EJBException {


    //SSL
        try {
           con.setTrustStoreName("C:/test/estrustStore.jks");
           con.setTrustStorePassword("srvrootpwd");
        } catch (Exception e) {
            throw new javax.ejb.EJBException(e); 
        }  



            com.microfocus.cics.connector.cci.MFECIConnection con = null;
        try {
            con = (com.microfocus.cics.connector.cci.MFECIConnection) cf.getConnection(new com.microfocus.cics.connector.cci.MFECIConnectionSpec(true, true, sessionId));
            lastConnectionHandle = con; 

        } catch (javax.resource.ResourceException ex) {
             throw new javax.ejb.EJBException("Error getting a Cobol Connection: ", ex);
        }
        return con ;
    }

    private void closeCobolConnection(javax.resource.cci.Connection con) throws javax.ejb.EJBException {
        try {
            if(con != null) {
             if(sessionId == null) {
                 sessionId = ((com.microfocus.cics.connector.cci.MFECIConnection)con).getSessionId();
             }
              con.close();
            }
        } catch (javax.resource.ResourceException ex) {
            throw new javax.ejb.EJBException("Error closing a Cobol Connection: ", ex);
        }
    }
}
JBoss EAP - File ChannelEJBBean.java:
package com.mypackage.channelEJB ;

import javax.ejb.Stateless;
import javax.ejb.Stateful;
import javax.ejb.EJB;
import javax.ejb.Init;
import javax.ejb.Remove;
import javax.ejb.PostActivate;
import javax.ejb.PrePassivate;
import javax.ejb.EJBException;
import javax.annotation.Resource;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.ejb.Remote;
import com.microfocus.cics.connector.ccl.CCLExtendMode;
import com.microfocus.cics.connector.ccl.CCLChannel;
import com.microfocus.cics.connector.ccl.CCLContainer;
import com.microfocus.cics.connector.ccl.ContainerData;
import com.microfocus.cics.connector.ccl.AbendException;
import com.microfocus.cics.connector.ccl.AbendCodeType;

import java.util.List;

@Stateful(name="channelEJB", mappedName="ejb/channelEJB")
@Remote(com.mypackage.channelEJB.ChannelEJB.class)

public class ChannelEJBBean implements ChannelEJB, java.io.Serializable {

     @Resource (name="CCIMFCICS_v1.5", authenticationType=Resource.AuthenticationType.CONTAINER, shareable=false, mappedName="java:/eis/MFCICS_v1.5")
    private transient javax.resource.cci.ConnectionFactory cf;
    private boolean disposed = false;
    private String sessionId = null;
    private transient javax.resource.cci.Connection lastConnectionHandle = null;
    private boolean doInitialize = true;
    public static final int DEFAULT_COBOL_RETURN_CODE = 2147483647;
    private int cobolReturnCode = DEFAULT_COBOL_RETURN_CODE;
    com.microfocus.cics.connector.cci.MFECIInteractionSpec interactionSpec = new com.microfocus.cics.connector.cci.MFECIInteractionSpec();

    public javax.resource.cci.ConnectionFactory getConnectionFactory() {
          return cf ;
    }

    @PostConstruct
    public void create() {           
	    disposed = false;
            sessionId = null;
	    interactionSpec.setFunctionName("CASA_ECI_Function");
            interactionSpec.setArgument(0, com.microfocus.cobol.lang.Pointer.class,
		        	 com.microfocus.cobol.RuntimeProperties.OUTPUT_ONLY);
            interactionSpec.setArgument(1, com.microfocus.cobol.lang.Pointer.class,
		        	com.microfocus.cobol.RuntimeProperties.BY_VALUE);
	    interactionSpec.setUserName("SYSAD");
            interactionSpec.setPassword("SYSAD");
	    interactionSpec.setProgramName("EC03");
    }


     @TransactionAttribute(TransactionAttributeType.NEVER)
    public com.mypackage.channelEJB.Channel First(com.mypackage.channelEJB.Channel channel) throws javax.ejb.EJBException {
        javax.resource.cci.Connection con = null;
        disposed = false;
        con = getCobolConnection();
        javax.resource.cci.RecordFactory rf = null;
        javax.resource.cci.Interaction ix = null;
        try {
            if(doInitialize) {
                initialize(false, con);
                doInitialize = false;
            }
            ix = con.createInteraction();

	    interactionSpec.setExtendMode(CCLExtendMode.CCL_EXTENDED);
            ix = con.createInteraction();
	    
            CCLChannel cclChannel = new CCLChannel("GenChannel");
	    CCLContainer cclContainer1 = new CCLContainer("GenCon1");
	    CCLContainer cclContainer2 = new CCLContainer("GenCon2");
	    byte[] cData1 = channel.getContainer1().getContainerData().getBytes();
	    byte[] cData2 = channel.getContainer2().getContainerData().getBytes();
	    ContainerData cd1 = new ContainerData(cData1);
            ContainerData cd2 = new ContainerData(cData2);
	    cclContainer1.setContainerData(cd1);
            cclContainer2.setContainerData(cd2);
            cclChannel.addContainer(cclContainer1);
            cclChannel.addContainer(cclContainer2);
	    interactionSpec.setChannel(cclChannel);
            rf = cf.getRecordFactory();
            javax.resource.cci.IndexedRecord oRec = rf.createIndexedRecord("FirstOut");
            javax.resource.cci.IndexedRecord iRec = interactionSpec.getInputRecord();	    
            ix.execute(interactionSpec, iRec, oRec);
            ix.close();
            cobolReturnCode = interactionSpec.getReturnCode();
            CCLChannel returnChannel = interactionSpec.getReturnChannel();
	    com.mypackage.channelEJB.Channel retFromEJBChannel = new com.mypackage.channelEJB.Channel();
	    if(returnChannel != null) {
		    List<CCLContainer> containers = returnChannel.getContainers();
		    int count = 0;
		    for(CCLContainer container: containers) {
                        if(count == 0) {
				retFromEJBChannel.getContainer1().setContainerData(new String(container.getContainerData().getContainerData()));
				count++;
			}
			if(count == 1) {
				retFromEJBChannel.getContainer2().setContainerData(new String(container.getContainerData().getContainerData()));
				count++;
			}
	            }
	    }
	    return retFromEJBChannel;
		    

        } catch(javax.resource.ResourceException __ex) {
            cobolReturnCode = interactionSpec.getReturnCode();
	    Exception linkedEx = __ex.getLinkedException();
	    if(linkedEx instanceof AbendException) {
		AbendException aex = (AbendException) linkedEx;    
		System.out.println("AbendCode = " + aex.getAbendCode());
		System.out.println("Abend Code Type = " + aex.getAbendCodeType());
	    }
            throw new javax.ejb.EJBException("First threw a resource Exception", __ex);
        } catch(java.io.UnsupportedEncodingException __ex) {
            cobolReturnCode = interactionSpec.getReturnCode();
            throw new javax.ejb.EJBException("First threw a resource Exception", __ex);
        }
        finally {
            closeCobolConnection(con);
            ix = null; rf = null;
        }
    }

        @TransactionAttribute(TransactionAttributeType.NEVER)
    public  com.mypackage.channelEJB.Channel commit() throws javax.ejb.EJBException {
        javax.resource.cci.Connection con = null;
        disposed = false;
        con = getCobolConnection();
        javax.resource.cci.RecordFactory rf = null;
        javax.resource.cci.Interaction ix = null;
        try {
            if(doInitialize) {
                initialize(false, con);
                doInitialize = false;
            }
            ix = con.createInteraction();
	    interactionSpec.setExtendMode(CCLExtendMode.CCL_COMMIT);
	    rf = cf.getRecordFactory();
            javax.resource.cci.IndexedRecord iRec = interactionSpec.getInputRecord();	    
            javax.resource.cci.IndexedRecord oRec = rf.createIndexedRecord("FirstOut");
            ix.execute(interactionSpec, iRec, oRec);
            ix.close();
            cobolReturnCode = interactionSpec.getReturnCode();
            CCLChannel returnChannel = interactionSpec.getReturnChannel();
	    com.mypackage.channelEJB.Channel retFromEJBChannel = new com.mypackage.channelEJB.Channel();
	    if(returnChannel != null) {
		    List<CCLContainer> containers = returnChannel.getContainers();
		    int count = 0;
		    for(CCLContainer container: containers) {
                        if(count == 0) {
				retFromEJBChannel.getContainer1().setContainerData(new String(container.getContainerData().getContainerData()));
				count++;
			}
			if(count == 1) {
				retFromEJBChannel.getContainer2().setContainerData(new String(container.getContainerData().getContainerData()));
				count++;
			}
	            }
	    }
	    return retFromEJBChannel;
        } catch(javax.resource.ResourceException __ex) {
            cobolReturnCode = interactionSpec.getReturnCode();
	    Exception linkedEx = __ex.getLinkedException();
	    if(linkedEx instanceof AbendException) {
		AbendException aex = (AbendException) linkedEx;    
		System.out.println("AbendCode = " + aex.getAbendCode());
		System.out.println("Abend Code Type = " + aex.getAbendCodeType());
	    }
            throw new javax.ejb.EJBException("First threw a resource Exception", __ex);
        } catch(java.io.UnsupportedEncodingException __ex) {
            cobolReturnCode = interactionSpec.getReturnCode();
            throw new javax.ejb.EJBException("First threw a resource Exception", __ex);
        }
        finally {
            closeCobolConnection(con);
            interactionSpec = null; ix = null; rf = null;
        }
    }

             @TransactionAttribute(TransactionAttributeType.NEVER)
    public  com.mypackage.channelEJB.Channel rollback() throws javax.ejb.EJBException {
        javax.resource.cci.Connection con = null;
        disposed = false;
        con = getCobolConnection();
        javax.resource.cci.RecordFactory rf = null;
        javax.resource.cci.Interaction ix = null;
        try {
            if(doInitialize) {
                initialize(false, con);
                doInitialize = false;
            }
            ix = con.createInteraction();
	    interactionSpec.setExtendMode(CCLExtendMode.CCL_BACKOUT);
            rf = cf.getRecordFactory();
            javax.resource.cci.IndexedRecord iRec = interactionSpec.getInputRecord();
            javax.resource.cci.IndexedRecord oRec = rf.createIndexedRecord("FirstOut");
            ix.execute(interactionSpec, iRec, oRec);
            ix.close();
            cobolReturnCode = interactionSpec.getReturnCode();
             CCLChannel returnChannel = interactionSpec.getReturnChannel();
	    com.mypackage.channelEJB.Channel retFromEJBChannel = new com.mypackage.channelEJB.Channel();
	    if(returnChannel != null) {
		    List<CCLContainer> containers = returnChannel.getContainers();
		    int count = 0;
		    for(CCLContainer container: containers) {
                        if(count == 0) {
				retFromEJBChannel.getContainer1().setContainerData(new String(container.getContainerData().getContainerData()));
				count++;
			}
			if(count == 1) {
				retFromEJBChannel.getContainer2().setContainerData(new String(container.getContainerData().getContainerData()));
				count++;
			}
	            }
	    }
	    return retFromEJBChannel;

        } catch(javax.resource.ResourceException __ex) {
            cobolReturnCode = interactionSpec.getReturnCode();
	    Exception linkedEx = __ex.getLinkedException();
	    if(linkedEx instanceof AbendException) {
		AbendException aex = (AbendException) linkedEx;    
		System.out.println("AbendCode = " + aex.getAbendCode());
		System.out.println("Abend Code Type = " + aex.getAbendCodeType());
	    }
            throw new javax.ejb.EJBException("First threw a resource Exception", __ex);
        } catch(java.io.UnsupportedEncodingException __ex) {
            cobolReturnCode = interactionSpec.getReturnCode();
            throw new javax.ejb.EJBException("First threw a resource Exception", __ex);
        } 
        finally {
            closeCobolConnection(con);
            interactionSpec = null; ix = null; rf = null;
        }
    }

    @Remove
    public void removeSF() {
            cleanup();
    }

    void cleanup() throws javax.ejb.EJBException {
       try {
            if(!disposed) {
                if(lastConnectionHandle != null) {
                  com.microfocus.cics.connector.cci.MFECIConnection.dispose(sessionId);
                  closeCobolConnection(lastConnectionHandle);
                }
                else {
                  com.microfocus.cics.connector.cci.MFECIConnection.dispose(sessionId);
                }
              disposed = true ;
            }
       } catch(javax.resource.ResourceException ex) {
            throw new javax.ejb.EJBException("Error disposing a Cobol Connection: ", ex);
       }
       finally {
           lastConnectionHandle = null;
           cf = null;
       }
    }

    public int getCobolReturnCode() throws javax.ejb.EJBException {
         return cobolReturnCode;
    }

    @PrePassivate
    public void passivate() throws javax.ejb.EJBException {
    }

    @PostActivate
    public void activate() throws javax.ejb.EJBException {
    }

    private void initialize(boolean isInitial, javax.resource.cci.Connection con) throws javax.ejb.EJBException {
        try {
            javax.resource.cci.Interaction ix = con.createInteraction();
            com.microfocus.cics.connector.cci.MFECIInteractionSpec interactionSpec = new com.microfocus.cics.connector.cci.MFECIInteractionSpec();
            interactionSpec.setFunctionName("initialize");
            javax.resource.cci.RecordFactory rf = cf.getRecordFactory();
            javax.resource.cci.IndexedRecord irec = rf.createIndexedRecord("beanArgs");
            irec.add(new Boolean(isInitial));
            javax.resource.cci.Record orec = ix.execute(interactionSpec, irec);
            ix.close();
            rf = null ; ix = null ; interactionSpec = null ; irec = null ;
        } catch(javax.resource.ResourceException ex) {
            throw new javax.ejb.EJBException("initialize threw ResourceException: ", ex);
        }
    }

    private javax.resource.cci.Connection getCobolConnection() throws javax.ejb.EJBException {


    //SSL
        try {
           con.setTrustStoreName("C:/test/estrustStore.jks");
           con.setTrustStorePassword("srvrootpwd");
        } catch (Exception e) {
            throw new javax.ejb.EJBException(e); 
        }  



            com.microfocus.cics.connector.cci.MFECIConnection con = null;
        try {
            con = (com.microfocus.cics.connector.cci.MFECIConnection) cf.getConnection(new com.microfocus.cics.connector.cci.MFECIConnectionSpec(true, true, sessionId));
            lastConnectionHandle = con; 

        } catch (javax.resource.ResourceException ex) {
             throw new javax.ejb.EJBException("Error getting a Cobol Connection: ", ex);
        }
        return con ;
    }

    private void closeCobolConnection(javax.resource.cci.Connection con) throws javax.ejb.EJBException {
        try {
            if(con != null) {
             if(sessionId == null) {
                 sessionId = ((com.microfocus.cics.connector.cci.MFECIConnection)con).getSessionId();
             }
              con.close();
            }
        } catch (javax.resource.ResourceException ex) {
            throw new javax.ejb.EJBException("Error closing a Cobol Connection: ", ex);
        }
    }
}