How about adding the actual logic to an osgi bundle, and then keep only the
jax-rs resource class inside the webapp? Then the webapp will invoke the
bundle, and that bundle can access the service references as required.

You could also use PrivilegedCarbonContext#getOSGiServices() method if you
need to access osgi services within a webapp.

Dataholders are only supposed to be used within a component, and is not
supposed to be exposed to other components.


On Sat, Feb 7, 2015 at 7:30 PM, Nirmal Fernando <[email protected]> wrote:

> One other way that I can think of is, by introducing a service component
> which has references to all OSGi service we require and then accessing the
> data holder via web app.
>
> On Sat, Feb 7, 2015 at 7:24 PM, Supun Sethunga <[email protected]> wrote:
>
>> Hi,
>>
>> Im trying to expose some OSGI services as REST API's. (Please refer mail
>> thread "[Architecture] REST API for Machine Learner")
>> For that, i want to access the Service References of the services which
>> were registered in the OSGI context by their respective bundle activators,
>> from the web app (.war).
>>
>> I tried the following methods [1] and [2], But both returns a NULL bundle
>> contexts.
>> (Here 'Project.class' is the web app's class name)
>>
>> [1] BundleContext bundleContext =
>> FrameworkUtil.getBundle(Project.class).getBundleContext();
>>
>> [2] @Context
>>       ServletContext servletContext;
>>       BundleContext bundleContext = (BundleContext)
>> servletContext.getAttribute("osgi-bundlecontext");
>>
>> AFAIU this happens because the 'Project.class' is not loaded by an OSGi
>> bundle class loader, because it is bundled as an web app.
>>
>> Is there a different apporach to expose the OSGi servioce as REST API's?
>> Can anyone please shed some light here?
>>
>> --
>> *Supun Sethunga*
>> Software Engineer
>> WSO2, Inc.
>> lean | enterprise | middleware
>> Mobile : +94 716546324
>>
>
>
>
> --
>
> Thanks & regards,
> Nirmal
>
> Senior Software Engineer- Platform Technologies Team, WSO2 Inc.
> Mobile: +94715779733
> Blog: http://nirmalfdo.blogspot.com/
>
>
>


-- 

*Kasun Gajasinghe*Senior Software Engineer, WSO2 Inc.
email: kasung AT spamfree wso2.com
linked-in: http://lk.linkedin.com/in/gajasinghe
blog: http://kasunbg.org
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to