CICS ECI 自由

CICS ECI Liberty

我正在尝试使用 JCA 和 CICSECI 功能通过 CICS 事务网关连接到 IBM 大型机。

我的 Servlet 代码是:

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);
    }

}

我得到的异常是:

[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)

我的server.xml如下:

<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>

我的 POM 是:

<?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>

当我google错误代码。 IBM 文档状态: 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."

我已经查看了以下教程,但它们没有显示完整的构建环境。 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

我在使用示例代码时遇到了同样的错误。

我还尝试按照 link:

中的描述设置 connectionFactory

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

当我如图所示设置 connectionFactory 时:

<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>

依赖注入中断。

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.

非常感谢

查看您的 server.xml 配置,Web 应用程序没有从资源适配器加载 InteractionSpec class 所需的 classloader 定义。

所以应该指定为

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

发布我解决问题的过程。 正如 Trilarion 和 crshnburn 所述,显然存在 class 版本冲突。

感谢您的帮助。

1 安装新的 Liberty 配置文件。

2 从 RAR 压缩包中提取 cics.jar 用于编译。

3 不要在 server.xml.

中包含 jcaRemoteEci-1.0 功能

4 使用以下 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 使用以下pom.xml。请注意,cicseci 是使用 'provided' 范围定义的,允许编译器依赖但避免打包到 war 存档中。

<?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>