-
1. Re: migrate to jboss 7 - How to get the module name to impliment a dynamic lookup for global JNDI
jaikiran Feb 27, 2012 1:51 AM (in response to ablet)The module name is available in JNDI at java:app/ModuleName and the app name is available at java:global/AppName. So you can either look it up in your code or inject it as follows:
@Resource (lookup="java:app/ModuleName") private String moduleName; @Resource(lookup="java:global/AppName") private String appName;
-
2. Re: migrate to jboss 7 - How to get the module name to impliment a dynamic lookup for global JNDI
ablet Feb 27, 2012 10:59 AM (in response to jaikiran)Thanks for the fast reply, actually above code returns the module name of current service ejb while i need a way to lookup a service through ServiceLocator from a separted module (ejb-jar).
For instance i have an EJB which is located in: kern-core-ejb/UserServiceBean
It invokes Messaging Service which is located in: kern-messaging-ejb/MessagingService through ServiceLocator
MessagingService messagingService = (MessagingService) ServiceLocator.getInstance().locate(MessagingService.class);
In ServiceLocator I build the jndi naming and do the lookup.
If i include lookup in ServiceLocator with
lookup="
java:app/ModuleName
" it returns kern-core-ejb
while i need to look for kern-messaging-ejb. -
3. Re: migrate to jboss 7 - How to get the module name to impliment a dynamic lookup for global JNDI
ablet Feb 28, 2012 2:29 AM (in response to ablet)I wrote this code to get the module name and it works for me, It might be useful for someone in the same trouble.//To extract the module name (ejb-jar name) String moduleName = ""; try{ URL url = serviceInterface.class.getResource(""); String [] strArray = url.getPath().split("/"); for (int i=0; i<strArray.length; i++){ if (strArray[i].contains(".jar")){ moduleName = strArray[i].substring(0, strArray[i].length() - 4); System.out.println(moduleName); break; } } }catch(Exception ex){ ex.printStackTrace(); }
-
4. Re: migrate to jboss 7 - How to get the module name to impliment a dynamic lookup for global JNDI
jaikiran Feb 28, 2012 3:51 AM (in response to ablet)That won't work in many cases like:
1) The bean interface is packaged separately in a different jar than the bean implementation classes
2) The module name is overridden in the deployment descriptors.
-
5. Re: migrate to jboss 7 - How to get the module name to impliment a dynamic lookup for global JNDI
jdabrowski Mar 1, 2012 7:54 AM (in response to jaikiran)Joining the thread: I have quite similar situation but I call ejb from standalone client.
We've always used "NameOfTheBean/remote" to find remote interface in JNDI.
In standalone client I don't have any chance to get the name of the module.
Is there any chance to add some configuration to reject module names during JNDI binding to ejb: ? Maybe in jboss-app.xml?
-
6. Re: migrate to jboss 7 - How to get the module name to impliment a dynamic lookup for global JNDI
ablet Mar 1, 2012 9:00 PM (in response to jdabrowski)jaikiran pai, Yes,You are right, we need a more comprehensive solution for that.. so I deactivated the Correct Answer status from my post.
-
7. Re: migrate to jboss 7 - How to get the module name to impliment a dynamic lookup for global JNDI
ablet Mar 6, 2012 4:22 AM (in response to jdabrowski)Jacek, I did also had the similar need of dynamic remote call on my client side. I just used the follworing method (taken from http://illegalargumentexception.blogspot.com/2008/04/java-finding-application-directory.html) to return the URL and then extracted the module name from that... it's not a clean and comprehensive aproach, but it works for me:
// Returns the URL of a given class. public static URL getUrlOfClass(Class c) { if (c == null) { throw new NullPointerException(); } String className = c.getName(); String resourceName = className.replace('.', '/') + ".class"; ClassLoader classLoader = c.getClassLoader(); if (classLoader == null) { classLoader = ClassLoader.getSystemClassLoader(); } URL url = classLoader.getResource(resourceName); return url; }
-
8. Re: migrate to jboss 7 - How to get the module name to impliment a dynamic lookup for global JNDI
jdabrowski Mar 6, 2012 11:39 AM (in response to ablet)On client side I don't even have Bean class - just bean name and remote interface.
So no chance for module name...
-
9. Re: migrate to jboss 7 - How to get the module name to impliment a dynamic lookup for global JNDI
ablet Mar 6, 2012 11:21 PM (in response to jdabrowski)Isn't this an important requirement/issue that need to be addressed in the next releases? Dynamic remote call might be used in many projects in enterprise level.
-
10. Re: migrate to jboss 7 - How to get the module name to impliment a dynamic lookup for global JNDI
jdabrowski Mar 8, 2012 1:33 AM (in response to ablet)For me (and probably for many developers) it is critical and there is no workaround.
No chance to migrate from older JBoss without this.