8

I use EJB inside OSGi bundles. And now when I need to get EJB I have long jndi, for example:

bean = (InterfaceName) ctx.lookup("java:global/longBundleName_version/OrganizationDirBean!and.plus.path.and.InterfaceName");

I want to change this part:

longBundleName_version

I mean, when I deploy bundle this part must be set from [glassfish-]application.xml or from [glassfish-]-ejb-jar.xml or from any other xml descriptor. I want jndi name for my ejb to be like:

java:global/newBundleNameWithoutVersion/etc

The problem that I can't find what I must set in these files. All variants I found in internet are not supported anymore and all I tried myself didn't work. Could you help me?

Please, don't offer mappedName as it can be used only(!) for remote beans. I do use beans which are at the same time both local and remote.

If someone is involved in glassfish development, could you at least point what bundles I must examine to find the question by myself? I will be very grateful.

Community
  • 1
  • 1
  • 1
    Glassfish is open source, no? Why not read the relevant code to find out if or how it is possible? – bmargulies Jul 18 '14 at 22:08
  • @bmargulies Thank you for idea! I'll try, although I think it won't be so easy taking into consideration it consists a lot of code and I never worked with its code. And to tell the truth, I'm afraid I don't have experience enough. –  Jul 18 '14 at 22:39

1 Answers1

3

You should annotate your EJB like that:

@Remote(value = YourInterface.class)
@Stateless(mappedName = "java:global/fancy")

After that, GF logs says:

EJB5182:Glassfish-specific (Non-portable) JNDI names for EJB YourInterfaceImpl: [java:global/fancy, java:global/fancy!com.example.YourInterface]]]

And at least I was able to inject like:

<!-- language:java -->

@EJB(lookup="java:global/fancy")

So I think manual look up should also work.

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
win_wave
  • 1,498
  • 11
  • 9
  • Thank you for your time. The problem is that what you offer is not portable JNDI name. And the second problem is that mappedName is used only for remote beans, but I have both local and remote. –  Jun 20 '14 at 04:03
  • Then probably it is not possible. If it would be possible, and you will deploy twice your application, which of the resources will be mapped to your custom JNDI? – win_wave Jun 20 '14 at 08:24
  • That's possible. See the link I provided. –  Jun 20 '14 at 11:48