CICS ECI Liberty

2019-08-23 08:08发布

问题:

I am trying to use the JCA and CICSECI functionality to connect to IBM Mainframe via the CICS Transaction Gateway.

My Servlet code is:

package com.ebs.jca.web;

import java.io.IOException;

import javax.annotation.Resource;
import javax.resource.ResourceException;
import javax.resource.cci.Connection;
import javax.resource.cci.ConnectionFactory;
import javax.resource.cci.Interaction;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ebs.cics.copybook.T060.T060REQUEST;
import com.ebs.cics.copybook.T060.T060RESPONSE;
import com.ibm.connector2.cics.ECIInteractionSpec;

/**
 * Servlet implementation class CICSServlet1
 */
@WebServlet("/CICSServlet1")
public class CICSServlet1 extends HttpServlet {
    private static final long serialVersionUID = 1L;

    @Resource(lookup="eis/cicsECI_CF")
    private ConnectionFactory cf = null;


    /**
     * @see HttpServlet#HttpServlet()
     */
    public CICSServlet1() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        T060REQUEST t060Req = new T060REQUEST();
        t060Req.setAccountNumber("10917683");
        t060Req.setApplication("ST");
        t060Req.setTransactionId("T060");


        T060RESPONSE t060Resp = new T060RESPONSE();
        try {
            Connection eciConn = cf.getConnection();
            Interaction eciInt = eciConn.createInteraction();


            // Setup the interactionSpec.
            ECIInteractionSpec eSpec = new ECIInteractionSpec();
            eSpec.setCommareaLength(8000);
            //eSpec.setReplyLength(20);
            eSpec.setFunctionName("EBOT060");
            eSpec.setInteractionVerb(ECIInteractionSpec.SYNC_SEND_RECEIVE);

            eciInt.execute(eSpec, t060Req, t060Resp);
            //eciInt.execute(eSpec, t060Req, t060Resp);
            /*System.out.println("return code is:");
            System.out.println(t060Resp.getReturnCode());

            icbResp.setResp__code(Short.toString(t060Resp.getReturnCode()));
            icbResp.setResp__text(t060Resp.getReturnText());*/
        } catch (ResourceException e) {
            e.printStackTrace();
            //throw e;
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }


        response.getWriter().append("Resp: ").append(Short.toString(t060Resp.getReturnCode())).append(", text: ").append(t060Resp.getReturnText());
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }

}

The exeption that I am getting is:

[err] com.ibm.connector2.cics.CICSUserInputException: CTG9628E InteractionSpec passed to execute() not of type ECIInteractionSpec
[err]   at com.ibm.connector2.cics.ECIInteraction.execute(Unknown Source)
[err]   at com.ebs.jca.web.CICSServlet1.doGet(CICSServlet1.java:62)
[err]   at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
[err]   at [internal classes]
[err]   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[err]   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[err]   at java.lang.Thread.run(Thread.java:748)

My server.xml is as follows:

<server description="new server">

    <!-- Enable features -->
     <featureManager>
        <feature>localConnector-1.0</feature>
        <feature>javaee-7.0</feature>
        <feature>jca-1.7</feature>
    </featureManager>

    <keyStore id="defaultKeyStore" password="{xor}NDomDCswLToPKDs="/>

    <!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" -->
    <httpEndpoint httpPort="9080" httpsPort="9443" id="defaultHttpEndpoint"/>

    <!-- Automatically expand WAR files and EAR files -->
    <applicationManager autoExpand="true"/>


    <library id="ebsPropertiesFiles">
       <folder dir="C:\ICBFiles\Properties\EBS\"/>
    </library>

    <!--The location of the cicseci.rar needs to be updated to the full path-->
   <resourceAdapter autoStart="true" id="eciResourceAdapter" location="C:\ICBFiles\SharedLibs\cicseci9002.rar"/>

   <connectionFactory id="cicsECI_CF" jndiName="eis/cicsECI_CF">
      <!--The properties need to be updated to the location of the CICS Transaction Gateway-->
      <properties.eciResourceAdapter ServerName="CICSQ2V5" connectionUrl="tcp://EBS-WSDEV2-2012.ad.xxx.pri" portNumber="2006"/>
   </connectionFactory>


    <applicationMonitor updateTrigger="mbean"/>


    <webApplication id="jca-web" location="jca-web.war" name="jca-web"/>
