ecology调用SAPRFC接口的第一种写法(不生成配置文件)

RFC第一种写法:不生成配置文件,直接连接

java 复制代码
package com.kaka.workflow.utils;

import com.sap.conn.jco.JCoDestination;
import com.sap.conn.jco.JCoDestinationManager;
import com.sap.conn.jco.ext.DestinationDataEventListener;
import com.sap.conn.jco.ext.DestinationDataProvider;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.util.Properties;
  class ConnSAPProperties implements DestinationDataProvider {
    public Properties getDestinationProperties(String destinationName) {
        Properties properties = new Properties();
        properties.setProperty(DestinationDataProvider.JCO_ASHOST, "IP地址");
        properties.setProperty(DestinationDataProvider.JCO_SYSNR, "编号");
        properties.setProperty(DestinationDataProvider.JCO_CLIENT, "客户端");
        properties.setProperty(DestinationDataProvider.JCO_USER, "账户名");
        properties.setProperty(DestinationDataProvider.JCO_PASSWD, "密码");
        properties.setProperty(DestinationDataProvider.JCO_LANG, "ZH");
        return properties;
    }
    public void setDestinationDataEventListener(DestinationDataEventListener eventListener) {}
    public boolean supportsEvents() { return false; }
}

/***
* @MethodName: ConnSAP
* @Description: 连接SAP
* @Param:
* @return:
* @Author: kaka
* @Date: 2023/9/18 17:33
*/
public class ConnSAP {
    private static Log log = LogFactory.getLog(ConnSAP.class);

    public static JCoDestination Connect() {
        ConnSAPProperties provider = new ConnSAPProperties();
        com.sap.conn.jco.ext.Environment.registerDestinationDataProvider(provider); //实例化
        JCoDestination destination = null;
        try {
            destination = JCoDestinationManager.getDestination("ABAP_AS_POOLED");
        } catch (Exception e) {
            e.printStackTrace();
        }
        log.info("provider>>"+provider);
        return destination;
    }

    public static void main(String[] args) {
        JCoDestination connect = ConnSAP.Connect();
        System.out.println("connect>>>>>"+connect);
    }

}

运行结果:成功了>>>

相关推荐
XiaoLeisj5 小时前
【JavaEE初阶 — 多线程】单例模式 & 指令重排序问题
java·开发语言·java-ee
尢词9 小时前
SpringMVC
java·spring·java-ee·tomcat·maven
阑梦清川12 小时前
JavaEE进阶---第一个SprintBoot项目创建过程&&&我的感受
java·java-ee·springboot
移民找老国13 小时前
加拿大移民新风向
java-ee·maven·phpstorm·visual studio code·nio
琪露诺大湿15 小时前
JavaEE-多线程初阶(4)
java·开发语言·jvm·java-ee·基础·1024程序员节·原神
细心的莽夫18 小时前
JavaWeb学习笔记
java·开发语言·笔记·学习·java-ee·web
yang_shengy2 天前
【JavaEE】认识进程
java·开发语言·java-ee·进程
听潮阁2 天前
【SpringCloud详细教程】-01-一文了解微服务
开发语言·spring boot·spring cloud·servlet·java-ee·mybatis