cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Access Jdbc Material while developing a Custom Adapter for SAP CPI

aln1
Discoverer
0 Kudos
259

I am currently developing a Custom adapter for the SAP CPI. Now I want to access an SQL-server over a Cloud Connector. I only found a guid how to access Tcp-Connections in general (Accessing On-Premise Application using Cloud Connector | SAP Help Portal). But using this would lose the capsulation provided by the Jdbc Material store. So, is there a way to access the Information stored in the Jdbc Material while developing a custom adapter? 

Accepted Solutions (0)

Answers (1)

Answers (1)

pwedemann
Discoverer
0 Kudos

It is incredibly easy if you know SAP CI uses OSGi:

javax.sql.DataSource ds = new InitialContext().lookup(
"osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=YOUR-NAME)",
) as javax.sql.DataSource
aln1
Discoverer
0 Kudos

Thanks for the clue. But i still don't get how to address my Jdbc store in particular. My Jdbc material is called db1 the connection works i tested it with the standard jdbc adapter. So, I tried to get my connection with: 

Spoiler
private javax.sql.DataSource ds = ((javax.sql.DataSource) new InitialContext().lookup("osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=db1)"));

but nothing sems to exist under that name.

Spoiler
Reason: javax.naming.NameNotFoundException:[{"message":"CAUSE","parameters":["javax.naming.NameNotFoundException: osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=db1)"]}]}]}

next, i tried to get a list of all jndi services in the context with:

Spoiler
StringBuilder rout = new StringBuilder();
InitialContext ctx = new InitialContext();
NamingEnumeration<NameClassPair> list = ctx.list("");
while (list.hasMore()) {
rout.append(list.next().getName()+"\n");
}
exchange.getMessage().setBody(rout.toString());

but only got:

Spoiler
clientfactory-1
serverfactory-1
statemanager-1

So, I'm not quite sure were to go from here.