The Source for Java Technology Collaboration

Home » java.net Forums » GlassFish » GlassFish

Thread: Is there a vendor independent way of accessing EJBs from a standalone
client?

Welcome, Guest Help
Login Login
Guest Settings Guest Settings
Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 4 - Last Post: Feb 23, 2007 3:24 PM by: Ryan
Ryan
Is there a vendor independent way of accessing EJBs from a standalone
client?

Posted: Feb 22, 2007 1:43 AM
  Click to reply to this thread Reply

Hi,

I'm working at setting up an application client and am having some
difficulty accessing EJBs on the server. I'm running my client using an
application client container and am trying it out on a few different
application servers.

However, I'm having difficulty finding a way to lookup EJBs in a vendor
independent manner. Specifically, almost every doc I can find has some
variation of:

Context initialContext = new InitialContext();
Object ref = initialContext.lookup("some vendor specific name here");

If I replace "some vendor specific name here" with the proper vendor
specific name for each app server and re-deploy everything works.

At first I thought I could use application-client.xml to name each EJB
and have the container(s) take care of the mapping, but I haven't had
any luck with this approach. I tried something like this (relevant
parts only):

<ejb-ref>
<ejb-ref-name>ejb/test1234/ConnectionTester</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<remote>domain.ejb.interfaces.ConnectionTesterRemote</remote>
</ejb-ref>

When I deploy to Glassfish using the above I end up with a JNDI name of
"ejb/test1234/ConnectionTester" and can look it up using
"java:comp/env/ejb/test1234/ConnectionTester".

However, when I try to deploy to Geronimo, I get the following error
(while deploying):

org.apache.openejb.OpenEJBException: Cannot find bean
"ejb/test1234/ConnectionTester" referenced by bean "GeronimoEnc".

Obviously I'm missing something because Glassfish appears to use
'ejb-ref-name' as a type of alias for the EJB name while Geronimo thinks
it contains the name of an existing EJB.

Maybe I'm just not thinking clearly tonight, but isn't there some kind
of simple, standard way of looking up an EJB from a standalone client?
Is vendor independence even a realistic goal (that's what the spec is
for right)?

Thanks in advance for any help,
Ryan

