You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@geronimo.apache.org by sanjay kumar <sa...@gmail.com> on 2011/01/17 09:03:09 UTC

Geronimo 2.2, EJB call from client code running on same server

Hi all,
   I am trying to call an EJB from a client that is itself deployed in same
server i.e Geronimo 2.2. But I am getting Exception.
The code to call EJB is:
try {

            Context icontext=new InitialContext();
             obj = icontext.lookup("ejbName");
            ......................
......................
}
.............


And I am getting exception as:

javax.naming.NameNotFoundException: ejbName
    at
org.apache.xbean.naming.context.AbstractContext.lookup(AbstractContext.java:167)
    at
org.apache.xbean.naming.context.AbstractContext.lookup(AbstractContext.java:605)
    at javax.naming.InitialContext.lookup(InitialContext.java:392)
    at
com.viithiisys.eadmin.security.EadminLoginModule.login(EadminLoginModule.java:123)
    at
org.apache.geronimo.security.jaas.ClassOptionLoginModule.login(ClassOptionLoginModule.java:58)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav
-- 




I have @Local and @Remote annotations in the EJB. And it works properly when
called from external client. I have tried iContext.lookup("ejb/beanrefname")
as well as all these:
lookup("local:/ejb/UserManagerImplLocal");
.lookup("java:/comp/env/ejb/UserManagerImplLocal");



Can anyone give me any idea how to accomplish this.?
How to lookup an EJB from client code that resides in same server.?
and all that...
Regards:
Sanjay Kumar
sanjaykumar2891987@gmail.com
Java Developer

Re: Geronimo 2.2, EJB call from client code running on same server

Posted by fordendk <da...@pwsindonesia.com>.
I have a solution to this. It took a bit of messing around but I managed to
get it working (session EJB calling another session EJB in the same
container transaction using local EJB interface through JNDI lookup). My
solution is using Geronimo 2.2.1 and can be found on my blog here: 
http://blog.pwsindonesia.com/index.php/2011/06/07/how_to_call_geronimo_2_2_local_ejb_using
http://blog.pwsindonesia.com/index.php/2011/06/07/how_to_call_geronimo_2_2_local_ejb_using 

--
View this message in context: http://apache-geronimo.328035.n3.nabble.com/Geronimo-2-2-EJB-call-from-client-code-running-on-same-server-tp2270889p3034732.html
Sent from the Users mailing list archive at Nabble.com.

Re: Geronimo 2.2, EJB call from client code running on same server

Posted by Ivan <xh...@gmail.com>.
Hi,
As mentioned by other members, if you want to call the ejb in the managed
instance, e.g. another ejb, servlet, jsf managed bean. You might need to
configure to map the ejb to local naming context. There are some samples in
the testsuite of geronimo.
If not, you could use the local initial context factory of OpenEJB. If you
are not sure the name, in the past, I always try to invoke the list("")
method to show what could be found in the context.

2011/1/17 sanjay kumar <sa...@gmail.com>

