Hello,
I am trying to make a remote EJB call from one Stateless Session Bean to
another in EJB3.0. These two SLSBs are deployed to 2 separate instances
of GF2.1 and these instances of GF2.1 do not belong in a same cluster.
1. I have no problem in making this remote EJB call from 1 SLSB to
another by following the instructions here:
https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html#cross-appserverremoteref
2. However, when I tried to programmatically specify remote host and
port to make the exact same EJB call by following another set of
instructions here:
https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html#nonJavaEEwebcontainerRemoteEJB
(skipped Step 3 since the GF instance already has all the necessary code
in its classpath)
I got an exception:
Caused by: javax.naming.NameNotFoundException: AMService not found
In both cases (1 and 2 above) the target JNDI name for the remote SLSB
is AMService. The two experiments point to the same AMService instance
(same deployment also). I can switch back and forth between the 2
experiments and experiment 1 always worked and experiment 2 always threw
the name not found exception.
I also tried many JNDI name permutations in experiment 2 , such as by
adding the ejb/ prefix or the java:comp/env prefix and the outcome is
always the same (just the name in the name not found exception is
different).
Is there a way to programmatically specify target host and port when
making remote EJB from one SLSB to another (in 2 separate GF2.1 instances).
Thanks for any help in advance.
Ming
Ming Chan wrote:
> Thanks for your reply again, Kenneth.
>
> However, I am not able to get things to work (yet) this time. Would
> appreciate any further advise. Here is what I have done so far.
>
> 1. In the previous test, I have:
>
> @EJB(name="AMService")
> private AMServiceRemote amService;
>
> and
>
> <ejb-ref>
> <ejb-ref-name>AMService</ejb-ref-name>
>
> <jndi-name>corbaname:iiop:129.155.9.252:3700#AMService</jndi-name>
> </ejb-ref>
>
> The above works.
>
> 2. Now without making any changes to the target remote EJB, I changed
> my client EJB to do the following instead:
>
> Removed sun-ejb-jar.xml and above injection for EJB reference.
>
> Added code to obtain remote EJB reference:
>
> Properties props = new Properties();
>
> props.setProperty("java.naming.factory.initial",
> "com.sun.enterprise.naming.SerialInitContextFactory");
>
> props.setProperty("java.naming.factory.url.pkgs",
> "com.sun.enterprise.naming");
>
> props.setProperty("java.naming.factory.state",
>
> "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
>
> props.setProperty("org.omg.CORBA.ORBInitialHost",
> "129.155.9.252");
>
> props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
>
> InitialContext ic = new InitialContext(props);
>
> AMServiceRemote amService = (AMServiceRemote)
> ic.lookup("AMService");
>
> And I got an exception this time in the server log for the client EJB:
>
> Caused by: javax.naming.NameNotFoundException: AMService not found
>
> Again, the target EJB has not been changed or redeployed, just same as
> before.
>
> Am I missing something ? Please advise.
>
> Thanks again.
> Ming
>
>
>
>
>
>
>
>
>
>
> Kenneth Saks wrote:
>> Glad to hear that worked well for you. If you want to specify
>> everything dynamically you should be able to use the approach
>> outlined here :
>> https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html#nonJavaEEwebcontainerRemoteEJB
>> (you can skip Step 3 since the GF instance
>> already has all the necessary code in its classpath) In this case,
>> the target host/port are configured
>> as part of the InitialContext() instance itself. Then, all lookups
>> through that context are served by the target server instance. That
>> means
>> the lookup string is just the target JNDI name, without the
>> corbaname:iiop.. prefix.
>> On Mar 26, 2010, at 11:34 AM, Ming Chan wrote:
>>
>>
>>> Thank you for your reply Kenneth.
>>>
>>> What you suggested worked great in my test project in which one ejb
>>> makes remote call to another ejb in a different GL instance.
>>>
>>> Now I have another follow up question, hope you don't mind.
>>>
>>> Is there another way to achieve the same cross ejb and cross GL
>>> instance remote call so that the remote ejb's host name and port are
>>> specified programmatically rather than statically in sun-ejb-jar.xml ?
>>>
>>> The reason I asked is, we can configure sun-ejb-jar.xml for it to
>>> point to a target EJB in a development environment during coding.
>>> But then after development the same project will be deployed to
>>> different environments such as UAT, Production and a few other
>>> environments in between. This would mean every time we deploy the
>>> same project to a different environment the deployer would need to
>>> rememeber to change the host name/port in the sun-ejb-jar.xml file
>>> so that they can point to the target environment that the project is
>>> being deployed into.
>>>
>>> Would it be possible to specify the host_name and port
>>> programmatically ? So that these information can be looked up as
>>> system properties from the GL instance in the environment that the
>>> project is being deployed into
>>> Hope my question makes sense and thanks again for your help.
>>>
>>> Regards,
>>> Ming
>>>
>>>
>>>
>>> Kenneth Saks wrote:
>>>
>>>> On Mar 26, 2010, at 9:50 AM, Ming Chan wrote:
>>>>
>>>>
>>>>
>>>>> Hello,
>>>>>
>>>>> Thanks for publishing the very detailed information here:
>>>>>
>>>>> https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html#cross-appserverremoteref
>>>>>
>>>>>
>>>>> I have a follow up question.
>>>>>
>>>>> I would like to access from one stateless session bean (SLSB) to
>>>>> another
>>>>> stateless session bean (SLSB) using remote EJB interface. Both are
>>>>> EJB3.0 session beans running on difference instances of glassfish
>>>>> 2.1.
>>>>> Each of these session beans is running on its own glassfish
>>>>> instance and
>>>>> these two glassfish instances do not belong to a same cluster.
>>>>>
>>>>> The mentioned reference suggests we do the following:
>>>>>
>>>>> Within the servlet :
>>>>>
>>>>> @EJB(name="fooejbref")
>>>>> private FooRemote fooRemote;
>>>>>
>>>>> Within sun-web.xml :
>>>>>
>>>>> <ejb-ref>
>>>>> <ejb-ref-name>fooejbref</ejb-ref-name>
>>>>> <jndi-name>corbaname:iiop:host2:3700#Foo</jndi-name>
>>>>> </ejb-ref>
>>>>>
>>>>> How to access a remote SLSB from another SLSB (rather than from a
>>>>> servlet) ?
>>>>>
>>>> Hi Ming,
>>>>
>>>> In that case, the @EJB would be placed within the SLSB bean class
>>>> and the
>>>> ejb-ref elements would be put in a sun-ejb-jar.xml file. --ken
>>>>
>>>>> Thanks in advance.
>>>>>
>>>>> Ming
>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: ejb-unsubscribe_at_glassfish.dev.java.net
>>>>> For additional commands, e-mail: ejb-help_at_glassfish.dev.java.net
>>>>>
>>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: ejb-unsubscribe_at_glassfish.dev.java.net
>>>> For additional commands, e-mail: ejb-help_at_glassfish.dev.java.net
>>>>
>>>>
>>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: ejb-unsubscribe_at_glassfish.dev.java.net
>>> For additional commands, e-mail: ejb-help_at_glassfish.dev.java.net
>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: ejb-unsubscribe_at_glassfish.dev.java.net
>> For additional commands, e-mail: ejb-help_at_glassfish.dev.java.net
>>
>>
>
>