P.S. Sorry for the formatting :-(

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net


weberjn

Posts: 17
Re: Is there a vendor independent way of accessing EJBs from a standalone
Posted: Feb 22, 2007 11:59 PM   in response to: Ryan
  Click to reply to this thread Reply

Did you try the RMI over IIOP way?

From
http://java.sun.com/j2se/1.4.2/docs/guide/rmi-iiop/tutorial.html


// STEP 1: Get the Object reference from the Name Service
// using JNDI call.
objref = ic.lookup("HelloService");
System.out.println("Client: Obtained a ref. to Hello server.");

// STEP 2: Narrow the object reference to the concrete type and
// invoke the method.
hi = (HelloInterface) PortableRemoteObject.narrow(
objref, HelloInterface.class);
hi.sayHello( " MARS " );

Ryan
Re: Is there a vendor independent way of accessing EJBs from a standalone
Posted: Feb 23, 2007 12:45 AM   in response to: weberjn
  Click to reply to this thread Reply

Thanks for the reply weberjn. After a bit of discussion tonight we've
decided to target Glassfish and deal with porting to another application
server if it ever needs to be done.

I felt like I was spending as much time ensuring our application was
portable as I was doing actual work. Almost all of the books, tutorials
and docs that I've seen tend to explain how to do things for a specific
application server. I found it almost impossible to find Java EE
examples that showed how to do things in a vendor independent manner.

However, if anyone is aware of a sample EE application (.ear) that will
run on multiple application servers without modification I'd still be
interested in looking at it just for fun.

Ryan


glassfish@javadesktop.org wrote:
> Did you try the RMI over IIOP way?
>
> From
> http://java.sun.com/j2se/1.4.2/docs/guide/rmi-iiop/tutorial.html
>
>
> // STEP 1: Get the Object reference from the Name Service
> // using JNDI call.
> objref = ic.lookup("HelloService");
> System.out.println("Client: Obtained a ref. to Hello server.");
>
> // STEP 2: Narrow the object reference to the concrete type and
> // invoke the method.
> hi = (HelloInterface) PortableRemoteObject.narrow(
> objref, HelloInterface.class);
> hi.sayHello( " MARS " );
> [Message sent by forum member 'weberjn' (weberjn)]
>
> http://forums.java.net/jive/thread.jspa?messageID=204935
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net


Sanjeeb Kumar S...
Re: Is there a vendor independent way of accessing EJBs from a
standalone

Posted: Feb 23, 2007 3:58 AM   in response to: Ryan
  Click to reply to this thread Reply

Ryan,

It is not that difficult to write portable ear/jar/war/rar file. Don't
be under the impression that a portable jar/war/war does not require
any modification when you move from one platform to another. In fact,
they may just have to be modified when you move from one installation to
another while using the same software, but one must not have to change
source code or standard deployment descriptors of a portable
applications. Migration of portable applications should be possible by
just configuring vendor specific deployment descriptors like
sun-ejb-jar.xml, or sun-application-client.xml, etc.

In your example below, a portable way to look up an EJB from an
application client would be to:

1. In application-client.xml, declare a dependency on the EJB using
<ejb-ref> entry. Give it a name. You have already done this:

<ejb-ref>
<ejb-ref-name>ejb/test1234/ConnectionTester</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<remote>domain.ejb.interfaces.ConnectionTesterRemote</remote>
</ejb-ref>


2. In your code, look up in the java:comp/env/ namespace using the above
name. So your code looks like:

Object objref = new InitialContext().lookup("java:comp/env/ejb/test1234/ConnectionTester");

HelloInterface hello = (HelloInterface) PortableRemoteObject.narrow(objref, HelloInterface.class);

3. In sun-application-client.xml, you need to bind the ejb-ref-name to
the actual JNDI name of the EJB.
<sun-application-client>
<ejb-ref>
<ejb-ref-name>ejb/test1234/ConnectionTester</ejb-ref-name>
<jndi-name>Use Actual JNDI Name of the EJB</jndi-name>
</ejb-ref>
</sun-application-client>

It is the last step that varies from vendor to vendor.

With Java EE 5, the EJB look up code has been greatly simplified. Steps
1 & 2 can be replaced by the following single line of code:

/@javax.ejb.EJB(name="ejb/test1234/ConnectionTester") private static
HelloInterface hello;/

Take a look at Java EE 5 tutorials from Sun where you can find a lot of
portable applications.

Thanks,
Sahoo

Ryan wrote:
> Thanks for the reply weberjn. After a bit of discussion tonight we've
> decided to target Glassfish and deal with porting to another application
> server if it ever needs to be done.
>
> I felt like I was spending as much time ensuring our application was
> portable as I was doing actual work. Almost all of the books, tutorials
> and docs that I've seen tend to explain how to do things for a specific
> application server. I found it almost impossible to find Java EE
> examples that showed how to do things in a vendor independent manner.
>
> However, if anyone is aware of a sample EE application (.ear) that will
> run on multiple application servers without modification I'd still be
> interested in looking at it just for fun.
>
> Ryan
>
>
> glassfish@javadesktop.org wrote:
>
>> Did you try the RMI over IIOP way?
>>
>> From
>> http://java.sun.com/j2se/1.4.2/docs/guide/rmi-iiop/tutorial.html
>>
>>
>> // STEP 1: Get the Object reference from the Name Service
>> // using JNDI call.
>> objref = ic.lookup("HelloService");
>> System.out.println("Client: Obtained a ref. to Hello server.");
>>
>> // STEP 2: Narrow the object reference to the concrete type and
>> // invoke the method.
>> hi = (HelloInterface) PortableRemoteObject.narrow(
>> objref, HelloInterface.class);
>> hi.sayHello( " MARS " );
>> [Message sent by forum member 'weberjn' (weberjn)]
>>
>> http://forums.java.net/jive/thread.jspa?messageID=204935
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
>> For additional commands, e-mail: users-help@glassfish.dev.java.net
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net


Ryan
Re: Is there a vendor independent way of accessing EJBs from a standalone
Posted: Feb 23, 2007 3:24 PM   in response to: Sanjeeb Kumar S...
  Click to reply to this thread Reply

I didn't have a proper understanding of the XML configurations. Your
reply put it in perspective for me and I 'get it' now. Thank you very much.

Ryan

Sanjeeb Kumar Sahoo wrote:
> Ryan,
>
> It is not that difficult to write portable ear/jar/war/rar file. Don't
> be under the impression that a portable jar/war/war does not require
> any modification when you move from one platform to another. In fact,
> they may just have to be modified when you move from one installation to
> another while using the same software, but one must not have to change
> source code or standard deployment descriptors of a portable
> applications. Migration of portable applications should be possible by
> just configuring vendor specific deployment descriptors like
> sun-ejb-jar.xml, or sun-application-client.xml, etc.
>
> In your example below, a portable way to look up an EJB from an
> application client would be to:
>
> 1. In application-client.xml, declare a dependency on the EJB using
> <ejb-ref> entry. Give it a name. You have already done this:
>
> <ejb-ref>
> <ejb-ref-name>ejb/test1234/ConnectionTester</ejb-ref-name>
> <ejb-ref-type>Session</ejb-ref-type>
> <remote>domain.ejb.interfaces.ConnectionTesterRemote</remote>
> </ejb-ref>
>
>
> 2. In your code, look up in the java:comp/env/ namespace using the above
> name. So your code looks like:
>
> Object objref = new
> InitialContext().lookup("java:comp/env/ejb/test1234/ConnectionTester");
>
> HelloInterface hello = (HelloInterface)
> PortableRemoteObject.narrow(objref, HelloInterface.class);
>
> 3. In sun-application-client.xml, you need to bind the ejb-ref-name to
> the actual JNDI name of the EJB.
> <sun-application-client>
> <ejb-ref>
> <ejb-ref-name>ejb/test1234/ConnectionTester</ejb-ref-name>
> <jndi-name>Use Actual JNDI Name of the EJB</jndi-name>
> </ejb-ref>
> </sun-application-client>
>
> It is the last step that varies from vendor to vendor.
>
> With Java EE 5, the EJB look up code has been greatly simplified. Steps
> 1 & 2 can be replaced by the following single line of code:
>
> /@javax.ejb.EJB(name="ejb/test1234/ConnectionTester") private static
> HelloInterface hello;/
>
> Take a look at Java EE 5 tutorials from Sun where you can find a lot of
> portable applications.
>
> Thanks,
> Sahoo
>
> Ryan wrote:
>> Thanks for the reply weberjn. After a bit of discussion tonight we've
>> decided to target Glassfish and deal with porting to another application
>> server if it ever needs to be done.
>>
>> I felt like I was spending as much time ensuring our application was
>> portable as I was doing actual work. Almost all of the books, tutorials
>> and docs that I've seen tend to explain how to do things for a specific
>> application server. I found it almost impossible to find Java EE
>> examples that showed how to do things in a vendor independent manner.
>>
>> However, if anyone is aware of a sample EE application (.ear) that will
>> run on multiple application servers without modification I'd still be
>> interested in looking at it just for fun.
>>
>> Ryan
>>
>>
>> glassfish@javadesktop.org wrote:
>>
>>> Did you try the RMI over IIOP way?
>>>
>>> From
>>> http://java.sun.com/j2se/1.4.2/docs/guide/rmi-iiop/tutorial.html
>>>
>>> // STEP 1: Get the Object reference from the Name
>>> Service
>>> // using JNDI call.
>>> objref = ic.lookup("HelloService");
>>> System.out.println("Client: Obtained a ref. to Hello
>>> server.");
>>>
>>> // STEP 2: Narrow the object reference to the concrete type and
>>> // invoke the method.
>>> hi = (HelloInterface) PortableRemoteObject.narrow(
>>> objref, HelloInterface.class);
>>> hi.sayHello( " MARS " );
>>> [Message sent by forum member 'weberjn' (weberjn)]
>>>
>>> http://forums.java.net/jive/thread.jspa?messageID=204935
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
>>> For additional commands, e-mail: users-help@glassfish.dev.java.net
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
>> For additional commands, e-mail: users-help@glassfish.dev.java.net
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net





 XML java.net RSS