cancel
Showing results for 
Search instead for 
Did you mean: 

JCo version 3.0 - how to set connection properties?

Former Member
0 Kudos

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.

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member

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.

Former Member
0 Kudos

Hi Carsten.

Do you mind sending me a JCo 3.0 app example?? I have a few doubts and I need to see an example to find out the work way with this library (I was use to use the 2.x). Specially I need the "portalapp.xml" to see how to declare the library and a "main.java" to see how to setup the destination without the properties file that the SAP howto sais you have to avoid.

In two words: I need to learn it.

Thanks in advance.

(cferreira at integra-soluciones dot net)

Former Member
0 Kudos

hi all,

I'm also facinig the same problem. Currently i'm migrating my java code, which uses JCO 2.1.8 to connect to SAP server to JCo 3.0.0 which supports JDK 1.5.

I have couple of queries to JCo experts w.r.t JCo connection.

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.

2) How to implement connection pooling?

I am hoping that someone will throw some light on what changes I would need to make to get this to work.

It will be of great help, if you could send some example code.

Thanks in advance,

Raj

Former Member
0 Kudos

Hi Carlos,

sorry for taking so long to answer your question.

I did not use JCo3 within an portal application, so i can't give you an example for portalapp.xml.

See my previous message for example code on how to how to setup destinations without properties files.

If you don't need more than one destination in your application you may use a simpler example:


public class MySimpleDestinationDataProvider
    implements DestinationDataProvider
{
    private final Properties properties;
 
    public MySimpleDestinationDataProvider()
    {
        properties = new Properties();
        // set properties; check DestinationDataProvider javadoc for the list of properties
        properties.setProperty(DestinationDataProvider.JCO_CLIENT, "800");
        ...
    }

    public Properties getDestinationProperties( String destinationName )
    {
        return properties;
    }
 
    public void setDestinationDataEventListener( DestinationDataEventListener eventListener )
    {
        // nothing to do
    }
 
    public boolean supportsEvents()
    {
        return false;
    }
}

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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