</server>

And my POM is:

<?xml version="1.0" encoding="UTF-8"?>
<project
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
    xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <licenses>
        <license>
            <name>The Apache Software License, Version 2.0</name>
            <url>https://raw.github.com/WASdev/ci.maven.tools/master/LICENSE</url>
            <distribution>repo</distribution>
        </license>
    </licenses>

    <modelVersion>4.0.0</modelVersion>

  <groupId>com.ebs.jca</groupId>
  <artifactId>jca-web</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>

  <name>jca-web</name>
  <url>http://maven.apache.org</url>

  <dependencies>
        <dependency>
            <groupId>net.wasdev.maven.tools.targets</groupId>
            <artifactId>liberty-target</artifactId>
            <version>RELEASE</version>
            <type>pom</type>
            <scope>provided</scope>
        </dependency>

    <dependency>
      <groupId>com.ibm.websphere.ws</groupId>
      <artifactId>wsadie.marshall</artifactId>
      <version>1.0.0</version>
      <type>jar</type>
     <!--  <scope>provided</scope> -->
    </dependency>
    <dependency>
      <groupId>com.ebs.cics.copybooks</groupId>
      <artifactId>T060</artifactId>
      <version>1.2.0</version>
      <type>jar</type>
    </dependency>

    <dependency>
      <groupId>javax.resource</groupId>
      <artifactId>javax.resource-api</artifactId>
      <version>1.7.1</version>
    </dependency>   
   <dependency>
    <groupId>com.ibm.cicseci</groupId>
      <artifactId>cicseci</artifactId>
      <version>9.0.0</version>
      <type>jar</type>

    </dependency>    
    <dependency>
    <groupId>com.ibm.cicseci</groupId>
      <artifactId>cicsframe</artifactId>
      <version>9.0.0</version>
      <type>jar</type>

    </dependency>  

  </dependencies>

  <build>
    <finalName>${project.name}</finalName>
    <plugins>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.1.1</version>
        <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.0.2</version>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

When I google the error code. The IBM docs state: https://www.ibm.com/support/knowledgecenter/en/SSZHFX_9.2.0/CTG9628E.html

"Review your Java client application. Refer to the product documentation for further details."

I have reviewed the following tutorials but they do not show a complete build environment. https://developer.ibm.com/cics/2014/05/06/using-jca-with-the-cics-tg-in-websphere-liberty-profile/ https://github.com/cicsdev/cicstg-jca-liberty-sample

And I get the same error when using the sample code.

I have also tried to setting up a connectionFactory as described in this link:

https://www.ibm.com/support/knowledgecenter/SSGMCP_5.3.0/com.ibm.cics.ts.java.doc/topics/dfhpj2_jca_remote_eci_devconfig.html

When I set up a connectionFactory as shown:

<connectionFactory id="com.ibm.cics.wlp.jca.local.eci" jndiName="eis/ECI">
    <properties.com.ibm.cics.wlp.jca.remote.eci serverName="CICSQ2V5" connectionUrl="tcp://EBS-WSDEV2-2012.ad.xxxx.pri" portNumber="2006"/>
   </connectionFactory>

the dependency injection breaks.

CWNEN0030E: The server was unable to obtain an object instance for the java:comp/env/com.ibm.ctg.samples.liberty.JCAServlet/cf reference.  The exception message was: CWNEN1003E: The server was unable to find the eis/ECI binding with the javax.resource.cci.ConnectionFactory type for the java:comp/env/com.ibm.ctg.samples.liberty.JCAServlet/cf reference.

Many Thanks

回答1:

