You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by ymaraner <tp...@gmail.com> on 2013/04/03 17:38:39 UTC

How to reference an EJB in an EAR from a separate WAR?

I have an EAR that consists primarily of a number of EJB modules. Now I need
to develop a WAR that can be deployed separately from the EAR but references
EJBs from within the EAR. 

Since this makes them separate applications, I know that I need to use
remote business interfaces. So, I annotated the first, most useful, bean (a
@Singleton) with both a @Local business interface for use within the EAR and
a @Remote business interface for use outside the EAR.

I have no problem getting a reference to the EJB using the @EJB annotation
from a bean within the EAR. However, I can't seem to get the POJO JAX-RS
class to successfully obtain a reference to the remote business interface
using either @EJB or @Inject. I either get a NullPointerException (@EJB) or
an UnsatisfiedResolutionException (@Inject).

*This is my REST class:
*

*My Singleton has the following annotations and interfaces:
*


*Is there something that I am missing to get this to work?
*





-----
- Tim
--
View this message in context: http://openejb.979440.n4.nabble.com/How-to-reference-an-EJB-in-an-EAR-from-a-separate-WAR-tp4661962.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: How to reference an EJB in an EAR from a separate WAR?

Posted by ymaraner <tp...@gmail.com>.
As it turns out, *it /is/ as simple as I had hoped.* 

The only thing I was missing was the mappedName="/ServerState/" attribute in
my @Singleton annotation.

*This is my REST class:*

*My Singleton has the following annotations and interfaces: *


*And it now works just fine.*

Thanks for the feedback and the outstanding work on TomEE.



-----
- Tim
--
View this message in context: http://openejb.979440.n4.nabble.com/How-to-reference-an-EJB-in-an-EAR-from-a-separate-WAR-tp4661962p4661971.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: How to reference an EJB in an EAR from a separate WAR?

Posted by "John D. Ament" <jo...@gmail.com>.
I don't believe that's the EJB.  Singleton is still a generic singleton
typed object.  You could always test this idea out by putting a log
statement in the constructor and seeing how many times it gets called.


On Wed, Apr 3, 2013 at 1:19 PM, ymaraner <tp...@gmail.com> wrote:

> John D. Ament wrote
> > Using CDI, you should be able to write an extension that observes
> > BeforeBeanDiscovery to add the annotated types using
> > beanManager.createAnnotatedType(Interface.class) and Impl.class.
>
> Looking at those APIs; it doesn't look like I would get a reference to the
> Singleton in my other application but rather a new instance of the class in
> my web application. Not really what I was looking for.
>
>
>
>
> -----
> - Tim
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/How-to-reference-an-EJB-in-an-EAR-from-a-separate-WAR-tp4661962p4661967.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: How to reference an EJB in an EAR from a separate WAR?

Posted by ymaraner <tp...@gmail.com>.
John D. Ament wrote
> Using CDI, you should be able to write an extension that observes
> BeforeBeanDiscovery to add the annotated types using
> beanManager.createAnnotatedType(Interface.class) and Impl.class.

Looking at those APIs; it doesn't look like I would get a reference to the
Singleton in my other application but rather a new instance of the class in
my web application. Not really what I was looking for.




-----
- Tim
--
View this message in context: http://openejb.979440.n4.nabble.com/How-to-reference-an-EJB-in-an-EAR-from-a-separate-WAR-tp4661962p4661967.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: How to reference an EJB in an EAR from a separate WAR?

Posted by "John D. Ament" <jo...@gmail.com>.
Using CDI, you should be able to write an extension that observes
BeforeBeanDiscovery to add the annotated types using
beanManager.createAnnotatedType(Interface.class) and Impl.class.


On Wed, Apr 3, 2013 at 12:56 PM, ymaraner <tp...@gmail.com> wrote:

