2 Replies Latest reply on Jan 11, 2016 10:36 AM by Hristo Stoyanov

    [WF.9.0.2.Final] JNDI issues - accessing simple global binding

    Hristo Stoyanov Master

      Hi all,

      I have issues reading globally configured JNDI values in WF902:

       

      I have configured my WF902 instance to have a simple JNDI binding via the standalone.xml file like this:

      ....

      <subsystem xmlns="urn:jboss:domain:naming:2.0">

                  <bindings>

                      <simple name="java:global/ga" value="true" type="String"/>

                  </bindings>

                  <remote-naming/>

      </subsystem>

      ....

       

       

      In my web app, I am trying to look up  the value in a JSP like this:

      ...

      <%

              String ga = null;

              try{

                  ga = javax.naming.InitialContext.doLookup("java:global/ga");

              }catch(javax.naming.NameNotFoundException e){}

              ...

      %>

       

      which is not working - i am going in the empty catch clause.

      Further, I tried to see value in the WF902 management console, and although "java:global/ga" shows up under "/subsystem=naming/binding=java:global/ga", there is no Data or anything else associated with it.

       

      What am I doing wrong?


      I followed the examples outlined here:

      JNDI Reference - WildFly 8 - Project Documentation Editor

        • 1. Re: [WF.9.0.2.Final] JNDI issues - accessing simple global binding
          Jay SenSharma Master

          You need to change it as following:  [ type="String"    => type="java.lang.String" ]

           

           

                  <subsystem xmlns="urn:jboss:domain:naming:2.0">
                      <bindings>
                          <simple name="java:global/ga" value="true" type="java.lang.String"/>
                      </bindings>
                      <remote-naming/>
                  </subsystem>
          
          
          

           

          CLI Output:

          [standalone@localhost:9990 /] /subsystem=naming/binding=java\:global\/ga:read-attribute(name=type)
          {
              "outcome" => "success",
              "result" => "java.lang.String"
          }
          
          [standalone@localhost:9990 /] /subsystem=naming/binding=java\:global\/ga:read-attribute(name=value)
          {
              "outcome" => "success",
              "result" => "true"
          }
          
          [standalone@localhost:9990 /] /subsystem=naming/binding=java\:global\/ga:read-resource(recursive=true)
          {
              "outcome" => "success",
              "result" => {
                  "binding-type" => "simple",
                  "cache" => undefined,
                  "class" => undefined,
                  "environment" => undefined,
                  "lookup" => undefined,
                  "module" => undefined,
                  "type" => "java.lang.String",
                  "value" => "true"
              }
          }
          
          

           

           

           

          My JSP is as following:

           

          <h1>Hello World!!!</h1>
          <%
                  //To disable Google Analytics, configure a JNDI property, or use: http://localhost:8080/s4gwebapp/index.jsp?ga=false#StartPage   
                  String ga = null;
                  try{
                      ga = javax.naming.InitialContext.doLookup("java:global/ga");
                  }catch(javax.naming.NameNotFoundException e){}
          
                  if ("false".equals(ga)) {
                      out.println("Yahoooo! ga = " + ga);
                  } else {
                      out.println("Wqqqqqq! ga = " + ga);      
                  }
          %>
          
          
          

           

           

          The Output i received is as following when accessing the application:

           

          Hello World!!!

          Wqqqqqq! ga = true

           

           

          Regards

          Jay SenSharma