Discussion:
[jboss-user] [JNDI and Naming] - Use plain @EJB for remote EJB lookup?
Mikal Henriksen
2013-05-30 09:35:11 UTC
Permalink
Mikal Henriksen [https://community.jboss.org/people/stylpe] created the discussion

"Use plain @EJB for remote EJB lookup?"

To view the discussion, visit: https://community.jboss.org/message/820321#820321

--------------------------------------------------------------
I've been using the guide at https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+server+instance https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+server+instance to make a standalone war that uses beans that are deployed in an ear running on a separate AS. I got it working by using an explicit lookup name in the @EJB annotation, like this:

@EJB(lookup = "ejb:earname/modulename/BeanClass!fully.qualified.RemoteInterface")
private RemoteInterface bean;

Writing this for all the remote EJBs is getting tedious, and refactoring with it is even worse. Is there a way to tell the default context which app name and module name to use, so that I can use plain @EJB annotations without parameters?

I know I could create a helper class and use InitialContext.lookup, or alias each bean I plan to use in xml (I forget which one), but I want to be sure there isn't an easier, cleaner way to do this.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/820321#820321]

Start a new discussion in JNDI and Naming at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2083]
jaikiran pai
2013-05-30 09:52:26 UTC
Permalink
jaikiran pai [https://community.jboss.org/people/jaikiran] created the discussion

"Re: Use plain @EJB for remote EJB lookup?"

To view the discussion, visit: https://community.jboss.org/message/820335#820335

--------------------------------------------------------------
Mikal, welcome to the forums.
Post by Mikal Henriksen
@EJB(lookup = "ejb:earname/modulename/BeanClass!fully.qualified.RemoteInterface")
private RemoteInterface bean;
The server cannot guess what the appname, module name and bean name would be for that target bean (which resides on a different server) to be. It's the user's application which has that idea. One way to reduce the tediouness is to use the ejb-jar.xml to set up the injection (ejb-jar xsd has the necessary details) such that you can then use something like this in the ejb-jar.xml:

<lookup-name>${myfoo.bar.system.property}</lookup-name>


and set the system property (typically by passing -D<system-property-name>=<system-property-value>) while launching the server. Note that the system property replacement in deployment descriptors is a JBoss application server specific features and may not be portable across different server vendors.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/820335#820335]

Start a new discussion in JNDI and Naming at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2083]
Mikal Henriksen
2013-05-30 12:33:58 UTC
Permalink
Mikal Henriksen [https://community.jboss.org/people/stylpe] created the discussion

"Re: Use plain @EJB for remote EJB lookup?"

To view the discussion, visit: https://community.jboss.org/message/820393#820393

--------------------------------------------------------------
Thanks for the quick reply!
Post by jaikiran pai
The server cannot guess what the appname, module name and bean name would be for that target bean (which resides on a different server) to be. It's the user's application which has that idea.
I know it can't guess the appname and module name, that's what I wanted to know if I could configure somewhere. I guess my idea is that I should be able to tell the web app "Hey, use this server, this appname and this module name for ejb lookups," and the servers figure out the rest from there.

But your answer made me realize that we also need to know the name for the implementing class, since that's part of every standard jndi name. Thinking about it, it seems weird that the client should have to know about the name of the server-side class implementing the interface (the exception is of course multiple implementations of the same interface).

Is this just a limitation of jndi and remote ejb? Other than mapping these session beans to custom, shorter jndi names, is there no simpler way to accomplish something like this?
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/820393#820393]

Start a new discussion in JNDI and Naming at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2083]
jaikiran pai
2013-05-30 12:45:32 UTC
Permalink
jaikiran pai [https://community.jboss.org/people/jaikiran] created the discussion

"Re: Use plain @EJB for remote EJB lookup?"

To view the discussion, visit: https://community.jboss.org/message/820396#820396

--------------------------------------------------------------
Post by Mikal Henriksen
But your answer made me realize that we also need to know the name for the implementing class, since that's part of every standard jndi name. Thinking about it, it seems weird that the client should have to know about the name of the server-side class implementing the interface (the exception is of course multiple implementations of the same interface).
You don't need to know the class name of the implementing bean class. That's just a default that gets used. i.e. the bean name defaults to the simple class name of the implementing class. It can always be overriden using the +name+ attribute of the appropriate annotation (@Stateless, @Stateful, @Singleton) or via the +ejb-name+ element of ejb-jar.xml.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/820396#820396]

Start a new discussion in JNDI and Naming at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2083]
Mikal Henriksen
2013-05-31 06:10:21 UTC
Permalink
Mikal Henriksen [https://community.jboss.org/people/stylpe] created the discussion

"Re: Use plain @EJB for remote EJB lookup?"

To view the discussion, visit: https://community.jboss.org/message/820571#820571

--------------------------------------------------------------
Post by Mikal Henriksen
But your answer made me realize that we also need to know the name for the implementing class, since that's part of every standard jndi name. Thinking about it, it seems weird that the client should have to know about the name of the server-side class implementing the interface (the exception is of course multiple implementations of the same interface).
I've done some more research, and I guess what it boils down to is that the client needs to know that name (whether default or custom); the interface alone plus the connection to the server is not enough to lookup and connect to the remote implementation.

Are there other approaches I can use to streamline this? Is this something domain deployment would help with?
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/820571#820571]

Start a new discussion in JNDI and Naming at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2083]
jaikiran pai
2013-05-31 06:21:14 UTC
Permalink
jaikiran pai [https://community.jboss.org/people/jaikiran] created the discussion

"Re: Use plain @EJB for remote EJB lookup?"

To view the discussion, visit: https://community.jboss.org/message/820573#820573

--------------------------------------------------------------
Post by Mikal Henriksen
I've done some more research, and I guess what it boils down to is that the client needs to know that name (whether default or custom); the interface alone plus the connection to the server is not enough to lookup and connect to the remote implementation.
Of course it has to know the name of the bean it is trying to communicate with. A remote interface can be implemented by multiple beans. So it's upto the client to tell the server which bean it is interested in communicating with.
Post by Mikal Henriksen
Are there other approaches I can use to streamline this? Is this something domain deployment would help with?
Why are you trying to avoid the bean name usage?
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/820573#820573]

Start a new discussion in JNDI and Naming at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2083]
Mikal Henriksen
2013-05-31 07:57:56 UTC
Permalink
Mikal Henriksen [https://community.jboss.org/people/stylpe] created the discussion

"Re: Use plain @EJB for remote EJB lookup?"

To view the discussion, visit: https://community.jboss.org/message/820619#820619

--------------------------------------------------------------
Okay, so while reading through the EJB 3.0 spec, I've realized that dependency injection and jndi lookup are independent concepts, and I've been researching the wrong concept :p So we've more or less been talking past each other the whole time. Sorry about that.

The actual question I'm trying to answer is: Is there a way to do *dependency injection* cross-server? Essentially binding my client war to the server's context. I don't know if this involves jndi naming in any way, so it probably belongs in one of the other subforums, right?
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/820619#820619]

Start a new discussion in JNDI and Naming at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2083]
Loading...