Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Gemini » [Gemini-naming] Referecing an Osgi service with filter fails
[Gemini-naming] Referecing an Osgi service with filter fails [message #1009161] Thu, 14 February 2013 15:14 Go to next message
Charlie Mordant is currently offline Charlie MordantFriend
Messages: 88
Registered: July 2010
Member

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

Re: [Gemini-naming] Referecing an Osgi service with filter fails [message #1019026 is a reply to message #1009161] Thu, 14 March 2013 22:47 Go to previous messageGo to next message
Michael Keith is currently offline Michael KeithFriend
Messages: 243
Registered: July 2009
Senior Member
Charlie, did you ever solve your problem?
Re: [Gemini-naming] Referecing an Osgi service with filter fails [message #1019250 is a reply to message #1009161] Fri, 15 March 2013 10:15 Go to previous messageGo to next message
Charlie Mordant is currently offline Charlie MordantFriend
Messages: 88
Registered: July 2010
Member

Hi,

Unfortunately I didn't, I succeed to get the JNDI reference, but I was stuck with Gemini JPA integration (Gemini-JPA requires a connection-url String in it's PU properties, that prevent the use of JTA-DataSource statement) (I wanted to enable jta transaction management with Atomikos).

If you want to know more about the subject, see http://www.eclipse.org/forums/index.php/t/447657/ and the related issue (and let's talk on this thread).

Regards,

[Updated on: Fri, 15 March 2013 11:50]

Report message to a moderator

Re: [Gemini-naming] Referecing an Osgi service with filter fails [message #1019464 is a reply to message #1019250] Fri, 15 March 2013 18:41 Go to previous message
Michael Keith is currently offline Michael KeithFriend
Messages: 243
Registered: July 2009
Senior Member
Ok, so it sounds like your problem is not really JNDI anymore but JTA integration, as described in your other post. In other words, this particular problem is solved.
Previous Topic:Moving from persistence.xml to ConfigurationAdmin
Next Topic:Problem with Gemini JPA & Spring Data JPA
Goto Forum:
  


Current Time: Tue Apr 23 09:51:08 GMT 2024

Powered by FUDForum. Page generated in 0.03566 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top