> Hi,
> Thanks, I have already done that too. But all in vain........Still not
> finding any solutions.
>
>
> On Mon, Jan 17, 2011 at 5:45 PM, Shawn Jiang <ge...@gmail.com> wrote:
>
>> try this:
>>
>> Properties p = new Properties();
>> p.put("java.naming.factory.initial", "org.apache.openejb.client.RemoteInitialContextFactory");
>> p.put("java.naming.provider.url", "ejbd://localhost:4201");// user and pass optionalp.put("java.naming.security.principal", "myuser");
>> p.put("java.naming.security.credentials", "mypass");
>>
>> InitialContext ctx = new InitialContext(p);
>>
>> MyBean myBean = (MyBean) ctx.lookup("MyBeanRemote");
>>
>>
>> On Mon, Jan 17, 2011 at 6:12 PM, sanjay kumar <
>> sanjaykumar2891987@gmail.com> wrote:
>>
>>> Hi,
>>> @devid ...
>>>    I have already tried this. Any more suggestion.
>>>
>>>
>>> On Mon, Jan 17, 2011 at 2:01 PM, David Jencks <da...@yahoo.com>wrote:
>>>
>>>> Hi Sanjay,
>>>>
>>>> IIUC you are trying to get to the ejb from a javaee app that is not part
>>>> of the app containing the ejb?
>>>>
>>>> (if they are part of the same app your can use an ejb-link IIRC)
>>>>
>>>> I think you can either include a properties object in new
>>>> InitialContext(properties) with the openejb jndi properties to use openejb
>>>> jndi directly or include an ejb-ref or @EJB and use some configuration in
>>>> the geronimo plan to refer to the ejb in the other app.
>>>>
>>>> hope this helps... it is not a complete answer but might point you in a
>>>> useful direction.
>>>>
>>>> thanks
>>>> david jencks
>>>>
>>>> On Jan 17, 2011, at 12:03 AM, sanjay kumar wrote:
>>>>
>>>>
>>>> Hi all,
>>>>    I am trying to call an EJB from a client that is itself deployed in
>>>> same server i.e Geronimo 2.2. But I am getting Exception.
>>>> The code to call EJB is:
>>>> try {
>>>>
>>>>             Context icontext=new InitialContext();
>>>>              obj = icontext.lookup("ejbName");
>>>>             ......................
>>>> ......................
>>>> }
>>>> .............
>>>>
>>>>
>>>> And I am getting exception as:
>>>>
>>>> javax.naming.NameNotFoundException: ejbName
>>>>     at
>>>> org.apache.xbean.naming.context.AbstractContext.lookup(AbstractContext.java:167)
>>>>     at
>>>> org.apache.xbean.naming.context.AbstractContext.lookup(AbstractContext.java:605)
>>>>     at javax.naming.InitialContext.lookup(InitialContext.java:392)
>>>>     at
>>>> com.viithiisys.eadmin.security.EadminLoginModule.login(EadminLoginModule.java:123)
>>>>     at
>>>> org.apache.geronimo.security.jaas.ClassOptionLoginModule.login(ClassOptionLoginModule.java:58)
>>>>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>>>     at
>>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav
>>>> --
>>>>
>>>>
>>>>
>>>>
>>>> I have @Local and @Remote annotations in the EJB. And it works properly
>>>> when called from external client. I have tried
>>>> iContext.lookup("ejb/beanrefname")
>>>> as well as all these:
>>>> lookup("local:/ejb/UserManagerImplLocal");
>>>> .lookup("java:/comp/env/ejb/UserManagerImplLocal");
>>>>
>>>>
>>>>
>>>> Can anyone give me any idea how to accomplish this.?
>>>> How to lookup an EJB from client code that resides in same server.?
>>>> and all that...
>>>> Regards:
>>>> Sanjay Kumar
>>>> sanjaykumar2891987@gmail.com
>>>> Java Developer
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>> --
>>> Regards:
>>> Sanjay Kumar
>>> sanjaykumar2891987@gmail.com
>>> Java Developer
>>>
>>>
>>>
>>
>>
>> --
>> Shawn
>>
>
>
>
> --
> Regards:
> Sanjay Kumar
> sanjaykumar2891987@gmail.com
> Java Developer
>
>
>


-- 
Ivan

Re: Geronimo 2.2, EJB call from client code running on same server

Posted by sanjay kumar <sa...@gmail.com>.
Hi,
Thanks, I have already done that too. But all in vain........Still not
finding any solutions.

On Mon, Jan 17, 2011 at 5:45 PM, Shawn Jiang <ge...@gmail.com> wrote:

