0

SAP テーブルに配置されている SAP システムからデータを取得する必要がある Java アプリに取り組んでいます。SAP Java Connector 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.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) で

BUILD SUCCESSFUL (合計時間: 2 秒)

4

2 に答える 2

1

あなたのコードは、ログオン データを HashMap の "secureDBStorage" に保持しているようです。この HashMap をどこに入力しますか?

また、ファイルではなく HashMap を使用している場合、「createDestinationDataFile()」メソッドは何のために必要ですか?

編集:この投稿はレビューによって削除されたため、より正確にしようとしています. したがって、コードには 2 つの問題があります。

  1. バックエンド システムのログオン パラメータを「secureDBStorage」という名前の HashMap に保持していますが、このマップに「ABAP_AS_WITHOUT_POOL」という名前のシステム/宛先のパラメータを入力していません。

  2. コードにはまだメソッド「createDestinationDataFile()」が含まれています。これはおそらくサンプル プログラムからコピーされたもので、削除するのを忘れていました。プログラムは、ファイル システムではなくログオン パラメータの格納に HashMap を使用しているため、このメソッドを削除できます。(プログラムを混乱させるだけです。)

于 2019-09-17T13:01:03.363 に答える
0

宛先を呼び出す前に、SAP Java Application Server (NWA Manager) の Configuration Manager で宛先を作成してから呼び出す必要があります。

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サンプルのように、コードのどこに変数を入力するかわかりません。

于 2019-06-20T23:23:17.643 に答える