[jboss-user] [JNDI and Naming] - How to bind objects to the java:jboss/exported from OSGI code

Ed Roberts do-not-reply at jboss.com
Wed Mar 21 10:52:58 EDT 2012


Ed Roberts [https://community.jboss.org/people/ejroberts] created the discussion

"How to bind objects to the java:jboss/exported from OSGI code"

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

--------------------------------------------------------------
Hi, 

I'm migrating some code currently working when deployed in JBoss AS 5.1.0 to 7.1.1

I have converted what was originally a SAR based deployment to an OSGI bundle deployment.
A service which was originally started by an MBean, is now registered as an OSGI Service via a Spring DM xml file.
I can see this mechanism works fine in JBoss 7.1.1.Final. 

However, the service attempts to bind a remotely accessible object into the JNDI registry. I changed the JNDI name
to reflect what I had seen in documentation. However, the binding bit is failing and I cannot find any documentation with any OSGI based 
code snippets to follow.

The JNDI name I want to bind to at the moment is java:jboss/exported/A/B##/C, and the code the service uses to do this is like this
When I run the AS server, I get the following exception thrown out:

Caused by: java.lang.UnsupportedOperationException: JBAS011859: Naming context is read-only
        at org.jboss.as.naming.WritableServiceBasedNamingStore.requireOwner(WritableServiceBasedNamingStore.java:126)
        at org.jboss.as.naming.WritableServiceBasedNamingStore.bind(WritableServiceBasedNamingStore.java:56)
        at org.jboss.as.naming.NamingContext.bind(NamingContext.java:221)
        at org.jboss.as.naming.InitialContext.bind(InitialContext.java:172)
        at javax.naming.InitialContext.bind(InitialContext.java:404)

I have seen references  https://issues.jboss.org/browse/AS7-2667?focusedCommentId=12654355&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel https://issues.jboss.org/browse/AS7-2667?focusedCommentId=12654355&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel
from February suggesting that in a non-EE component you need to use the following code:

WritableServiceBasedNamingStore.pushOwner(context.getChildTarget());
    try {
    jmsManager.createConnectionFactory(false, configuration, configuration.getBindings());
    } finally {
    WritableServiceBasedNamingStore.popOwner();
    }

Is there an OSGI way of cracking this ? I would prefer not to have to reference JBoss specific code to bind into JNDI. 
However, If that is the only working solution, then what exactly is the context object in this example, and how do I get hold of one within the OSGI environment.



InitialContext ctx = bundleContext.getService( bundleContext.getServiceReference(InitialContext.class.getName()) );
Name name = ctx.getNameParser("").parse( "java:jboss/exported/A/B/C" );
 
ctx.bind( name, myObject );
--------------------------------------------------------------

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

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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20120321/6fd5a050/attachment.html 


More information about the jboss-user mailing list