构建没有Properties-File的JCoServer

我得到了另一个与JCo有关的问题,希望能找到帮助。

使用JCo,您可以轻松地建立连接,就像JCo-library附带的示例表中所述。 不幸的是,构建连接的唯一方法是使用创建的属性文件进行处理。 如果没有任何明智的数据,它就不会那么糟糕。 但至少,SAP用户的密码位于文件中,因此这种连接处理方式缺乏安全性。 JCo的手册也是这样说的:

“对于这个例子,目标配置存储在程序调用的文件中。实际上,出于安全原因,应该避免这种情况。”

但毕竟找不到合适的解决方案。 关于这个主题有一些掌上电脑,就像这样

http://forums.sdn.sap.com/thread.jspa?messageID=7303957

但没有一个是有帮助的。 我真的无法找到解决方案而且找不到解决方案。 实际上我在构建连接后删除了文件解决了安全问题,但这不是一个令人满意的解决方案。 必须有一个更好的方法来获取连接的参数,特别是当它在手册中,但我没有胶水如何。

有人已经与JCo 3.0合作并且知道这个问题吗?

是的,那是可能的。 您必须创建自己的DestinationDataProvider实现并使用Environment.registerDestinationDataProvider()注册它。 但是,您的DDP会获取连接数据,凭据由您自己决定。 看看net.sf.rcer.conn.connections.ConnectionManager ,那里有一个工作示例。

你需要

  • 从第66行开始复制私有类并根据您自己的需要进行调整(即,从您想要的任何地方获取连接数据)
  • 在应用程序启动期间的某处执行注册(第204行)
  • 使用一些将传递给DestinationDataProvider的字符串标识符来获取连接。

这有点让人困惑,对我来说如何解决这个问题也很困难。

您只需要一个java.util.Properties类型的对象来填充所需的字段,但这取决于如何填充此对象。

我通过ValueObject对它,我可以从文件,数据库,Web表单填写这个VO …

JCOProvider jcoProvider = null; SAPVO sap = new SAPVO(); // Value Object Properties properties = new Properties(); if(jcoProvider == null) { // Get SAP config from DB try { sap = SAPDAO.getSAPConfig(); // DAO object that gets conn data from DB } catch (Exception ex) { throw new ConexionSAPException(ex.getMessage()); } // Create new conn jcoProvider = new JCOProvider(); } properties.setProperty(DestinationDataProvider.JCO_ASHOST, sap.getJCO_ASHOST()); properties.setProperty(DestinationDataProvider.JCO_SYSNR, sap.getJCO_SYSNR()); properties.setProperty(DestinationDataProvider.JCO_CLIENT, sap.getJCO_CLIENT()); properties.setProperty(DestinationDataProvider.JCO_USER, sap.getJCO_USER()); properties.setProperty(DestinationDataProvider.JCO_PASSWD, sap.getJCO_PASSWD()); properties.setProperty(DestinationDataProvider.JCO_LANG, sap.getJCO_LANG()); // properties.setProperty(DestinationDataProvider.JCO_TRACE, "10"); try { jcoProvider.changePropertiesForABAP_AS(properties); } catch (Exception e) { throw new ConexionSAPException(e.getMessage()); } 

JCOProvider类:

 import com.sap.conn.jco.ext.DestinationDataEventListener; import com.sap.conn.jco.ext.DestinationDataProvider; import com.sap.conn.jco.ext.Environment; import es.grupotec.ejb.util.ConexionSAPException; import java.util.Properties; public class JCOProvider implements DestinationDataProvider { private String SAP_SERVER = "SAPSERVER"; private DestinationDataEventListener eventListener; private Properties ABAP_AS_properties; public JCOProvider() { } @Override public Properties getDestinationProperties(String name) { if (name.equals(SAP_SERVER) && ABAP_AS_properties != null) { return ABAP_AS_properties; } else { return null; } // if(ABAP_AS_properties!=null) return ABAP_AS_properties; // else throw new RuntimeException("Destination " + name + " is not available"); } @Override public boolean supportsEvents() { return true; } @Override public void setDestinationDataEventListener(DestinationDataEventListener eventListener) { this.eventListener = eventListener; } public void changePropertiesForABAP_AS(Properties properties) throws ConexionSAPException { try { if (!Environment.isDestinationDataProviderRegistered()) { if (ABAP_AS_properties == null) { ABAP_AS_properties = properties; } Environment.registerDestinationDataProvider(this); } if (properties == null) { if (eventListener != null) { eventListener.deleted(SAP_SERVER); } ABAP_AS_properties = null; } else { ABAP_AS_properties = properties; if (eventListener != null) { eventListener.updated(SAP_SERVER); } } } catch (Exception ex) { throw new ConexionSAPException(ex.getMessage()); } } } 

问候