java JCO连接SAP时报错

Caused by: RfcException: [null]
message: Connect from SAP gateway to RFC server failed
Connection parameters: TYPE=A DEST=ABAP_AS_WITHOUT_POOL ASHOST=******** SYSNR=00 PCS=1

LOCATION SAP-Gateway on host ERPDEVAP1 / sapgw00
ERROR timeout during allocate
TIME Sat Dec 2 10:52:57 2017
RELEASE 742
COMPONENT SAP-Gateway
VERSION 2
RC 242
MODULE /bas/742_REL/src/krn/si/gw/gwr3cpic.c
LINE 2181
DETAIL no connect of TP sapdp00 from host mail.edifier.com after 20
sec
COUNTER 3

Return code: RFC_FAILURE(1)
error group: 102
key: RFC_ERROR_COMMUNICATION

废话不多说了,直接上代码吧。

 import java.util.HashMap;
import java.util.Properties;

import com.sap.conn.jco.ext.DataProviderException;
import com.sap.conn.jco.ext.DestinationDataEventListener;
import com.sap.conn.jco.ext.DestinationDataProvider;

public class JCOProvider implements DestinationDataProvider {

    private HashMap<String, Properties> secureDBStorage = new HashMap<String, Properties>();
    private DestinationDataEventListener eL;

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

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

    @Override
    public void setDestinationDataEventListener(
            DestinationDataEventListener eventListener) {
        this.eL = eventListener;

    }

    @Override
    public boolean supportsEvents() {
        return true;
    }

    //implementation that saves the properties in a very secure way
    public void changePropertiesForABAP_AS(String destName, Properties properties) {
        synchronized(secureDBStorage)
        {
            if(properties==null)
            {
                if(secureDBStorage.remove(destName)!=null)
                    eL.deleted(destName);
            }
            else 
            {
                secureDBStorage.put(destName, properties);
                eL.updated(destName); // create or updated
            }
        }
    }
}
我有一个微信公众号,经常会分享一些Java技术相关的干货。如果你喜欢我的分享,可以用微信搜索“Java团长”或者“javatuanzhang”关注。

问题已解决!是SAP那边SO配置文件问题,需要对reginfo(路径为/usr/sap/DEV/DVEBMGS00/data/reginfo)配置文件进行修改
P TP=* HOST=local CANCEL=local ACCESS=local
P TP=* HOST=internal CANCEL=internal ACCESS=internal

P TP=CLOUDESB(programID) HOST=* CANCEL=* ACCESS=*