0 Replies Latest reply on Mar 21, 2012 10:52 AM by ejroberts

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

    ejroberts

      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

      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 );