首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >sapjco3驱动程序的问题

sapjco3驱动程序的问题
EN

Stack Overflow用户
提问于 2017-05-26 13:25:54
回答 1查看 1.2K关注 0票数 2

我编写了一个Spring (SpringFramework4.1.1)java1.8应用程序,该应用程序使用皂荚3.jar驱动程序成功地连接到SAP,并使用CustomDestinationDataProvider技术完成了这一工作。然后我使用这个驱动器在我的SAP R/3系统中调用RFCs。java代码是通过AngularJS前端应用程序的api调用来执行的。

在对SAP的调用发生的大约5%的时间里,我发现发生了以下错误:

代码语言:javascript
复制
NestedServletException: Handler processing failed; nested exception is 
java.lang.Error: java.lang.IllegalStateException: DestinationDataProvider 
already registered 

下面是我的CustomDestinationDataProvider.java文件的内容:

代码语言:javascript
复制
public class CustomDestinationDataProvider {

public class MyDestinationDataProvider implements DestinationDataProvider {
    private DestinationDataEventListener eL;
    private HashMap<String, Properties> secureDBStorage = new HashMap<String, Properties>();
    public Properties getDestinationProperties(String destinationName) {
        try {
            Properties p = secureDBStorage.get(destinationName);
            if(p!=null) {
                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);
        }
    }
    public void setDestinationDataEventListener(DestinationDataEventListener eventListener) {
        this.eL = eventListener;
    }
    public boolean supportsEvents() {
        return true;
    }
    public void changeProperties(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
            }
        }
    }
}

public ArrayList<MaterialBean> executeAvailabilityCall(Properties connectProperties, String searchString) {
    String destName = "ABAP_AS";
    SAPDAO sapDAO = new SAPDAO(); 
    ArrayList<MaterialBean> searchResults = new ArrayList<MaterialBean>();
    MyDestinationDataProvider myProvider = new MyDestinationDataProvider();
    JCoDestination dest;
    try {
        com.sap.conn.jco.ext.Environment.registerDestinationDataProvider(myProvider);
    } catch(IllegalStateException providerAlreadyRegisteredException) {
    }
    myProvider.changeProperties(destName, connectProperties);
    try {
        dest = JCoDestinationManager.getDestination(destName);
        searchResults = sapDAO.searchAvailability(dest, searchString);
    } catch(JCoException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
    myProvider.changeProperties(destName, null);
    try {
        com.sap.conn.jco.ext.Environment.unregisterDestinationDataProvider(myProvider);
    } catch(IllegalStateException providerAlreadyRegisteredException) {
        throw new Error(providerAlreadyRegisteredException);
    }
    return searchResults;
}   // end method executeAvailabilityCall()
}   // end class CustomDestinationProvider()

我的猜测是,多个api调用同时发生,一旦第一个查询注册了目标数据提供程序,随后的查询(这些查询也试图注册目标数据提供程序)失败,因为它们在executeAvailabilityCall方法中对‘executeAvailabilityCall’使用相同的值。

首先,在我看来,我应该为destName变量使用一个动态值,而不是只对所有查询使用"ABAP_AS“。换句话说,我应该修改以下一行:

代码语言:javascript
复制
    String destName = "ABAP_AS";

像这样的事情:

代码语言:javascript
复制
    String destName = "ABAP_AS_" + LocalDateTime.now();

这将保证destName变量的唯一值,从而保证唯一的目标提供程序名称。

对尝试这个是否明智有什么想法吗?如果这不是一个好主意,还有什么其他的解决方案值得探索呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-26 17:02:26

是的,您应该为各种登录属性配置集使用多个唯一的目标名称。您的类MyDestinationDataProvider已经以这种方式实现了。但是为什么要在目标名中加上时间戳呢?为什么不简单地使用像"TargetSystem__with_“这样的目标名称模式呢?

对于您的异常,只需注册一次MyDestinationDataProvider,而不永久注册和注销它。这不是JCo所期望的实现方式。引用JCo JavaDoc at com.sap.conn.jco.ext.DestinationDataProvider的话

只能注册DestinationDataProvider的一个实现。为了注册另一个实现,基础设施必须首先注销当前注册的实现。不建议永久交换DestinationDataProvider注册。一个已注册的实例应该全局管理整个基础结构环境的所有目标配置。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44202820

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档