> Romain Manni-Bucau wrote
> > remote reference are obtained either using a lookup or openejb remote
> > injection feature (see http://tomee.apache.org/ejb-refs.html)
>
> I had looked at that page; however, the problem with these approaches is
> that they all involve entries in the ejb-jar.xml file for EJBs that access
> remote EJBs. I'm trying to reference the remote EJB from a POJO. It has no
> ejb-jar.xml file.
>
> Is it possible to inject a remote EJB reference into a POJO in a different
> application using CDI? Or does the @EJB or @Inject annotation have to be
> inside of another EJB in order to obtain the remote reference?
>
>
>
>
> -----
> - Tim
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/How-to-reference-an-EJB-in-an-EAR-from-a-separate-WAR-tp4661962p4661964.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: How to reference an EJB in an EAR from a separate WAR?

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Think you didnt look jndiprovider solution
Le 3 avr. 2013 18:57, "ymaraner" <tp...@gmail.com> a écrit :

> Romain Manni-Bucau wrote
> > remote reference are obtained either using a lookup or openejb remote
> > injection feature (see http://tomee.apache.org/ejb-refs.html)
>
> I had looked at that page; however, the problem with these approaches is
> that they all involve entries in the ejb-jar.xml file for EJBs that access
> remote EJBs. I'm trying to reference the remote EJB from a POJO. It has no
> ejb-jar.xml file.
>
> Is it possible to inject a remote EJB reference into a POJO in a different
> application using CDI? Or does the @EJB or @Inject annotation have to be
> inside of another EJB in order to obtain the remote reference?
>
>
>
>
> -----
> - Tim
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/How-to-reference-an-EJB-in-an-EAR-from-a-separate-WAR-tp4661962p4661964.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: How to reference an EJB in an EAR from a separate WAR?

Posted by ymaraner <tp...@gmail.com>.
Romain Manni-Bucau wrote
> remote reference are obtained either using a lookup or openejb remote
> injection feature (see http://tomee.apache.org/ejb-refs.html)

I had looked at that page; however, the problem with these approaches is
that they all involve entries in the ejb-jar.xml file for EJBs that access
remote EJBs. I'm trying to reference the remote EJB from a POJO. It has no
ejb-jar.xml file.

Is it possible to inject a remote EJB reference into a POJO in a different
application using CDI? Or does the @EJB or @Inject annotation have to be
inside of another EJB in order to obtain the remote reference?




-----
- Tim
--
View this message in context: http://openejb.979440.n4.nabble.com/How-to-reference-an-EJB-in-an-EAR-from-a-separate-WAR-tp4661962p4661964.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: How to reference an EJB in an EAR from a separate WAR?

Posted by Romain Manni-Bucau <rm...@gmail.com>.
remote reference are obtained either using a lookup or openejb remote
injection feature (see http://tomee.apache.org/ejb-refs.html)

*Romain Manni-Bucau*
*Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
*Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
*LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
*Github: https://github.com/rmannibucau*



2013/4/3 ymaraner <tp...@gmail.com>

> I have an EAR that consists primarily of a number of EJB modules. Now I
> need
> to develop a WAR that can be deployed separately from the EAR but
> references
> EJBs from within the EAR.
>
> Since this makes them separate applications, I know that I need to use
> remote business interfaces. So, I annotated the first, most useful, bean (a
> @Singleton) with both a @Local business interface for use within the EAR
> and
> a @Remote business interface for use outside the EAR.
>
> I have no problem getting a reference to the EJB using the @EJB annotation
> from a bean within the EAR. However, I can't seem to get the POJO JAX-RS
> class to successfully obtain a reference to the remote business interface
> using either @EJB or @Inject. I either get a NullPointerException (@EJB) or
> an UnsatisfiedResolutionException (@Inject).
>
> *This is my REST class:
> *
>
> *My Singleton has the following annotations and interfaces:
> *
>
>
> *Is there something that I am missing to get this to work?
> *
>
>
>
>
>
> -----
> - Tim
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/How-to-reference-an-EJB-in-an-EAR-from-a-separate-WAR-tp4661962.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>