views:

77

answers:

2

Hello, I got another JCo-related question and hopefully finding help.

With JCo you can easily build up a connection like it is explained in the example sheets which came with the JCo-library. Unfortunately, the only way building a connection is handled with a created property file. It wouldn´t be that bad, if there wasn´t any sensible data in it. But at least, the password for the SAP user stands in the file, so it is a lack of safety in this way of connection-handling. The manual of JCo says so, too :

"For this example the destination configuration is stored in a file that is called by the program. In practice you should avoid this for security reasons."

but couldn´t find a working solution after all. There are a palmful threads about this theme, like this

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

but none of them are helpful. I really can´t figure out a solution and neither find one. Actually I solved the security-problem with deleting the file after building the connection, but this is not a satisfying solution. There have to be a better way getting the parameter for the connection, especially when it stands in the manual, but I have no glue how.

Anybody already worked with JCo 3.0 and knows this problem?

+1  A: 

Yes, that's possible. You have to create your own implementation of DestinationDataProvider and register it using Environment.registerDestinationDataProvider(). However your DDP obtains the connection data and credentials is up to you. Take a look at net.sf.rcer.conn.connections.ConnectionManager, there's a working example in there.

You need to

  • copy the private class starting on line 66 and adapt it to your own needs (that is, fetch the connection data from wherever you want to)
  • perform the registration (line 204) somewhere during the startup of your application
  • get the connection using some string identifier that will be passed to your DestinationDataProvider.
vwegert
Sorry, but I don´t really get it. There are so many dependencies in the package, that I have to ask, which classes are essentially for the wanted function of a single, simple connection? I already browsed through the classes, but I also don´t get the purpose of the Credentials. I imagined it easier. Your implementation is for sure really great, but I wanted to build my own class and by now, I really don´t know how :/
I've extended my answer a bit - does that help?
vwegert
Yeah, thanks, it helps, but how to replace the Connection and Credential-class? Are they fully necessary or can I implement their basic function by myself? I couldn´t understand the full functionality of this two until yet :/
You don't need these, they belong to my framework.
vwegert
Thanks for your patience until yet ;)Ok, I already worked this out yesterday, so I implemented my own DestinationDataProvider with the wanted data aquisition. But now I got caught at your third point how to pass the string identifier. When I define a String, set my Destinationproperties and want to call the Destination with the String, how are the properties linked with the String. Thats the most proplematic part for me, because I always only saw examples, where this String only direct to a destinationfile with the same name.
Try passing "FooBar" and see what reaches your DDP...
vwegert
+1  A: 

It's a bit confusing, it was dificult to me how to figure this too.

All you need is an object of type java.util.Properties to fill the desired fields, but it's up to ou how to fill this object.

I dit it through a ValueObject, I can fill this VO from a file, database, web form...

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

    }

The JCOProvider class:

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

        }


    }
}

Regards

franblay