Topic
  • 6 replies
  • Latest Post - ‏2013-04-19T10:00:29Z by Emily Jiang
yusufe
yusufe
5 Posts

Pinned topic Unable to lookup registered service from WAB

‏2013-03-28T10:28:50Z |
We have a feature called example.mf


Subsystem-ManifestVersion: 1 Subsystem-SymbolicName: example; visibility:=

public Subsystem-Version: 1.0.0 Subsystem-Type: osgi.subsystem.feature Subsystem-Content: 
{some bundle names here
} IBM-Feature-Version: 2 IBM-API-Service: com.example.MyClass IBM-API-Package: 
{some packages here
} Subsystem-Name: %name Subsystem-Description: %description


And one of the bundles of this feature (as part of Subsystem-Content) registers a service in it's bundle activator: (yes in this case we didn't use bluprint)




public 

void start(BundleContext context) 

throws Exception 
{ context.registerService(MyClass.class.getName(), 

new MyClass(), 

null); 
}


And once we run the server, bundle gets activated as part of the feature as expected and registers the service. We can see it inside osgi console:


osgi> services com.example.MyClass 
{com.example.MyClass
}=
{service.id=230
} 
"Registered by bundle:" com.example.bundle [68] 
"Bundles using service" com.ibm.ws.jndi_1.0.1.20130309-1525 [139] osgi> jndilookup osgi:service/com.example.MyClass [].lookup(
"osgi:service/com.example.MyClass") com.example.MyClass@59c7d66d


And eventually we try to get a reference to this service inside an EBA app (user/defaultServer/someApp.eba) with a WAB (someApp.eba/webappbundle.jar). This code is part of a servlet inside the WAB:


InitialContext ic = 

new InitialContext(); Object o = ic.lookup(
"osgi:service/com.example.MyClass");


But we get this exception:


[err] javax.naming.NameNotFoundException: osgi:service/com.example.MyClass [err]   at org.apache.aries.jndi.url.ServiceRegistryContext.lookup(ServiceRegistryContext.java:113) [err]   at org.apache.aries.jndi.url.ServiceRegistryContext.lookup(ServiceRegistryContext.java:144) [err]   at org.apache.aries.jndi.DelegateContext.lookup(DelegateContext.java:161) [err]   at javax.naming.InitialContext.lookup(InitialContext.java:436) [err]   at com.tivoli.am.fim.war.runtime.SSOPSServlet.doGet(SSOPSServlet.java:136) [err]   at javax.servlet.http.HttpServlet.service(HttpServlet.java:575) [err]   at [internal classes]


Followed this article: https://www.ibm.com/developerworks/mydeveloperworks/blogs/wasdev/entry/getting_started_with_osgi_applications_osgi_services_and_servlets5?lang=en

But only difference with this article:
  • Instead of registering service from a bundle as part EBA app, we register the service from a bundle as part of a feature.

I am suspecting services have different context in this case but then again liberty documentation mentions: IBM-API-Service to expose services to applications and that's already there for us.

It seems IBM-API-Service is not working...?