> try this:
>
> Properties p = new Properties();
> p.put("java.naming.factory.initial", "org.apache.openejb.client.RemoteInitialContextFactory");
> p.put("java.naming.provider.url", "ejbd://localhost:4201");// user and pass optionalp.put("java.naming.security.principal", "myuser");
> p.put("java.naming.security.credentials", "mypass");
>
> InitialContext ctx = new InitialContext(p);
>
> MyBean myBean = (MyBean) ctx.lookup("MyBeanRemote");
>
>
> On Mon, Jan 17, 2011 at 6:12 PM, sanjay kumar <
> sanjaykumar2891987@gmail.com> wrote:
>
>> Hi,
>> @devid ...
>>    I have already tried this. Any more suggestion.
>>
>>
>> On Mon, Jan 17, 2011 at 2:01 PM, David Jencks <da...@yahoo.com>wrote:
>>
>>> Hi Sanjay,
>>>
>>> IIUC you are trying to get to the ejb from a javaee app that is not part
>>> of the app containing the ejb?
>>>
>>> (if they are part of the same app your can use an ejb-link IIRC)
>>>
>>> I think you can either include a properties object in new
>>> InitialContext(properties) with the openejb jndi properties to use openejb
>>> jndi directly or include an ejb-ref or @EJB and use some configuration in
>>> the geronimo plan to refer to the ejb in the other app.
>>>
>>> hope this helps... it is not a complete answer but might point you in a
>>> useful direction.
>>>
>>> thanks
>>> david jencks
>>>
>>> On Jan 17, 2011, at 12:03 AM, sanjay kumar wrote:
>>>
>>>
>>> Hi all,
>>>    I am trying to call an EJB from a client that is itself deployed in
>>> same server i.e Geronimo 2.2. But I am getting Exception.
>>> The code to call EJB is:
>>> try {
>>>
>>>             Context icontext=new InitialContext();
>>>              obj = icontext.lookup("ejbName");
>>>             ......................
>>> ......................
>>> }
>>> .............
>>>
>>>
>>> And I am getting exception as:
>>>
>>> javax.naming.NameNotFoundException: ejbName
>>>     at
>>> org.apache.xbean.naming.context.AbstractContext.lookup(AbstractContext.java:167)
>>>     at
>>> org.apache.xbean.naming.context.AbstractContext.lookup(AbstractContext.java:605)
>>>     at javax.naming.InitialContext.lookup(InitialContext.java:392)
>>>     at
>>> com.viithiisys.eadmin.security.EadminLoginModule.login(EadminLoginModule.java:123)
>>>     at
>>> org.apache.geronimo.security.jaas.ClassOptionLoginModule.login(ClassOptionLoginModule.java:58)
>>>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>>     at
>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav
>>> --
>>>
>>>
>>>
>>>
>>> I have @Local and @Remote annotations in the EJB. And it works properly
>>> when called from external client. I have tried
>>> iContext.lookup("ejb/beanrefname")
>>> as well as all these:
>>> lookup("local:/ejb/UserManagerImplLocal");
>>> .lookup("java:/comp/env/ejb/UserManagerImplLocal");
>>>
>>>
>>>
>>> Can anyone give me any idea how to accomplish this.?
>>> How to lookup an EJB from client code that resides in same server.?
>>> and all that...
>>> Regards:
>>> Sanjay Kumar
>>> sanjaykumar2891987@gmail.com
>>> Java Developer
>>>
>>>
>>>
>>>
>>
>>
>> --
>> Regards:
>> Sanjay Kumar
>> sanjaykumar2891987@gmail.com
>> Java Developer
>>
>>
>>
>
>
> --
> Shawn
>



-- 
Regards:
Sanjay Kumar
sanjaykumar2891987@gmail.com
Java Developer

Re: Geronimo 2.2, EJB call from client code running on same server

Posted by Shawn Jiang <ge...@gmail.com>.
try this:

Properties p = new Properties();
p.put("java.naming.factory.initial",
"org.apache.openejb.client.RemoteInitialContextFactory");
p.put("java.naming.provider.url", "ejbd://localhost:4201");// user and
pass optionalp.put("java.naming.security.principal", "myuser");
p.put("java.naming.security.credentials", "mypass");

InitialContext ctx = new InitialContext(p);

MyBean myBean = (MyBean) ctx.lookup("MyBeanRemote");


On Mon, Jan 17, 2011 at 6:12 PM, sanjay kumar
<sa...@gmail.com>wrote:

> Hi,
> @devid ...
>    I have already tried this. Any more suggestion.
>
>
> On Mon, Jan 17, 2011 at 2:01 PM, David Jencks <da...@yahoo.com>wrote:
>
>> Hi Sanjay,
>>
>> IIUC you are trying to get to the ejb from a javaee app that is not part
>> of the app containing the ejb?
>>
>> (if they are part of the same app your can use an ejb-link IIRC)
>>
>> I think you can either include a properties object in new
>> InitialContext(properties) with the openejb jndi properties to use openejb
>> jndi directly or include an ejb-ref or @EJB and use some configuration in
>> the geronimo plan to refer to the ejb in the other app.
>>
>> hope this helps... it is not a complete answer but might point you in a
>> useful direction.
>>
>> thanks
>> david jencks
>>
>> On Jan 17, 2011, at 12:03 AM, sanjay kumar wrote:
>>
>>
>> Hi all,
>>    I am trying to call an EJB from a client that is itself deployed in
>> same server i.e Geronimo 2.2. But I am getting Exception.
>> The code to call EJB is:
>> try {
>>
>>             Context icontext=new InitialContext();
>>              obj = icontext.lookup("ejbName");
>>             ......................
>> ......................
>> }
>> .............
>>
>>
>> And I am getting exception as:
>>
>> javax.naming.NameNotFoundException: ejbName
>>     at
>> org.apache.xbean.naming.context.AbstractContext.lookup(AbstractContext.java:167)
>>     at
>> org.apache.xbean.naming.context.AbstractContext.lookup(AbstractContext.java:605)
>>     at javax.naming.InitialContext.lookup(InitialContext.java:392)
>>     at
>> com.viithiisys.eadmin.security.EadminLoginModule.login(EadminLoginModule.java:123)
>>     at
>> org.apache.geronimo.security.jaas.ClassOptionLoginModule.login(ClassOptionLoginModule.java:58)
>>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>     at
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav
>> --
>>
>>
>>
>>
>> I have @Local and @Remote annotations in the EJB. And it works properly
>> when called from external client. I have tried
>> iContext.lookup("ejb/beanrefname")
>> as well as all these:
>> lookup("local:/ejb/UserManagerImplLocal");
>> .lookup("java:/comp/env/ejb/UserManagerImplLocal");
>>
>>
>>
>> Can anyone give me any idea how to accomplish this.?
>> How to lookup an EJB from client code that resides in same server.?
>> and all that...
>> Regards:
>> Sanjay Kumar
>> sanjaykumar2891987@gmail.com
>> Java Developer
>>
>>
>>
>>
>
>
> --
> Regards:
> Sanjay Kumar
> sanjaykumar2891987@gmail.com
> Java Developer
>
>
>


-- 
Shawn

Re: Geronimo 2.2, EJB call from client code running on same server

Posted by sanjay kumar <sa...@gmail.com>.
Hi,
@devid ...
   I have already tried this. Any more suggestion.

On Mon, Jan 17, 2011 at 2:01 PM, David Jencks <da...@yahoo.com>wrote:

> Hi Sanjay,
>
> IIUC you are trying to get to the ejb from a javaee app that is not part of
> the app containing the ejb?
>
> (if they are part of the same app your can use an ejb-link IIRC)
>
> I think you can either include a properties object in new
> InitialContext(properties) with the openejb jndi properties to use openejb
> jndi directly or include an ejb-ref or @EJB and use some configuration in
> the geronimo plan to refer to the ejb in the other app.
>
> hope this helps... it is not a complete answer but might point you in a
> useful direction.
>
> thanks
> david jencks
>
> On Jan 17, 2011, at 12:03 AM, sanjay kumar wrote:
>
>
> Hi all,
>    I am trying to call an EJB from a client that is itself deployed in same
> server i.e Geronimo 2.2. But I am getting Exception.
> The code to call EJB is:
> try {
>
>             Context icontext=new InitialContext();
>              obj = icontext.lookup("ejbName");
>             ......................
> ......................
> }
> .............
>
>
> And I am getting exception as:
>
> javax.naming.NameNotFoundException: ejbName
>     at
> org.apache.xbean.naming.context.AbstractContext.lookup(AbstractContext.java:167)
>     at
> org.apache.xbean.naming.context.AbstractContext.lookup(AbstractContext.java:605)
>     at javax.naming.InitialContext.lookup(InitialContext.java:392)
>     at
> com.viithiisys.eadmin.security.EadminLoginModule.login(EadminLoginModule.java:123)
>     at
> org.apache.geronimo.security.jaas.ClassOptionLoginModule.login(ClassOptionLoginModule.java:58)
>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>     at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav
> --
>
>
>
>
> I have @Local and @Remote annotations in the EJB. And it works properly
> when called from external client. I have tried
> iContext.lookup("ejb/beanrefname")
> as well as all these:
> lookup("local:/ejb/UserManagerImplLocal");
> .lookup("java:/comp/env/ejb/UserManagerImplLocal");
>
>
>
> Can anyone give me any idea how to accomplish this.?
> How to lookup an EJB from client code that resides in same server.?
> and all that...
> Regards:
> Sanjay Kumar
> sanjaykumar2891987@gmail.com
> Java Developer
>
>
>
>


-- 
Regards:
Sanjay Kumar
sanjaykumar2891987@gmail.com
Java Developer

Re: Geronimo 2.2, EJB call from client code running on same server

Posted by David Jencks <da...@yahoo.com>.
Hi Sanjay,

IIUC you are trying to get to the ejb from a javaee app that is not part of the app containing the ejb?

(if they are part of the same app your can use an ejb-link IIRC)

I think you can either include a properties object in new InitialContext(properties) with the openejb jndi properties to use openejb jndi directly or include an ejb-ref or @EJB and use some configuration in the geronimo plan to refer to the ejb in the other app.

hope this helps... it is not a complete answer but might point you in a useful direction.

thanks
david jencks
  
On Jan 17, 2011, at 12:03 AM, sanjay kumar wrote:

> 
> Hi all,
>    I am trying to call an EJB from a client that is itself deployed in same server i.e Geronimo 2.2. But I am getting Exception.
> The code to call EJB is:
> try {
>                 
>             Context icontext=new InitialContext();
>              obj = icontext.lookup("ejbName");
>             ......................
> ......................
> }
> .............
> 
> 
> And I am getting exception as:
> 
> javax.naming.NameNotFoundException: ejbName
>     at org.apache.xbean.naming.context.AbstractContext.lookup(AbstractContext.java:167)
>     at org.apache.xbean.naming.context.AbstractContext.lookup(AbstractContext.java:605)
>     at javax.naming.InitialContext.lookup(InitialContext.java:392)
>     at com.viithiisys.eadmin.security.EadminLoginModule.login(EadminLoginModule.java:123)
>     at org.apache.geronimo.security.jaas.ClassOptionLoginModule.login(ClassOptionLoginModule.java:58)
>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav
> -- 
> 
> 
> 
> 
> I have @Local and @Remote annotations in the EJB. And it works properly when called from external client. I have tried iContext.lookup("ejb/beanrefname")
> as well as all these:
> lookup("local:/ejb/UserManagerImplLocal");
> .lookup("java:/comp/env/ejb/UserManagerImplLocal");
> 
> 
> 
> Can anyone give me any idea how to accomplish this.?
> How to lookup an EJB from client code that resides in same server.?
> and all that...
> Regards:
> Sanjay Kumar
> sanjaykumar2891987@gmail.com
> Java Developer
> 
>