You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Andre Brito <an...@gmail.com> on 2011/06/03 19:57:57 UTC

Can I lookup a different service from a service without @EJB?

Hey guys. The subject of this thread is ugly, I know. Pardon me, my english
is very poor.

I know I can use @EJB. Is simpler, easier and cleaner. But this question
appeared in the team. With JBoss, if I'm in SessionBean A and I need
SessionBean B, I must call the ServiceLocator. How can I do that with
OpenEJB? I tied this:


> // SessionBean A looking up SessionBean B
> Properties properties = new Properties();
> properties.setProperty(Context.INITIAL..., "RemoteInitialContextFactory");
> properties.setProperty(Context.PROVIDER_URL, "ejbd://10.1.1.2:4201");
> 
> // 10.1.1.2 is where the server is started, using openejb start
> --ejbd-bind.
> 
> Context ctx = new InitialContext(properties);
> ctx.lookup("SessionBeanBRemote");
> 

Apparently, it can't locate SessionBeanB. What am I doing wrong?

Thanks in advance,
Regards,
Andre.

--
View this message in context: http://openejb.979440.n4.nabble.com/Can-I-lookup-a-different-service-from-a-service-without-EJB-tp3571549p3571549.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: Can I lookup a different service from a service without @EJB?

Posted by Romain Manni-Bucau <rm...@gmail.com>.
it works but your properties are false. You should provide the qualified
name of the factory.

2011/6/3 Andre Brito <an...@gmail.com>

> Hey guys. The subject of this thread is ugly, I know. Pardon me, my english
> is very poor.
>
> I know I can use @EJB. Is simpler, easier and cleaner. But this question
> appeared in the team. With JBoss, if I'm in SessionBean A and I need
> SessionBean B, I must call the ServiceLocator. How can I do that with
> OpenEJB? I tied this:
>
>
> > // SessionBean A looking up SessionBean B
> > Properties properties = new Properties();
> > properties.setProperty(Context.INITIAL...,
> "RemoteInitialContextFactory");
> > properties.setProperty(Context.PROVIDER_URL, "ejbd://10.1.1.2:4201");
> >
> > // 10.1.1.2 is where the server is started, using openejb start
> > --ejbd-bind.
> >
> > Context ctx = new InitialContext(properties);
> > ctx.lookup("SessionBeanBRemote");
> >
>
> Apparently, it can't locate SessionBeanB. What am I doing wrong?
>
> Thanks in advance,
> Regards,
> Andre.
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/Can-I-lookup-a-different-service-from-a-service-without-EJB-tp3571549p3571549.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: Can I lookup a different service from a service without @EJB?

Posted by David Blevins <da...@gmail.com>.
On Jun 3, 2011, at 12:56 PM, Andre Brito wrote:

> Sh*t. My fault. It was a typo in my code. Sorry.

:)


> 
> --
> View this message in context: http://openejb.979440.n4.nabble.com/Can-I-lookup-a-different-service-from-a-service-without-EJB-tp3571549p3571907.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.


Re: Can I lookup a different service from a service without @EJB?

Posted by Andre Brito <an...@gmail.com>.
Sh*t. My fault. It was a typo in my code. Sorry.

--
View this message in context: http://openejb.979440.n4.nabble.com/Can-I-lookup-a-different-service-from-a-service-without-EJB-tp3571549p3571907.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: Can I lookup a different service from a service without @EJB?

Posted by David Blevins <da...@gmail.com>.
On Jun 3, 2011, at 10:57 AM, Andre Brito wrote:

> Hey guys. The subject of this thread is ugly, I know. Pardon me, my english
> is very poor.
> 
> I know I can use @EJB. Is simpler, easier and cleaner. But this question
> appeared in the team. With JBoss, if I'm in SessionBean A and I need
> SessionBean B, I must call the ServiceLocator. How can I do that with
> OpenEJB? I tied this:
> 
> 
>> // SessionBean A looking up SessionBean B
>> Properties properties = new Properties();
>> properties.setProperty(Context.INITIAL..., "RemoteInitialContextFactory");
>> properties.setProperty(Context.PROVIDER_URL, "ejbd://10.1.1.2:4201");
>> 
>> // 10.1.1.2 is where the server is started, using openejb start
>> --ejbd-bind.
>> 
>> Context ctx = new InitialContext(properties);
>> ctx.lookup("SessionBeanBRemote");
>> 
> 

This doc has some info.

   http://openejb.apache.org/3.0/service-locator.html

If the two beans are in the same vm you can use the org.apache.openejb.client.LocalInitialContextFactory instead and leave out the Context.PROVIDER_URL.

-David