What the problem can be?
  • Emily Jiang
    Emily Jiang
    10 Posts

    Re: Unable to lookup registered service from WAB

    ‏2013-03-28T11:14:05Z  
    Which version of liberty are you using? It will help if you can post your server.xml here as well? Did you export com.example in your example.mf (please list the details under IBM-API-Package:)?
    Regards,
    Emily
  • yusufe
    yusufe
    5 Posts

    Re: Unable to lookup registered service from WAB

    ‏2013-04-01T04:49:26Z  
    Which version of liberty are you using? It will help if you can post your server.xml here as well? Did you export com.example in your example.mf (please list the details under IBM-API-Package:)?
    Regards,
    Emily
    • Liberty version: 8.5.next.beta-20130309-1525
    • Yes, com.example is exported
    • IBM package also contains com.example

    
    <server description=
    "new server">   <!-- Enable features --> <featureManager> <feature>jsp-2.2</feature> <feature>localConnector-1.0</feature> <feature>osgiconsole-1.0</feature> <feature>osgi-3.8.2</feature> <feature>wab-1.0</feature> <feature>servlet-3.0</feature> <feature>blueprint-1.0</feature> <feature>jndi-1.0</feature> <feature>usr:example</feature> </featureManager>   <httpEndpoint host=
    "localhost" httpPort=
    "9080" httpsPort=
    "9443" id=
    "defaultHttpEndpoint"/>   <logging maxFileSize=
    "200" maxFiles=
    "10" traceSpecification=
    "com.ibm.ws.jndi.*=ALL:org.apache.aries.jndi.*=ALL :com.ibm.ws.kernel.feature.*=ALL=enabled:javax.naming=ALL=enabled :org.osgi.*=ALL=enabled:org.eclipse.osgi.framework.*=ALL
    "/>    <applicationMonitor updateTrigger=
    "mbean"/>   <application id=
    "exampleApp" location=
    "exampleApp.eba" name=
    "exampleApp" type=
    "eba" />   </server>
    


    PS: I changed some values before I post here for to comply with IBM confidentiality policy.
  • yusufe
    yusufe
    5 Posts

    Re: Unable to lookup registered service from WAB

    ‏2013-04-01T04:52:55Z  
    • yusufe
    • ‏2013-04-01T04:49:26Z
    • Liberty version: 8.5.next.beta-20130309-1525
    • Yes, com.example is exported
    • IBM package also contains com.example

    <pre class="jive-pre"> <server description= "new server"> <!-- Enable features --> <featureManager> <feature>jsp-2.2</feature> <feature>localConnector-1.0</feature> <feature>osgiconsole-1.0</feature> <feature>osgi-3.8.2</feature> <feature>wab-1.0</feature> <feature>servlet-3.0</feature> <feature>blueprint-1.0</feature> <feature>jndi-1.0</feature> <feature>usr:example</feature> </featureManager> <httpEndpoint host= "localhost" httpPort= "9080" httpsPort= "9443" id= "defaultHttpEndpoint"/> <logging maxFileSize= "200" maxFiles= "10" traceSpecification= "com.ibm.ws.jndi.*=ALL:org.apache.aries.jndi.*=ALL :com.ibm.ws.kernel.feature.*=ALL=enabled:javax.naming=ALL=enabled :org.osgi.*=ALL=enabled:org.eclipse.osgi.framework.*=ALL "/> <applicationMonitor updateTrigger= "mbean"/> <application id= "exampleApp" location= "exampleApp.eba" name= "exampleApp" type= "eba" /> </server> </pre>

    PS: I changed some values before I post here for to comply with IBM confidentiality policy.
    One simple note about com.example is exported or not:

    There can not be an Export-Package header in feature mf file instead there is IBM-API-Package. And yes com.example also appears in IBM-API-Package.
  • Emily Jiang
    Emily Jiang
    10 Posts

    Re: Unable to lookup registered service from WAB

    ‏2013-04-04T15:58:59Z  
    • yusufe
    • ‏2013-04-01T04:52:55Z
    One simple note about com.example is exported or not:

    There can not be an Export-Package header in feature mf file instead there is IBM-API-Package. And yes com.example also appears in IBM-API-Package.
    I am working with Yusuf offline to identify the problem.
    Regards
    Emily
  • Jacek_Laskowski
    Jacek_Laskowski
    133 Posts

    Re: Unable to lookup registered service from WAB

    ‏2013-04-05T07:38:33Z  
    I am working with Yusuf offline to identify the problem.
    Regards
    Emily
    Hi Emily,

    Let us know what the issue and its solution were.

    Jacek
    Japila :: verba docent, exempla trahunt
  • Emily Jiang
    Emily Jiang
    10 Posts

    Re: Unable to lookup registered service from WAB

    ‏2013-04-19T10:00:29Z  

    The services declared in the IBM-API-Service in the declared feature will not be made to an EBA framework unless there is a blueprint xml to specify the service dependencies. Therefore to get the service injecting into the EAB framework, you will need to create a blueprint.xml for the WAB and then declare the service dependency in the xml (In your WAB, you need to import the corresponding packages of course) . Then in the servlet, you can use jndi look up such as osgi:service, blueprint:comp or even the raw look up via bundle context to get hold of the service. We are updating our inforcenter doc to make it much clearer.

     

    Hope this helps.

    Emily