我还有另一个与JCO相关的问题,希望能找到帮助。

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

“对于此示例,目标配置存储在程序调用的文件中。实际上,出于安全原因,您应该避免使用此内容。”

但是毕竟无法找到工作解决方案。关于这个主题有一个棕色的线程

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

但是他们都没有帮助。我真的无法找到解决方案,也没有找到解决方案。实际上,我通过在建立连接后删除文件解决了安全问题,但这不是一个令人满意的解决方案。必须有一个更好的方法来获得连接的参数,尤其是当它在手册中,但我没有胶水。

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

有帮助吗?

解决方案

是的,这是可能的。您必须创建自己的目标dataprovider的实现,并使用uniginger.registerdestinationdataprovider()进行注册。但是,您的DDP获得了连接数据,并且凭据取决于您。看一眼 net.sf.rcer.conn.connections.connectionmanager, ,那里有一个有效的例子。

你需要

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

其他提示

这有点令人困惑,这对我来说也很重要。

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

我通过一个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());

        }


    }
}

问候

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top