【问题标题】:JCO_ERROR_RESOURCE: Destination ABAP_AS_WITHOUT_POOL does not exist... error while connecting via JCoJCO_ERROR_RESOURCE:目标 ABAP_AS_WITHOUT_POOL 不存在...通过 JCo 连接时出错
【发布时间】:2019-05-20 12:40:59
【问题描述】:

我正在开发一个 Java 应用程序,该应用程序需要从位于 SAP 表中的 SAP 系统获取数据。我尝试使用 SAP Java 连接器 3.X 将 SW 与 SAP 连接,但我遇到了目的地问题。

我使用了 SAP Java 连接器附带的代码示例。

public class CustomDestinationDataProvider {

static class MyDestinationDataProvider implements DestinationDataProvider {
    private DestinationDataEventListener eL;
    private HashMap<String, Properties> secureDBStorage = new HashMap<String, Properties>();

    public Properties getDestinationProperties(String ABAP_AS) {
        try {
            //read the destination from DB
            Properties p = secureDBStorage.get(ABAP_AS);

            if(p!=null) {
                //check if all is correct, for example
                if(p.isEmpty())
                    throw new DataProviderException(DataProviderException.Reason.INVALID_CONFIGURATION, "destination configuration is incorrect", null);

                return p; 
                }

            return null; 
            } catch(RuntimeException re) {
            throw new DataProviderException(DataProviderException.Reason.INTERNAL_ERROR, re);
        }
    }

    //An implementation supporting events has to retain the eventListener instance provided
    //by the JCo runtime. This listener instance shall be used to notify the JCo runtime
    //about all changes in destination configurations.
    public void setDestinationDataEventListener(DestinationDataEventListener eventListener) {
        this.eL = eventListener;
    }

    public boolean supportsEvents() {
        return true;
    }

    //implementation that saves the properties in a very secure way
    void changeProperties(String ABAP_AS, Properties properties) {
        synchronized(secureDBStorage) {
            if(properties==null) {
                if(secureDBStorage.remove(ABAP_AS)!=null)
                    eL.deleted(ABAP_AS);
            } else {
                secureDBStorage.put(ABAP_AS, properties);
                eL.updated(ABAP_AS); // create or updated
            }
        }
    }
} // end of MyDestinationDataProvider

//business logic
void executeCalls(String ABAP_AS) {
    JCoDestination dest;
    try {
        dest = JCoDestinationManager.getDestination(ABAP_AS);
        dest.ping();
        System.out.println("Destination " + ABAP_AS + " works");
    } catch(JCoException e) {
        e.printStackTrace();
        System.out.println("Execution on destination " + ABAP_AS + " failed");
    }
}

static Properties getDestinationPropertiesFromUI() {
    //adapt parameters in order to configure a valid destination
    Properties connectProperties = new Properties();
    connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, "XXX");
    connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR,  "XX");
    connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, "XXX");
    connectProperties.setProperty(DestinationDataProvider.JCO_USER,   "XXX");
    connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, "XXX");
    connectProperties.setProperty(DestinationDataProvider.JCO_LANG,   "XX");
    createDestinationDataFile(ABAP_AS, connectProperties);
    return connectProperties;
}

static void createDestinationDataFile(String ABAP_AS, Properties connectProperties) {
    File destCfg = new File(ABAP_AS + ".jcoDestination");
    try {
        FileOutputStream fos = new FileOutputStream(destCfg, false);
        connectProperties.store(fos, "for tests only!");
        fos.close();
    } catch (Exception e) {
        throw new RuntimeException("Unable to create the destination files", e);
    }
} 

}

这是我从 NetBeans 得到的错误消息:

目标 ABAP_AS_WITHOUT_POOL 有效 在目标 ABAP_AS_WITHOUT_POOL 上执行失败 com.sap.conn.jco.JCoException: (106) JCO_ERROR_RESOURCE: 目标 ABAP_AS_WITHOUT_POOL 不存在 在 com.sap.conn.jco.rt.DefaultDestinationManager.update(DefaultDestinationManager.java:217) 在 com.sap.conn.jco.rt.DefaultDestinationManager.searchDestination(DefaultDestinationManager.java:382) 在 com.sap.conn.jco.rt.DefaultDestinationManager.getDestinationInstance(DefaultDestinationManager.java:100) 在 com.sap.conn.jco.JCoDestinationManager.getDestination(JCoDestinationManager.java:104) 在 jcotest2.CustomDestinationDataProvider.executeCalls(CustomDestinationDataProvider.java:92) 在 jcotest2.Main.main(Main.java:39)

构建成功(总时间:2 秒)

【问题讨论】:

    标签: java sap saprfc sapjco3


    【解决方案1】:

    看起来您的代码将登录数据保存在 HashMap“secureDBStorage”中。你在哪里填写这个 HashMap?

    另外:如果您使用的是 HashMap 而不是文件,您需要方法“createDestinationDataFile()”来做什么?

    编辑:由于这篇文章已被审查删除,我现在正努力使其更准确。所以你的代码有两个问题:

    1. 您将后端系统的登录参数保存在名为“secureDBStorage”的 HashMap 中,但您没有使用名为“ABAP_AS_WITHOUT_POOL”的系统/目标的参数填充此映射。

    2. 您的代码仍然包含方法“createDestinationDataFile()”,它可能是从示例程序中复制的,然后忘记删除。由于您的程序使用 HashMap 来存储登录参数而不是文件系统,因此您可以删除此方法。 (只会混淆程序。)

    【讨论】:

    • 这并没有提供问题的答案。请改写评论。
    • 这篇文章确实提供了问题的答案(或者更确切地说是 Deep13 问题的解决方案)。也许我不应该将其表述为“反问句”,而是表述为……
    【解决方案2】:

    在调用目标之前,您应该在 SAP Java 应用程序服务器的配置管理器(NWA 管理器)中创建它,然后只调用它。

    https://help.sap.com/doc/saphelp_nwpi711/7.1.1/enUS/07/0d27932264284b883dab13ce1008a6/frameset.htm

    示例如下:

    static String ABAP_AS = "WD_MODELDATA_DEST";
    
    PrintWriter out = response.getWriter();
         JCoDestination destination;
        try {
            destination = JCoDestinationManager.getDestination(ABAP_AS);
            out.println("Attributes:");
            out.println(destination.getAttributes());
            out.println();
        } catch (JCoException e) {
            e.printStackTrace();
            out.println(e.getMessage());
        }
    

    我看不到您在代码中填写 ABAP_AS 变量的位置,就像在示例中一样。

    【讨论】:

    • 这不适用,因为 Deep13 显然在普通的旧 Java 应用程序中使用“独立”JCo(从 Main.main() 开始......)而不是 NetWeaver Java 堆栈中的 servlet。跨度>
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-10
    • 2017-02-27
    • 1970-01-01
    • 1970-01-01
    • 2019-10-07
    相关资源
    最近更新 更多