users@grizzly.java.net

OpenEJB in Grizzly and Jersey(Need help)

From: Radhakrishna Kalyan <nrkkalyan_at_gmail.com>
Date: Sat, 19 Oct 2013 19:22:53 +0200

Hi

Iam looking to develop a REST based webservice but I don't want to use any
application server. All I am looking is to start my application which in
turn should start the Grizzly server with CDI along with Jax-RS. I am
using OpenEJB as the EJB Container to inject CDI.

I have used "Grizzly server" as http server and Jersey for my Jax-RS
implementation and now I would like to use OpenEJB for CDI.

When I tried to write something like

public static void main(String[] args) throws Exception {
        final String baseUri = "http://localhost:" + (System.getenv("PORT")
!= null ? System.getenv("PORT") : "9998")
                + "/";
        final Map<String, String> initParams = new HashMap<String,
String>();
        initParams.put("com.sun.jersey.config.property.packages", "org");
        System.out.println("Starting grizzly...");
        SelectorThread threadSelector =
GrizzlyWebContainerFactory.create(baseUri, initParams);
        System.out
                .println(String.format("Jersey started with WADL available
at %sapplication.wadl.", baseUri, baseUri));

        Properties p = new Properties();
        p.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.LocalInitialContextFactory");

p.setProperty("com.sun.jersey.server.impl.cdi.lookupExtensionInBeanManager",
"true");
        EJBContainer.createEJBContainer(p).getContext().bind("inject",
threadSelector);

 }


But when I start my application then I am getting exception.
Caused by: javax.naming.NoInitialContextException: Need to specify class
name in environment or system property, or as an applet parameter, or in an
application resource file: java.naming.factory.initial
    at
javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
    at
javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
    at
javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
    at javax.naming.InitialContext.getNameParser(InitialContext.java:480)
    at
com.sun.jersey.server.impl.cdi.CDIExtension.diveIntoJNDIContext(CDIExtension.java:264)
    at
com.sun.jersey.server.impl.cdi.CDIExtension.createJerseyConfigJNDIContext(CDIExtension.java:273)
    at
com.sun.jersey.server.impl.cdi.CDIExtension.initialize(CDIExtension.java:192)
    ... 17 more
...More

 Detail exception is attached as attachment.

I am not understanding how to trigger the CDI while starting Grizzly server.

Please give me some pointers if I am doing any wrong or if I should use any
thing more.

Thanks in advance.
-- 
Thanks and Regards
N Radhakrishna Kalyan
P:  +46 733 312 584
http://about.me/nrkkalyan <http://about.me/nrkkalyan>