I figured it out - turns out I was missing one small bit from my blueprint.xml; my <service> tag was missing an 'id'. I had:
<service ref="persistenceImpl" interface="alex.mjpa.api.persistence.ThingPersistenceService" > </service> but needed: <service ref="persistenceImpl" id="ThingPersistenceService" interface="alex.mjpa.api.persistence.ThingPersistenceService" > </service> This looks to be either a bug in Aries or a bug in the blog sample; I am not sure which. regards, alex From: Valentin Mahrwald <[email protected]> To: [email protected] Date: 01/10/2010 19:10 Subject: Re: Looking up a Blueprint service via JNDI / InitialContext Hi Alex, what you do all sounds entirely reasonable. The one thing I wonder is from where your lookup originates. For the osgi:service to work, I believe the caller has to be a bundle in the same OSGi framework as the service. If you are doing the lookup out of say a JEE application it is not going to work. If you are using a bundle then I would try to see whether a lookup via the BundleContext works when JNDI doesn't (-> that would be a bug :). Otherwise, there might also be a class space incompatibility between the bundle that does the lookup and the one that has the service. Valentin On 1 Oct 2010, at 12:05, Alex Hutter wrote: Hello, I am using Blueprint / Managed OpenJPA in a scenario based on the blog sample. I need a way to fetch a Blueprint service from a point in the code that starts with no reference to anything Blueprint related. As I understand it, this should be possible using something that looks a bit like this: InitialContext ic = new InitialContext(); Object s = ic.lookup("osgi:service/" + ThingPersistenceService.class.getName()); Where ThingPersistenceService is the interface my service is implementing. However when I try this code, I get this unhelpful exception: javax.naming.NameNotFoundException: osgi:service/alex.mjpa.api.persistence.ThingPersistenceService at org.apache.aries.jndi.url.ServiceRegistryContext.lookup(ServiceRegistryContext.java:110) at org.apache.aries.jndi.url.ServiceRegistryContext.lookup(ServiceRegistryContext.java:141) at org.apache.aries.jndi.DelegateContext.lookup(DelegateContext.java:148) at javax.naming.InitialContext.lookup(InitialContext.java:455) at alex.mjpa.ThingCommandProvider.getThingPS(ThingCommandProvider.java:22) ... I know the service is registered in the OSGi environment because typing "services" at the OSGi console includes this line: {alex.mjpa.api.persistence.ThingPersistenceService}={osgi.service.blueprint.compname=persistenceImpl, service.id=51} Registered by bundle: alex.mjpa.persistence.jpa_1.0.0.qualifier [35] No bundles using service. The service is registered in Blueprint using the following blueprint.xml: <?xml version="1.0" encoding="UTF-8"?> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://aries.apache.org/xmlns/transactions/v1.0.0" xmlns:jpa="http://aries.apache.org/xmlns/jpa/v1.0.0" default-activation="lazy" > <bean id="persistenceImpl" class="alex.mjpa.persistence.jpa.ThingPersistenceServiceImpl" > <tx:transaction method="*" value="Required" /> <jpa:context property="entityManager" unitname="thingExample" /> </bean> <service ref="persistenceImpl" interface="alex.mjpa.api.persistence.ThingPersistenceService" > </service> </blueprint> I feel that I am missing something obvious here, but after an hour of experimentation I am still not making any progress. Can anyone here help me solve this? If I have not provided enough information, please let me know. thanks in advance, alex Unless stated otherwise above: IBM United Kingdom Limited - Registered in England and Wales with number 741598. Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU Unless stated otherwise above: IBM United Kingdom Limited - Registered in England and Wales with number 741598. Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU
