Previous Topic Next topic Print topic


CICS Program Call with Commarea using SSL

Sample EJB for SSL, accessing a CICS resource adapter using CommArea without extended LUW.
Note: Code in bold is specifically for SSL. You can include this same snippet in any of the sample EJBs to enable SSL.
File CommAreaEJB.java:
package com.mypackage.commareaEJB ;

import javax.ejb.Remote;
@Remote
public interface CommareaEJB {
    public byte[] First(byte[] commarea);
    public int getCobolReturnCode();
}
File CommareaEJBBean.java:
package com.mypackage.commareaEJB ;

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.CommArea;
import com.microfocus.cics.connector.ccl.AbendException;
import com.microfocus.cics.connector.ccl.AbendCodeType;
import com.microfocus.cics.connector.ccl.CommAreaSizeException;

@Stateless(name="commareaEJB", mappedName="ejb/commareaEJB")
@Remote(com.mypackage.commareaEJB.CommareaEJB.class)

public class CommareaEJBBean implements CommareaEJB, java.io.Serializable {

    @Resource (name="CCIMFCICS_v1.5", authenticationType=Resource.AuthenticationType.CONTAINER, shareable=true)
    private transient javax.resource.cci.ConnectionFactory cf;
    private boolean disposed = false;
    private String sessionId = null;
    public static final int DEFAULT_COBOL_RETURN_CODE = 2147483647;
    private int cobolReturnCode = DEFAULT_COBOL_RETURN_CODE;

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

    @PostConstruct
    public void create() {            sessionId = null;
    }

    /**
     *     @ejb:interface-method
     *     @ejb:transaction type="RequiresNew"
     *      
     *     @output byte[]	commarea
     */
     @TransactionAttribute(TransactionAttributeType.NEVER)
    public byte[] First(byte[] commarea) 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;
        com.microfocus.cics.connector.cci.MFECIInteractionSpec iSpec = null;
        try {
            initialize(true, con);
            ix = con.createInteraction();
            iSpec = new com.microfocus.cics.connector.cci.MFECIInteractionSpec();
            iSpec.setFunctionName("CASA_ECI_Function");
            iSpec.setArgument(0, com.microfocus.cobol.lang.Pointer.class,
		        	 com.microfocus.cobol.RuntimeProperties.OUTPUT_ONLY);
            iSpec.setArgument(1, com.microfocus.cobol.lang.Pointer.class,
		        	com.microfocus.cobol.RuntimeProperties.BY_VALUE);
	    iSpec.setExtendMode(CCLExtendMode.CCL_NO_EXTEND);
	    iSpec.setUserName("SYSAD");
            iSpec.setPassword("SYSAD");
	    iSpec.setProgramName("EC01");
	    iSpec.setCommArea(new CommArea(commarea));

            rf = cf.getRecordFactory();
            javax.resource.cci.IndexedRecord iRec = iSpec.getInputRecord();
            javax.resource.cci.IndexedRecord oRec = rf.createIndexedRecord("FirstOut");
            ix.execute(iSpec, iRec, oRec);
            ix.close();
            cobolReturnCode = iSpec.getReturnCode();
            CommArea returnCommArea = iSpec.getReturnCommArea();
	    byte[] retCommArea = returnCommArea.getCommArea();
	    return retCommArea;

	} catch(javax.resource.ResourceException __ex) {
            cobolReturnCode = iSpec.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 = iSpec.getReturnCode();
            throw new javax.ejb.EJBException("First threw a resource Exception", __ex);
        } catch(CommAreaSizeException __ex) {
            cobolReturnCode = iSpec.getReturnCode();
            throw new javax.ejb.EJBException("First threw a resource Exception", __ex);
        }

        finally {
            closeCobolConnection(con);
            con = null; iSpec = null; ix = null; rf = null;
            sessionId = null;
        }
    }

    void cleanup() throws javax.ejb.EJBException {
    }

    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 iSpec = new com.microfocus.cics.connector.cci.MFECIInteractionSpec();
            iSpec.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(iSpec, irec);
            ix.close();
            rf = null ; ix = null ; iSpec = 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 {

            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(false, sessionId));
    //SSL
        try {
            con.setTrustStoreName("C:/test/estrustStore.jks");
            con.setTrustStorePassword("srvrootpwd");
            } catch (Exception e) {
                throw new javax.ejb.EJBException(e); 
            }           

        } 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) {
              con.close();
            }
        } catch (javax.resource.ResourceException ex) {
            throw new javax.ejb.EJBException("Error closing a Cobol Connection: ", ex);
        }
    }

}
Previous Topic Next topic Print topic