1 2 Previous Next 25 Replies Latest reply on Dec 12, 2012 10:41 AM by pmm

    JBoss7 JNDI

    pushpak1981

      Can i bind my custom objects in JBoss7.1b using InitialContext.bind?

       

      I found a link where it mentions that this is not supported in JBoss7.1b yet.

       

      https://issues.jboss.org/browse/AS7-2755?focusedCommentId=12645181&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-12645181

       

      Does anyone any idea how can so this?

        • 1. Re: JBoss7 JNDI
          wolfc

          Either add an ObjectFactory to the naming subsystem:

          <subsystem xmlns="urn:jboss:domain:naming:1.1">
              <bindings>
                  <object-factory name="java:/custom/dog" module="org.jboss.animalshelter" class="org.jboss.animalshelter.resource.DogFactory"/>
              </bindings>
          </subsystem>
          

          or look through the example mention on:

          https://docs.jboss.org/author/display/AS7/Creating+Programatic+JNDI+Bindings

          • 2. Re: JBoss7 JNDI
            pushpak1981

            thanks for the reply.

             

            In our application the Object is initialized and then it is binded into JNDI.

             

            In first case if i make an entry into subsystem is it possible to rebind it through our code ?

            • 3. Re: JBoss7 JNDI
              dastraub

              The first solution mixes server and application configuration, the second requires the usage of a propritary API including there dependencies and so on.

              And all this for a simple "context.bind(....)" what is possible with other application servers ?

              So it's a little bit hard to develop portable code if you have the requirement to support different customer/server.

              • 4. Re: JBoss7 JNDI
                pushpak1981

                Thanks for the reply. So there is no way we can bind the Object into JNDI using context.bind(...). Except using the propritary API. But in that case it will be specific to Jboss only.

                 

                Are they planning to support this functionality in near future ?

                • 5. Re: JBoss7 JNDI
                  jaikiran

                  I just discussed this over #jboss-as7 IRC. Apparently the ability to bind to JNDI from application code has been supported in 7.1.0.CR1. If you are running into issues, please post the exact code you use to bind the entries, the jndi name(s) you use and also let us know when and where this binding happens.

                  • 6. Re: JBoss7 JNDI
                    pushpak1981

                    Thanks for the reply.

                     

                    I tried to deploy the code in JBoss 7.1 CR1b but we are facing the same issue. Below is the code snapshot which tried the bind (java:/ProcessEngine, java:/applications/ProcessEngine) into JNDI.

                     

                    InitialContext initialContext = new InitialContext();

                    initialContext.bind(jndiName, this);

                     

                    Caused by: java.lang.UnsupportedOperationException: JBAS011859: Naming context is read-only

                            at org.jboss.as.naming.WritableServiceBasedNamingStore.requireOwner(WritableServiceBasedNamingStore.java:118)

                            at org.jboss.as.naming.WritableServiceBasedNamingStore.bind(WritableServiceBasedNamingStore.java:53)

                            at org.jboss.as.naming.NamingContext.bind(NamingContext.java:220)

                            at org.jboss.as.naming.InitialContext.bind(InitialContext.java:135)

                            at org.jboss.as.naming.NamingContext.bind(NamingContext.java:229)

                            at javax.naming.InitialContext.bind(InitialContext.java:400) [:1.6.0_03]

                            at org.jbpm.pvm.internal.processengine.ProcessEngineImpl.initializeProcessEngine(ProcessEngineImpl.java:142)

                            at org.jbpm.pvm.internal.processengine.ProcessEngineImpl.<init>(ProcessEngineImpl.java:104)

                            at org.jbpm.pvm.internal.cfg.ConfigurationImpl.instantiateProcessEngine(ConfigurationImpl.java:100)

                            at org.jbpm.pvm.internal.cfg.ConfigurationImpl.buildProcessEngine(ConfigurationImpl.java:92)

                            at org.jbpm.api.Configuration.getProcessEngine(Configuration.java:126)

                            at org.jbpm.jboss.internal.JbpmService.start(JbpmService.java:39)

                     

                     

                    We are deploying this as a JBoss POJO Service(SAR). We have configured a jboss-beans.xml file which loads the POJO during the server startup and the POJO binds ProcessEngine Object into JNDI.

                     

                    What are the other JNDI contexts in which we can bind our custom objects ?

                     

                    I tried to lookup for JNDI Tree view for JBoss7.1CR1 below is the output.

                     

                    [standalone@localhost:9999 /] /subsystem=naming:jndi-view

                    {

                        "outcome" => "success",

                        "result" => {

                            "java: contexts" => {

                                "java:" => {

                                    "TransactionManager" => {

                                        "class-name" => "com.arjuna.ats.jbossatx.jta.TransactionManagerDelegate",

                                        "value" => "com.arjuna.ats.jbossatx.jta.TransactionManagerDelegate@434887"

                                    },

                                    "jboss" => {

                                        "class-name" => "javax.naming.Context",

                                        "value" => "org.jboss.as.naming.WritableServiceBasedNamingStore@14e983a"

                                    }

                                },

                                "java:jboss" => {

                                    "TransactionManager" => {

                                        "class-name" => "com.arjuna.ats.jbossatx.jta.TransactionManagerDelegate",

                                        "value" => "com.arjuna.ats.jbossatx.jta.TransactionManagerDelegate@434887"

                                    },

                                    "TransactionSynchronizationRegistry" => {

                                        "class-name" => "com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionSynchronizationRegistryImple",

                                        "value" => "com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionSynchronizationRegistryImple@1fc765b"

                                    },

                                    "UserTransaction" => {

                                        "class-name" => "com.arjuna.ats.internal.jta.transaction.arjunacore.UserTransactionImple",

                                        "value" => "Transaction: unknown"

                                    },

                                    "jaas" => {

                                        "class-name" => "$Proxy9",

                                        "children" => {

                                            "jboss-ejb-policy" => {

                                                "class-name" => "org.jboss.as.security.plugins.SecurityDomainContext",

                                                "value" => "org.jboss.security.authentication.JBossCachedAuthenticationManager@1be5475"

                                            },

                                            "other" => {

                                                "class-name" => "org.jboss.as.security.plugins.SecurityDomainContext",

                                                "value" => "org.jboss.security.authentication.JBossCachedAuthenticationManager@9af639"

                                            },

                                            "jboss-web-policy" => {

                                                "class-name" => "org.jboss.as.security.plugins.SecurityDomainContext",

                                                "value" => "org.jboss.security.authentication.JBossCachedAuthenticationManager@19b45a1"

                                            }

                                        }

                                    },

                                    "mail" => {

                                        "class-name" => "javax.naming.Context",

                                        "children" => {"Default" => {

                                            "class-name" => "javax.mail.Session",

                                            "value" => "javax.mail.Session@8c53f9"

                                        }}

                                    },

                                    "datasources" => {

                                        "class-name" => "javax.naming.Context",

                                        "children" => {

                                            "ExampleDS" => {

                                                "class-name" => "org.jboss.jca.adapters.jdbc.WrapperDataSource",

                                                "value" => "org.jboss.jca.adapters.jdbc.WrapperDataSource@dd08eb"

                                            },

                                            "JbpmDS" => {

                                                "class-name" => "org.jboss.jca.adapters.jdbc.WrapperDataSource",

                                                "value" => "org.jboss.jca.adapters.jdbc.WrapperDataSource@174b423"

                                            }

                                        }

                                    }

                                },

                                "java:global" => undefined

                            },

                            "applications" => undefined

                        }

                    }

                    • 7. Re: JBoss7 JNDI
                      pushpak1981

                      Does anyone have any idea whether we can bind custom objects into JNDI using InitialContext.bind () . I read in some thread  that we can do it by creating a custom binding service. I wanted some information on how we can write a custon binding service?

                      • 8. Re: JBoss7 JNDI
                        jaikiran

                        We are deploying this as a JBoss POJO Service(SAR). We have configured a jboss-beans.xml file which loads the POJO during the server startup and the POJO binds ProcessEngine Object into JNDI.

                        If you want to be able to bind to JNDI without using any JBoss specific classes, then you'll have to move the bind logic to some Java EE component (for example a ServletContextListener which can bind when the web application is deployed). If you can't do that, then you'll need to add a few more lines of code to use JBoss specific classes to be able to successfully bind from non Java EE components. I don't have the code right now, but it's available in one of the JNDI related JIRAs.

                        • 9. Re: JBoss7 JNDI
                          pushpak1981

                          Thanks for the reply. Are you mentioning about the link mentioned above for programatic bindings.

                           

                          https://docs.jboss.org/author/display/AS7/Creating+Programatic+JNDI+Bindings

                          • 10. Re: JBoss7 JNDI
                            jaikiran

                            I actually meant this comment in the JIRA https://issues.jboss.org/browse/AS7-2667?focusedCommentId=12654355&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-12654355. But to add that code, you would have to be in the context of a MSC service which isn't applicable in your case.

                             

                            To be sure, you can't refactor that code to initiliaze and bind from a ServletContextListener instead of having a POJO within a SAR?

                            • 11. Re: JBoss7 JNDI
                              pushpak1981

                              thanks for the quick response. the We can refactor the binding code. But instead of ServletContextListener can we do it inside any singleton EJB and get its context ?

                               

                              In the code :

                              WritableServiceBasedNamingStore.pushOwner(context.getChildTarget());

                                  try {

                                  jmsManager.createConnectionFactory(false, configuration, configuration.getBindings());

                                  } finally {

                                  WritableServiceBasedNamingStore.popOwner();

                                  }

                               

                              what does "context.getChildTarget()" means ?

                               

                              Can you please provide sample code for Servlet and EJB if possible ? It would be really helpful.

                              • 12. Re: JBoss7 JNDI
                                jaikiran

                                pushpak1981 wrote:

                                 

                                thanks for the quick response. the We can refactor the binding code. But instead of ServletContextListener can we do it inside any singleton EJB

                                 

                                Yes, starting 7.1.0.CR1 that should be possible.

                                 

                                 

                                pushpak1981 wrote:

                                 

                                and get its context ?

                                 

                                In the code :

                                WritableServiceBasedNamingStore.pushOwner(context.getChildTarget());

                                    try {

                                    jmsManager.createConnectionFactory(false, configuration, configuration.getBindings());

                                    } finally {

                                    WritableServiceBasedNamingStore.popOwner();

                                    }

                                 

                                what does "context.getChildTarget()" means ?

                                 

                                Can you please provide sample code for Servlet and EJB if possible ? It would be really helpful.

                                You don't need any of that if you are doing it in a EJB or a servlet (starting 7.1.0.CR1). Just do:

                                 

                                new InitialContext().bind("java:/name", value); // just an example.

                                • 13. Re: JBoss7 JNDI
                                  pushpak1981

                                  Thanks a lot jaikiran. It worked with Jboss7.1 CR1. Out of curiosity i wanted to know what is difference when i try binding Objects from Simple POJO and EE components and how does it makes a difference.

                                   

                                  Previously you mentioned:

                                  I actually meant this comment in the JIRA https://issues.jboss.org/browse/AS7-2667?focusedCommentId=12654355&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-12654355. But to add that code, you would have to be in the context of a MSC service which isn't applicable in your case.

                                  I wanted to know "context of MSC means" ?

                                   

                                  thanks again.

                                  • 14. Re: JBoss7 JNDI
                                    jaikiran

                                    pushpak1981 wrote:

                                     

                                    Thanks a lot jaikiran. It worked with Jboss7.1 CR1.

                                    Good to know!

                                     

                                     

                                    pushpak1981 wrote:

                                     

                                    Out of curiosity i wanted to know what is difference when i try binding Objects from Simple POJO and EE components and how does it makes a difference.

                                    If it's a EE component, then the application server has the hooks to run the server interceptor code at the right time to setup the relevant infrastructure for allowing services like this. Unlike in the case of random POJOs whose lifecycle and execution context isn't controlled by the server and hence it wouldn't be able to setup the relevant information.

                                     

                                     

                                    pushpak1981 wrote:

                                     

                                     

                                     

                                    Previously you mentioned:

                                    I actually meant this comment in the JIRA https://issues.jboss.org/browse/AS7-2667?focusedCommentId=12654355&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-12654355. But to add that code, you would have to be in the context of a MSC service which isn't applicable in your case.

                                    I wanted to know "context of MSC means" ?

                                     

                                     

                                    MSC stands for JBoss Modular Service Container and is the backbone of AS7 (http://in.relation.to/Bloggers/WhyIsJBossAS7SoFast). It allows the server to install server specific services to enable EE capability and other services in AS7. What I meant by "context of MSC" was that you would have to write that code in a MSC service (which is usually an advanced thing to do for normal EE applications).

                                    1 2 Previous Next