zhangherong
2025-06-16 c10a845e0cf71bc1861feba99052d7822dffbd7d
art: SAP集成测试代码修改
已修改2个文件
34 ■■■■ 文件已修改
src/main/java/org/jeecg/config/sap/SapRfcConnectionManager.java 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/org/jeecg/modules/sap/service/impl/SAPServiceImpl.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/org/jeecg/config/sap/SapRfcConnectionManager.java
@@ -3,13 +3,17 @@
import com.sap.conn.jco.*;
import com.sap.conn.jco.ext.DestinationDataProvider;
import com.sap.conn.jco.ext.Environment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.io.File;
import java.io.FileOutputStream;
import java.util.Properties;
@Component
@Slf4j
public class SapRfcConnectionManager {
    @Value("${sap.rfc.destination}")
@@ -46,7 +50,7 @@
     * @throws JCoException
     */
    @PostConstruct
    public void init() throws JCoException {
    public void init() throws Exception {
        Properties connectProperties = new Properties();
        connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, ashost);
        connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR, sysnr);
@@ -63,7 +67,27 @@
        provider.addDestination(destinationName, connectProperties);
        // 设置全局目的地提供者
        Environment.registerDestinationDataProvider(provider);
//        Environment.registerDestinationDataProvider(provider);
        log.info("properties = " + connectProperties);
        //生成配置文件,JCoDestinationManager.getDestination()调用时会需要该连接配置文件,后缀名需要为jcoDestination
        FileOutputStream fos = null;
        String suffix = "jcoDestination";
        File cfg = new File(destinationName + "." + suffix);
        if (!cfg.exists()) {
            try {
                fos = new FileOutputStream(cfg, false);
                connectProperties.store(fos, "for tests only !");
                fos.close();
            } catch (Exception var9) {
                throw new Exception("Unable to create the destination file " + cfg.getName(), var9);
            } finally {
                if (null != fos) {
                    fos.close();
                }
            }
        }
        // 获取目的地
        this.destination = JCoDestinationManager.getDestination(destinationName);
src/main/java/org/jeecg/modules/sap/service/impl/SAPServiceImpl.java
@@ -3,6 +3,7 @@
import com.sap.conn.jco.JCoDestination;
import com.sap.conn.jco.JCoFunction;
import com.sap.conn.jco.JCoParameterList;
import com.sap.conn.jco.JCoRepository;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.config.sap.SapRfcConnectionManager;
@@ -19,10 +20,11 @@
    @Override
    public String test() {
        JCoDestination destination = connectionManager.getDestination();
        JCoFunction function = destination.getRepository().getFunction("ZPPF_022");
        JCoRepository repository = destination.getRepository();
        JCoFunction function = repository.getFunction("ZPPF_022");
        if (function == null) {
            throw new RuntimeException("RFC 函数模块 Z_GET_MATERIAL_INFO 未找到!");
            throw new RuntimeException("RFC 函数模块 ZPPF_022 未找到!");
        }
        // 设置输入参数