Skip to Content
avatar image
Former Member

JCo version 3.0 - how to set connection properties?

I'm in the process of migrating from SAP JCo 2.1 to the recently release JCo version 3.0. I don't understand the new process of defining destinations and setting connection properties. The SAP JCo 3.0 example is called StepByStepClient, and that example uses a stored properties file, and the JCo 3.0 documentation has the following warning, but does not provide any further info on how you should actually perform this in a real situation:

"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."

static String ABAP_AS_POOLED = "ABAP_AS_WITH_POOL";

Properties connectProperties = new Properties();
connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, "value" );
connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR,  "value" );
connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, "value" );
connectProperties.setProperty(DestinationDataProvider.JCO_USER,   "value" );
connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, "value" );
connectProperties.setProperty(DestinationDataProvider.JCO_LANG,   "value" );
connectProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY, "value" );
connectProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT, "value" );

createDataFile(ABAP_AS_POOLED, "jcoDestination", connectProperties);

JCoDestination destination = JCoDestinationManager.getDestination(ABAP_AS_POOLED);
JCoFunction function = destination.getRepository().getFunction("BAPI_SALESORDER_GETSTATUS");

I don't understand the connection between getDestination and DestinationDataProvider.

I am building some web-based inquiry screens using Tomcat that use JCo to extract R/3 data and I want to define the connection properties outside of the code for easy manipulation when moving from test to prod. I don't use J2EE - JNDI lookups.

Has anyone else migrated to JCo 3.0? Can you provide an explanation of how this should be perfomed?

Thanks, points to be awarded.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • avatar image
    Former Member
    Aug 22, 2008 at 12:51 PM

    Hello,

    have a look at the apidoc for class JCoDestinationManager - it states out how to change the DestinationManger

    as far as i can see it from the docs:

    implement interface DestinationDataProvider in a class which knows how to fetch your custom destination data

    and register an instace of the class using

    com.sap.conn.jco.ext.Environment -> registerDestinationDataProvider

    regards franz

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 02, 2008 at 03:16 PM

    Hi,

    here is a DestinationDataProvider implementation which you can use to manage different destinations:

    public class MyDestinationDataProvider
        implements DestinationDataProvider
    {
        Map<String, Properties> propertiesForDestinationName = new HashMap<String, Properties>();
    
        public void addDestination( String destinationName, Properties properties )
        {
            propertiesForDestinationName.put( destinationName, properties );
        }
    
        public Properties getDestinationProperties( String destinationName )
        {
            if ( propertiesForDestinationName.containsKey( destinationName ) )
            {
                return propertiesForDestinationName.get( destinationName );
            }
            else
            {
                throw new RuntimeException( "JCo destination not found: " + destinationName );
            }
        }
    
        public void setDestinationDataEventListener( DestinationDataEventListener eventListener )
        {
            // nothing to do
        }
    
        public boolean supportsEvents()
        {
            return false;
        }
    }

    And here is how to use it:

    ...
    MyDestinationDataProvider provider = new MyDestinationDataProvider();
    provider.addDestination( "A01", jcoPropertiesA01 );
    provider.addDestination( "A02", jcoPropertiesA02 );
    com.sap.conn.jco.ext.Environment.registerDestinationDataProvider( provider );
    ...
    // The destination name must match the name you use for looking up a destination.
    JCoDestination destination = JCoDestinationManager.getDestination( "A01" );
    ...

    Hope this is useful.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi Basavaraj,

      sorry also to you for taking so long.

      > 1) The SAP JCo 3.0 example StepByStepClient.java uses a stored properties file to connect SAP. This store user credentials as well.

      > So, how to avoid properties file to store user credentials and pass the credentials dynamically? Each user uses his own username and password to connect SAP.

      Please, see my other posts in this thread.

      > 2) How to implement connection pooling?

      JCo3 does this for you, simply specify the Property "jco.destination.pool_capacity" for each destination with the max. number of connections that should fit into the pool.

      Edited by: Carsten Erker on Apr 1, 2009 10:53 PM