OpenEJB in Grizzly and Jersey(Need help)

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

OpenEJB in Grizzly and Jersey(Need help)

Radhakrishna Kalyan
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

OpenEJB-Jersey-ErrorLog.txt (16K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: OpenEJB in Grizzly and Jersey(Need help)

oleksiys
Administrator
Hi,

not sure if it has something to do with Grizzly, looks like initial context factory is not getting propagated.

Thanks.

WBR,
Alexey.

On 19.10.13 10:22, Radhakrishna Kalyan wrote:
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