Looking at your server.xml configuration, the web application doesn't have the classloader definition required to load the InteractionSpec class from the resource adapters.

So it should be specified as

<webApplication id="jca-web" location="jca-web.war" name="jca-web">
   <classloader classProviderRef="eciResourceAdapter" />
</webApplication>


回答2:

Posting the process that I have followed to solve the issue. There was obviously a class version conflict as stated by Trilarion and crshnburn.

Thanks for the help.

1 Install new Liberty profile.

2 Extract the cics.jar from the RAR archive for compile purposes.

3 Do not include the jcaRemoteEci-1.0 feature in the server.xml.

4 Use the following server.xml:

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

    <!-- Enable features -->
    <featureManager>
        <feature>javaee-7.0</feature>
        <feature>localConnector-1.0</feature>
    </featureManager>

    <!-- Encoded password can be generated using bin/securityUtility -->
    <keyStore password="change1me"/>

    <basicRegistry id="basic" realm="BasicRealm">
        <user name="user1" password="change1me"/>
    </basicRegistry>

    <!-- Automatically expand WAR files and EAR files -->
    <applicationManager autoExpand="true"/>

    <library id="ebsPropertiesFiles">
       <folder dir="C:\\ICBFiles\\Properties\\EBS" />
    </library>

    <!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" -->
    <httpEndpoint id="defaultHttpEndpoint"
                  httpPort="9080"
                  httpsPort="9443" />

    <!--The location of the cicseci.rar needs to be updated to the full path-->
    <resourceAdapter autoStart="true" id="eciResourceAdapter" location="C:\ICBFiles\SharedLibs\cicseci9200.rar"/>

    <connectionFactory id="cicsECI_CF" jndiName="eis/cicsECI_CF">
        <!--The properties need to be updated to the location of the CICS Transaction Gateway-->
        <properties.eciResourceAdapter connectionUrl="tcp://EBS-WSDEV2-2012.ad.aib.pri" portNumber="2006" ServerName="CICSUWV5"/>
    </connectionFactory>

    <enterpriseApplication id="icb-liberty-ear" location="icb-liberty-ear.ear" name="icb-liberty-ear">
       <classloader commonLibraryRef="ebsPropertiesFiles" classProviderRef="eciResourceAdapter"/>
    </enterpriseApplication>
</server>

4 Use the following pom.xml. Note that cicseci is defined with the 'provided' scope allow compiler dependency but to avoid packaging into the war archive.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>com.icb</groupId>
    <artifactId>icb-liberty</artifactId>
    <version>1.0</version>
  </parent>

  <artifactId>icb-liberty-war</artifactId>
  <packaging>war</packaging>

  <name>ICB WAR Module</name>

  <properties>
    <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <log4j.version>2.8.2</log4j.version>
    <apache.commons.version>3.5</apache.commons.version>
  </properties>

  <dependencies>

    <dependency>
      <groupId>javax</groupId>
      <artifactId>javaee-api</artifactId>
      <version>7.0</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>    
    <dependency>
    <groupId>com.ibm.cicseci</groupId>
      <artifactId>cicseci</artifactId>
      <version>9.0.0</version>
      <type>jar</type>
      <scope>provided</scope>
    </dependency>    
    <dependency>
      <groupId>com.ibm.websphere.ws</groupId>
      <artifactId>wsadie.marshall</artifactId>
      <version>1.0.0</version>
      <type>jar</type>
    </dependency>
    <dependency>
      <groupId>com.ebs.cics.copybooks</groupId>
      <artifactId>LAICBRES</artifactId>
      <version>1.0.0</version>
      <type>jar</type>
    </dependency>
  </dependencies>

  <build>
    <finalName>icb-liberty-war</finalName>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>3.2.0</version>
        <configuration>         
          <webXml>src/main/webapp/WEB-INF/web.xml</webXml>
          <packagingExcludes>pom.xml</packagingExcludes>
          <warName>icb-liberty-war</warName>
          <fileNameMapping>no-version</fileNameMapping>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>