[Gemini-naming] Referecing an Osgi service with filter fails [message #1009161] |
Thu, 14 February 2013 15:14 |
|
Hi,
I'm trying to reference anosgi service declared this way:
reference id="jNDIContextManager" interface="org.osgi.service.jndi.JNDIContextManager" availability="mandatory"></reference>
<bean id="userDbDataSource" class="com.atomikos.jdbc.AtomikosDataSourceBean"
init-method="init" destroy-method="close">
<property name="uniqueResourceName" value="userDb" />
<property name="xaDataSourceClassName" value="org.apache.derby.jdbc.EmbeddedXADataSource" />
<property name="xaProperties">
<props>
<prop key="databaseName">/tmp/userDb</prop>
<prop key="createDatabase">create</prop>
</props>
</property>
<property name="minPoolSize" value="1" />
<property name="maxPoolSize" value="5" />
<property name="borrowConnectionTimeout" value="10000" />
</bean>
<service ref="userDbDataSource" interface="javax.sql.DataSource">
<service-properties>
<entry key="osgi.jndi.service.name" value="userDb" />
</service-properties>
</service>
The code I use is in a service tracker (to make eclipselink jndi aware ^^):
String persistanceUnit = (String) arg0.getProperty(EntityManagerFactoryBuilder.JPA_UNIT_NAME);
EntityManagerFactoryBuilder emfBuilder = (EntityManagerFactoryBuilder) context.getService(arg0);
//Get the JNDIContextManager service: It would be better if it worked ^^
ServiceReference ref = context.getServiceReference(JNDIContextManager.class.getName());
//Get the DataSource object by the 'osgi' schema, using JNDI to scan the Service Registry
JNDIContextManager JNDIContextManager = (JNDIContextManager) context.getService(ref);
try {
Context JNDIContext = JNDIContextManager.newInitialContext();
DataSource datasource=null;
datasource=
(DataSource) JNDIContext.lookup("osgi:service/"+DataSource.class.getName()+"/(osgi.jndi.service.name="+persistanceUnit.replace("Pu", "Db")+")");
if(datasource == null)
throw new Exception("DataSource has not been found");
Unformtunately, this code fails with " javax.naming.NameNotFoundException: The OSGi service referred to by the URL = osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=userDb) could not be located in the OSGi Service Registry ".
Have you got any idea of why this is happening? I'm struggling on this for two days now and I've lost half of my hairs...
Thanks in advance,
Charlie
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02438 seconds