tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Radhakrishna Kalyan <nrkkal...@gmail.com>
Subject Re: OpenEJB in JavaSE(Need help)
Date Sat, 19 Oct 2013 19:53:36 GMT
Hi,

Great Thank you for your help. It just worked.This is exactly what I was
looking for.
One more thing I wanted to clarify.
Can one use
"EJBContainer.createEJBContainer(properties).getContext().bind("inject",
main1);" in a BootStrap java program from public static void main().
If no then please recommend a proper way of doing this.
Because this is used only in the Junits in most of the examples  and I have
not found any example to use OpenEJB in a Java SE application.

Anyway wanted to share the working code:
public static void main(String... args){
       Main1 main1 = new Main1();
        Properties properties = new Properties();
        properties.setProperty(OpenEjbContainer.OPENEJB_EMBEDDED_REMOTABLE,
"true");

EJBContainer.createEJBContainer(properties).getContext().bind("inject",
main1);
        Thread.currentThread().join();
}
Off course there are other EJB classes exist.

The last statement "Thread.currentThread().join();" was missing. that's why
the application started but stopped immediately.





On Sat, Oct 19, 2013 at 7:42 PM, Romain Manni-Bucau
<rmannibucau@gmail.com>wrote:

> No, cdi works but not deploying a war you can only deploy ejb as jaxrs
> services IIRC.
>
> Look
> http://svn.apache.org/repos/asf/tomee/tomee/trunk/examples/rest-on-ejb/and
> its test which does what you want.
> Le 19 oct. 2013 19:39, "Radhakrishna Kalyan" <nrkkalyan@gmail.com> a
> écrit :
>
> > You mean it should work with CXF if I use EJB annotations instead of
> > @Inject and @Named annotations.
> > I had beans.xml in the META-INF folder in src/main/resources
> >
> >
> > On Sat, Oct 19, 2013 at 7:18 PM, Romain Manni-Bucau
> > <rmannibucau@gmail.com>wrote:
> >
> > > Hmm should work fine if rest services are ejb in embedded mode but pojo
> > are
> > > maybe not deployed depending your version. Think to add a beans.xml too
> > if
> > > not already done
> > > Le 19 oct. 2013 18:49, "Radhakrishna Kalyan" <nrkkalyan@gmail.com> a
> > > écrit :
> > >
> > > > Actually I tried both. But in either case I was getting the
> exception.
> > > > Then I tried to remove all Jersey dependencies and used CXF instead,
> > with
> > > > CXF the exceptions are gone but didn't able to get CDI.
> > > >
> > > >
> > > >
> > > > On Sat, Oct 19, 2013 at 6:17 PM, Romain Manni-Bucau
> > > > <rmannibucau@gmail.com>wrote:
> > > >
> > > > > If you really want jersey set a context factory or start openejb
> > before
> > > > > Le 19 oct. 2013 18:10, "Radhakrishna Kalyan" <nrkkalyan@gmail.com>
> a
> > > > > écrit :
> > > > >
> > > > > > Hi Romain,
> > > > > >
> > > > > > Sorry I didn't get you. If you closely look at the code, I am
> using
> > > the
> > > > > > EJBContainer. But I am getting an exception while running with
> > > Jersey.
> > > > > > If your question was something else. Please let me know.
> > > > > >
> > > > > >
> > > > > > On Sat, Oct 19, 2013 at 5:51 PM, Romain Manni-Bucau
> > > > > > <rmannibucau@gmail.com>wrote:
> > > > > >
> > > > > > > Hi
> > > > > > >
> > > > > > > Why not using EJBContainer?
> > > > > > >
> > > > > > > Note: openejb embedded supports jaxrs through openejb-cxf-rs
> > > > dependency
> > > > > > > Le 19 oct. 2013 16:55, "Radhakrishna Kalyan" <
> > nrkkalyan@gmail.com>
> > > a
> > > > > > > écrit :
> > > > > > >
> > > > > > > > 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 http server with CDI along with
Jax-RS.
> >  I
> > > > felt
> > > > > > > > OpenEJB is the right tool for this.
> > > > > > > >
> > > > > > > > I have used "com.sun.net.httpserver.HttpServer" 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
{
> > > > > > > >         MyBootStrap bootStrap= new MyBootStrap();
> > > > > > > >         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",
> > > > > > > > bootStrap);
> > > > > > > >
> > > > > > > >         HttpServer server = HttpServer.create(new
> > > > > > > InetSocketAddress(9998),
> > > > > > > > 0);
> > > > > > > >         HttpHandler sf =
> > > > > > RuntimeDelegate.getInstance().createEndpoint(new
> > > > > > > > ApplicationConfig(), HttpHandler.class);
> > > > > > > >         server.createContext("/", sf);
> > > > > > > >         server.start();
> > > > > > > >     }
> > > > > > > >
> > > > > > > >
> > > > > > > > But when I start my application then I am getting
exception.
> > > > > > > > java.lang.RuntimeException:
> > > 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
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
> com.sun.jersey.server.impl.cdi.CDIExtension.initialize(CDIExtension.java:196)
> > > > > > > >     at
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
> com.sun.jersey.server.impl.cdi.CDIExtension.beforeBeanDiscovery(CDIExtension.java:297)
> > > > > > > >     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> > > Method)
> > > > > > > >     at
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> > > > > > > >     at
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> > > > > > > >     at java.lang.reflect.Method.invoke(Method.java:597)
> > > > > > > >     at
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
> org.apache.webbeans.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:295)
> > > > > > > >     at
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
> org.apache.webbeans.event.NotificationManager.fireEvent(NotificationManager.java:429)
> > > > > > > > ...More
> > > > > > > >
> > > > > > > >  Detail exception is attached as attachment.
> > > > > > > >
> > > > > > > >
> > > > > > > > I am not understanding how to trigger the CDI while
starting
> > http
> > > > > > 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>
> > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > --
> > > > > > Thanks and Regards
> > > > > > N Radhakrishna Kalyan
> > > > > >
> > > > > > P:  +46 733 312 584
> > > > > > http://about.me/nrkkalyan
> > > > > >  <http://about.me/nrkkalyan>
> > > > > >
> > > > >
> > > >
> > > >
> > > >
> > > > --
> > > > Thanks and Regards
> > > > N Radhakrishna Kalyan
> > > >
> > > > P:  +46 733 312 584
> > > > http://about.me/nrkkalyan
> > > >  <http://about.me/nrkkalyan>
> > > >
> > >
> >
> >
> >
> > --
> > Thanks and Regards
> > N Radhakrishna Kalyan
> >
> > P:  +46 733 312 584
> > http://about.me/nrkkalyan
> >  <http://about.me/nrkkalyan>
> >
>



-- 
Thanks and Regards
N Radhakrishna Kalyan

P:  +46 733 312 584
http://about.me/nrkkalyan
 <http://about.me/nrkkalyan>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message