Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do I implement BOTH a local and a remote client view for a bean?

 
Jonny Andersson
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to page 157 in HF EJB can a bean have both a local and a remote view. Yes, It may be very unlikely that a real design require it, but if i want to try it just to know that it works and how to do it, or just for fun, how do I do it? Using the famous Advice bean example of course : )

I have already played with the naive ways to do it without success. I just created a EJBLocalHome and a EJBLocalObject interface together (in a parallell package) with the remote counterparts and deployed that in RI. I could also see that RI allows to define a bean with both local and remote interfaces, there is two drop downs for each of them. But the verifier did not test succesfully for the local interfaces, for one thing probably because the implementation methods in the bean class declares throw of RemoteException which the local interfaces does not (and not allows). And it did not work when I tried to execute a local client to it either, of course. But also, I guess I have to register the locla and remote home using different names in JNDI, to let the client have a chance to tell if it want the local or remote view, right? And I found some way it may be done in RI but am not sure I am right.

Instead of have to do trial and error to maybe get this to work, how should I do it? Please! : ) Is it correct that it should be possible to share the bean class and have two local and two remote interfaces and get it to work with both a local client and a remote client for that bean?
 
Michael Valentino
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I haven't used the Sun RI much, I typically use JBoss and Eclipse and XDoclet. But to answer your question, I've done this with a bean before. I think you're making it out to be a little tougher than it is. Follow the rules for creating a remote client view for the bean, and then a local client view for the bean. The bean should deploy just fine.

*editied original post* I just re-read your post, and your bean class should NEVER declare remote exceptions because you will never throw them, only the container will. Get the RemoteException out of the bean class, everything should be just fine.

Now, keep in mind you will only be able to access the remote client view from a stand alone program (i.e. the sample client). If you want to access advice bean from a local client view, you'll have to deploy another bean to access the advice bean locally.
[ May 31, 2006: Message edited by: Michael Valentino ]
 
Jonny Andersson
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aha, so I should only declare RemoteExceptions on interfaces? Because it is the container that may throw RemoteExceptions. That sounds reasonable, but I haven�t understood that before. With this change do I guess that I then should be able to at least share the bean class and so only have to create all the heavy business logic just once : )

I understand that I have to create a different client for local access of a bean because much is different from how a client for remote access of a bean works. But you say that I also has to deploy my bean as two separate EJBs? Using the same bean class but different interfaces for remote vs local access, am I right? Do you have to do this in JBoss? It LOOKS as it should be possible to deploy an EJB in RI with both local and remote interfaces, ther is at least drop downs to select interfaces for that. But then is the question how to separate the local interfaces from remote interfaces in JNDI? If someone know about RI regarding this am I curios : ) I will at least experiment a bit more on this, just for fun to see if I can get it to work.

Thank you very much for your answer, in was interesting and instructive!
 
Michael Valentino
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry if my post added more confusion Yes, you're correct. Only the remote interfaces should declare RemoteException. Never the bean class. Why? The BEAN isn't your remote object. You communicate with the bean through the EJBObject as it's proxy. As far as the bean is concerned all call to it are from the EJBObject which is local to the bean (meaning on the same heap). However, the container knows that you're dealing with remote objects (EJBObject is Remote) and so in it's "magic services" that go in between the EJBObject and the Bean, the container can see if things went horribly wrong and throw a RemoteException. Just think: Bean is never a remote object, only the EJBObject (the way to get TO the bean) is remote.

To answer your second question, no. You don't have to deploy the bean twice, but in your <session> tag that describes the bean, you have to have an entry for both the <home>, <remote> and <localhome>, <local> interfaces. Yes, you will need 2 different JNDI entries however... where you do that is dependent on what container/server you're using. For JBoss, there's a config file called jboss.xml which links your EJBs via the <ejb-name> you gave in ejb-jar.xml to the JNDI environment in JBoss. There's also another config file for mapping your persistence fields to database tables but we won't get into that for now. I don't know how the Sun RI does this, all I know is that it should take care of this for you via the GUI deploytool. For JBoss, if you want to have both a local and remote client view, in the jboss.xml file you have to have something like the following:



Hope that clears that up for you.
 
Jonny Andersson
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your answer. It was valuable to read it and after have removed all the exceptions from my bean class could I create and verify the advice bean in RI without any problems. Before did I get some errors during the verify step.

It sounds reasonable that the methods in the bean class shouldn�t declare the RemoteException. You have given convinceable arguments for that. And the bean class for the advice bean in HF EJB isn�t declaring RemoteExceptions either. But on the other hand, isn�t this statement
Only the remote interfaces should declare RemoteException. Never the bean class.

in conflict with the fact that my bean class has to implement for example the SessionBean interface that has declared the RemoteException on all its methods? I guess this is the reason to why I declared the exceptions in my first verison of the bean class earlier.

But I have realized that the real root to my problem actually is that I don�t know how to deploy with a separate JNDI name for the local home interface in RI. I have played with it without success and have instead get lost among all entries that is possible to enter of which most of them probably is beyond the scope of the SCBCD certification.

Because of lack of time do I stop here and is satisfied with what I learnt from your answers. But if anyone has sucessfully deployed the advice bean in RI with both local and remote interfaces and got it to work while executing a local and a remote client to it am I still very interested in a detailed description about which fields in the deploytool that was set and which values that were used. I guess it would not be that difficult for someone that know.
[ June 03, 2006: Message edited by: Jonny Andersson ]
 
Michael Valentino
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jonny Andersson:
[QB]
in conflict with the fact that my bean class has to implement for example the SessionBean interface that has declared the RemoteException on all its methods? I guess this is the reason to why I declared the exceptions in my first verison of the bean class earlier.
[QB]


To answer this question, keep in mind just because the interface declares that it throws the method does not mean that every implementation class of that method MUST throw the excetpion. This is not only java basics, but stressed heavily throughout the HF EJB book.

Sorry to hear you didn't have any luck with the RI. Have you tried JBoss? Time permitting to learn it, it's a great IDE to work with.

Good luck!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic