users@glassfish.java.net

Re: Can a web service deployed in Grizzly access Felix

From: Jerome Dochez <Jerome.Dochez_at_Sun.COM>
Date: Wed, 20 May 2009 09:21:39 -0700

On May 20, 2009, at 5:38 AM, paulbrickell wrote:

>
> I don't know if this is a silly question, but I am having some
> fundamental
> issues understanding the Glassfish v3 architecture and could use a
> pointer.
>
> I have created a bundle and added an entry in the glassfish/
> felix.conf e.g.
>
> file:///home/me/myworkspace/my-bundle/target/my-bundle-1.0-
> SNAPSHOT.jar
>
> I see this bundle starting and all is well. It opens a socket to
> which I can
> connect and exchange data, which is nice. The reason I created a
> bundle and
> not a H2K module is that I want it to be activated at server start-
> up time.
> I could not see a way of doing this with H2K. Maybe I missed
> something.
the easiest would be to add a startup service :

@Service
public class MyStartup implements Startup {

        ...
}

now if you don't need any GlassFish services, OSGi route is fine.
>
>
> Now I want to reference this service from a web service that I have
> deployed
> in Grizzly.
which service ? this service was added to OSGi service registry ?
> I simply cannot figure out how to do this. The docs do not
> really cover this, which leads me to believe I am doing something
> fundamentally wrong.
>
> Do Felix and Grizzly share any kind of context or is there a static
> way to
> access the Felix services from a web application deployed in Grizzly?
>
> I have tried this....
>
> wsContext.getMessageContext();
> ServletContext sCtx = (ServletContext)
> mc.get(MessageContext.SERVLET_CONTEXT);
> Object habitat = sCtx.getAttribute("org.glassfish.servlet.habitat");
>
> This, I believe, gets me a reference to the H2K habitat, but my
> bundle is an
> OSGi bundle deployed in Felix, not an H2K service. Can I navigate to
> my
> bundle through this habitat? Is it right to try? If so is there a
> maven
> dependency I need to pick up the Habitat class as I cannot seem to
> find it
> anywhere.

I can see Sahoo helped you getting to the habitat, I believe you can
also try normal Java EE injection,

@Resource
Habitat habitat;

or even better, if your service was added to the habitat or as an OSGi
service then you do not need to depend on hk2 at all, you can just do

@Resource(mappedName="osgiName")
SomeService myService

look at my latest blog entry http://blogs.sun.com/dochez/

it might help.

Jerome

>
> I would appreciate any pointers. TIA.
> Paul B.
>
>
>
> --
> View this message in context: http://www.nabble.com/Can-a-web-service-deployed-in-Grizzly-access-Felix-tp23634609p23634609.html
> Sent from the java.net - glassfish users mailing list archive at
> Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>