Java sapjco3驱动程序的问题
我已经编写了一个SpringMVC(SpringFramework4.1.1)Java1.8应用程序,它使用sapjco3.jar驱动程序成功地连接到SAP,并使用CustomDestinationDataProvider技术实现了这一点。然后,我使用此驱动器调用SAP R/3系统中的RFC。java代码通过AngularJS前端应用程序的api调用执行 我发现,在调用SAP的过程中,大约有5%的时间会发生以下错误:Java sapjco3驱动程序的问题,java,spring,sapjco3,Java,Spring,Sapjco3,我已经编写了一个SpringMVC(SpringFramework4.1.1)Java1.8应用程序,它使用sapjco3.jar驱动程序成功地连接到SAP,并使用CustomDestinationDataProvider技术实现了这一点。然后,我使用此驱动器调用SAP R/3系统中的RFC。java代码通过AngularJS前端应用程序的api调用执行 我发现,在调用SAP的过程中,大约有5%的时间会发生以下错误: NestedServletException: Handler process
NestedServletException: Handler processing failed; nested exception is
java.lang.Error: java.lang.IllegalStateException: DestinationDataProvider
already registered
以下是我的CustomDestinationDataProvider.java文件的内容:
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()
对这样的事情:
String destName = "ABAP_AS_" + LocalDateTime.now();
这将保证destName变量的值是唯一的,因此是唯一的目标提供程序名称
试一试这个有什么好处吗?如果这不是一个好主意,还有什么其他解决方案值得探索?是的,您应该为各种登录属性配置集使用多个唯一的目标名称。您的类MyDestinationDataProvider已经以这种方式实现。但是为什么要在目的地名称中添加时间戳呢?为什么不简单地使用目标名称模式,如“TargetSystem_uuuwith_uu” 关于您的异常,只需注册MyDestinationDataProvider一次,而不要永久注册和注销它。这不是JCo期望的实现方式。引自JCo JavaDoc,网址为
com.sap.conn.JCo.ext.DestinationDataProvider
:
只能注册DestinationDataProvider的一个实现。
要注册另一个实现,基础结构必须首先
注销当前已注册的实现。事实并非如此
建议永久交换目标数据提供程序
注册。一个已注册实例应全局管理所有
整个基础架构环境的目标配置
好啊关于只注册一次“MyDestinationDataProvider”,我应该通过singleton样式的类来实现这一点,还是应该仅在“registerDestinationDataProvider”行周围使用条件逻辑,该行仅在数据提供程序尚未注册时运行?我建议在一些只调用一次的初始化例程中注册
DestinationDataProvider
。在我看来,反复检查DestinationDataProvider
是否已经注册不是一种有效的编码方式。这听起来是个好主意。非常感谢您的投入!:)
String destName = "ABAP_AS_" + LocalDateTime.now();