Skip to main content

Portable JNDI names in EJB3.1 in an enterprise app

7 replies [Last post]
benupsavs
Offline
Joined: 2005-12-17
Points: 0

Hello,

I am trying to specify an application name for my Java EE 6 .ear project using the instructions here: http://glassfish.java.net/javaee5/ejb/EJB_FAQ.html#What_is_the_syntax_fo...

The problem is that the instructions are wrong. It says you can have an app-name element inside your application.xml file, and that's not part of the schema, so it fails to deploy if that's present. So, I noticed there was an application-name in the schema. The problem is, that it doesn't work. The portable JNDI name for session beans remains as the default, which is the unqualified name of the application, minus the extension. The module-name part for the ejb tier does work, but it is the application-name part of the main ear that doesn't work, so I am getting portable names like the following: java:global/com.example.test-ear_ear_1.0.0-SNAPSHOT/test-ejb/TestBean

Notice that the second part of the name inside the slashes (test-ejb) is correct, however the first part is using the entire name of the file, including the version number.

Hopefully someone has an easy solution for specifying the application name part of the portable JNDI name, using either application.xml or annotations somewhere. I can delete application.xml if need be, since it's only there to specify the name which isn't working anyway.

Regards,
Ben

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
cf126330
Offline
Joined: 2005-03-29
Points: 0

Please attach your test app, including src, especially application.xml. Our tests for this case are passing.

benupsavs
Offline
Joined: 2005-12-17
Points: 0

Here it is, although I need to clarify something I just tested. The problem doesn't occur if I upload using the Glassfish admin gui. I am only able to reproduce it by performing a directory deployment in NetBeans. So if you open all of the projects into NetBeans 7.0, and run the test-ear project in Glassfish 3.1, the behavior of the portable name is incorrect, even though the application.xml file has the application-name element.

I have no idea why directory deployment would change things, but the thing to take note of is that the ejb (module) part of the portable jndi name is correct and the ear (application) part of it is incorrect.

Thanks and regards,
Ben

cf126330
Offline
Joined: 2005-03-29
Points: 0

I built the project in NB and it looks fine. Can you check the actual asadmin command NB runs to deploy the EAR. Did NB explicitly pass a --name param to override the <application-name>?

benupsavs
Offline
Joined: 2005-12-17
Points: 0

Also I just wanted to add that if you run the ear project from NetBeans, it will deploy to the Glassfish 3.1 instance that was registered when NetBeans was installed, so it's easy to test this behavior. Also, Glassfish will display the portable JNDI name it's using for the test bean, in the output window. Maybe you'll have more luck than me figuring out what NetBeans is doing, if you want to try it.

benupsavs
Offline
Joined: 2005-12-17
Points: 0

Sorry, I don't know how NetBeans does its deployment. I have been trying to figure that out. For Maven projects it looks like it creates a gfdeploy directory inside the target directory of the ear project and it somehow does a directory deployment.

I did find a couple of posts online which suggests NetBeans does a GET request to Glassfish's admin port using deploy?path=<path>&force=true but I'm not 100% sure. Would that cause this problem?

Thanks for letting me know about the --name option. Maybe this is more of a NetBeans issue and I should just accept that the module name could be anything, so I should look up the module name in code to get the portable name of the beans.

cf126330
Offline
Joined: 2005-03-29
Points: 0

Please file a GlassFish issue.
I was able to reproduce it in NB 7. After deployment, domain.xml contains the following (note the name attr value is the same as the default appName):
<application location="file:/Users/cf126330/tmp/renamed/test/test-ear/target/gfdeploy/com.example_test-ear_ear_1.0-SNAPSHOT/" name="com.example_test-ear_ear_1.0-SNAPSHOT" directory-deployed="true" object-type="user">
<property name="appLocation" value="file:/Users/cf126330/tmp/renamed/test/test-ear/target/gfdeploy/com.example_test-ear_ear_1.0-SNAPSHOT/"></property>
<property name="org.glassfish.ejb.container.application_unique_id" value="85658066449334272"></property>
<property name="isComposite" value="true"></property>
<property name="defaultAppName" value="com.example_test-ear_ear_1.0-SNAPSHOT"></property>
<engine sniffer="ear"></engine>
<module name="test-ejb-1.0-SNAPSHOT.jar">
<engine sniffer="ejb"></engine>
<engine sniffer="security"></engine>
</module>
<module name="test-web-1.0-SNAPSHOT.war">
<engine sniffer="security"></engine>
<engine sniffer="web"></engine>
</module>
</application>
The generated application.xml contains the correct appName, which suggests the correct application.xml was processed, but somehow in this particular path, it's ignored when registering the app.
But when I run 'asadmin deploy .' in test-ear/target/gfdeploy/com.example_test-ear_ear_1.0-SNAPSHOT, to do a directory deploy, it works fine.

benupsavs
Offline
Joined: 2005-12-17
Points: 0

Thanks very much for all of your help. I created this bug: http://java.net/jira/browse/GLASSFISH-16793