Pavel Bucek wrote:
> Kedar Mhaswade wrote:
>> Pavel Bucek wrote:
>>>
>>> Hello,
>>>
>>> I have an osgi bundle and I need to determine application name from
>>> context root. I can do something like:
>>>
>>> public static String getAppName(String contextRoot) {
>>> if (contextRoot == null)
>>> return null;
>>> // first check in web modules
>>> List<WebModule> lm =
>>> domain.getApplications().getModules(WebModule.class);
>>> for (WebModule wm : lm) {
>>> if (contextRoot.equals(wm.getContextRoot())) {
>>> return (wm.getName());
>>> }
>>> }
>>> // then check under applications (introduced in V3 not j2ee app)
>>> List<Application> la =
>>> domain.getApplications().getModules(Application.class);
>>> for (Application sapp : la) {
>>> if (contextRoot.equals(sapp.getContextRoot())) {
>>> return (sapp.getName());
>>> }
>>> }
>>> return null;
>>> }
>>>
>>>
>>> but I dont have a instance of Domain. Can it be injected somehow like
>>> in hk2 class with @Service annotation?
>>
>> I believe
>> @Inject
>> volatile Domain domain = null;
>>
>> should work. Have you tried it?
> Yes, I did but domain is not injected.. I thought that these injections
> works only in @Services and its because the are instanciated in some
> special way. This is not my case, its service (declared in
> META.INF/services) but not hk2 service.
>
> (and.. I tried to annotate class with @Service annotation and domain was
> still null).
Oh I did not know that it's not an @Service. My understanding is that it
needs to be an hk2 @Service.
I could be wrong here, but annotating the class as @Service
alone is not enough. Your module's "build" needs to use the hk2-maven-plugin to
generate the hk2 magic for classes annotated as @Service.
>
> If it helps - I instanciate my "service" via ServiceFinder:
> https://jersey.dev.java.net/source/browse/jersey/trunk/jersey/jersey-core/src/main/java/com/sun/jersey/spi/service/ServiceFinder.java?rev=2400&view=markup
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>