2 Replies Latest reply on Aug 15, 2013 9:32 AM by Yaguo Zhou

    Let use-java-context make sense

    Yaguo Zhou Newbie

      Hi, all

        I am using JBoss AS 7.2.0.Final.

       

      When i set datasource jndi-name just like below(withtout java:/ or java:jboss/ prefiex)

      <subsystem xmlns="urn:jboss:domain:datasources:1.1">

                  <datasources>

                      <datasource jndi-name="pocDS" pool-name="db2DS_ocsdb2" enabled="true" use-java-context="false">

         I got error message:

      19:46:01,123 ERROR [org.jboss.as.server] (Controller Boot Thread) JBAS015956: Caught exception during boot: org.jboss.as.controller.persistence.ConfigurationPersistenceException: JBAS014676: Failed to parse configuration

                at org.jboss.as.controller.persistence.XmlConfigurationPersister.load(XmlConfigurationPersister.java:141) [jboss-as-controller-7.2.0.Final.jar:7.2.0.Final]

                at org.jboss.as.server.ServerService.boot(ServerService.java:308) [jboss-as-server-7.2.0.Final.jar:7.2.0.Final]

                at org.jboss.as.controller.AbstractControllerService$1.run(AbstractControllerService.java:188) [jboss-as-controller-7.2.0.Final.jar:7.2.0.Final]

                at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_38]

      Caused by: javax.xml.stream.XMLStreamException: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[112,17]

      Message: "JBAS010471: Jndi name have to start with java:/ or java:jboss/"

                at org.jboss.as.connector.subsystems.datasources.DataSourcesExtension$DataSourceSubsystemParser.readElement(DataSourcesExtension.java:577)

                at org.jboss.as.connector.subsystems.datasources.DataSourcesExtension$DataSourceSubsystemParser.readElement(DataSourcesExtension.java:182)

                at org.jboss.staxmapper.XMLMapperImpl.processNested(XMLMapperImpl.java:110) [staxmapper-1.1.0.Final.jar:1.1.0.Final]

                at org.jboss.staxmapper.XMLExtendedStreamReaderImpl.handleAny(XMLExtendedStreamReaderImpl.java:69) [staxmapper-1.1.0.Final.jar:1.1.0.Final]

                at org.jboss.as.server.parsing.StandaloneXml.parseServerProfile(StandaloneXml.java:1028) [jboss-as-server-7.2.0.Final.jar:7.2.0.Final]

                at org.jboss.as.server.parsing.StandaloneXml.readServerElement_1_4(StandaloneXml.java:449) [jboss-as-server-7.2.0.Final.jar:7.2.0.Final]

                at org.jboss.as.server.parsing.StandaloneXml.readElement(StandaloneXml.java:136) [jboss-as-server-7.2.0.Final.jar:7.2.0.Final]

                at org.jboss.as.server.parsing.StandaloneXml.readElement(StandaloneXml.java:103) [jboss-as-server-7.2.0.Final.jar:7.2.0.Final]

                at org.jboss.staxmapper.XMLMapperImpl.processNested(XMLMapperImpl.java:110) [staxmapper-1.1.0.Final.jar:1.1.0.Final]

                at org.jboss.staxmapper.XMLMapperImpl.parseDocument(XMLMapperImpl.java:69) [staxmapper-1.1.0.Final.jar:1.1.0.Final]

                at org.jboss.as.controller.persistence.XmlConfigurationPersister.load(XmlConfigurationPersister.java:133) [jboss-as-controller-7.2.0.Final.jar:7.2.0.Final]

                ... 3 more

        code is org.jboss.as.connector.subsystems.datasources.Constants

       

          static SimpleAttributeDefinition JNDI_NAME = new SimpleAttributeDefinition(JNDINAME_NAME, DataSource.Attribute.JNDI_NAME.getLocalName(), new ModelNode(), ModelType.STRING, false, true, MeasurementUnit.NONE, new ParameterValidator() {

              @Override

              public void validateParameter(String parameterName, ModelNode value) throws OperationFailedException {

                  if (value.isDefined()) {

                      if (value.getType() != ModelType.EXPRESSION) {

                          String str = value.asString();

                          if (!str.startsWith("java:/") && !str.startsWith("java:jboss/")) {

                              throw MESSAGES.jndiNameInvalidFormat();

                          }

                      }

                  } else {

                      throw MESSAGES.jndiNameRequired();

                  }

              }

       

       

              @Override

              public void validateResolvedParameter(String parameterName, ModelNode value) throws OperationFailedException {

                  validateParameter(parameterName, value.resolve());

              }

          });

       

       

      But, org.jboss.as.connector.subsystems.datasources.Util also says:

       

          public static String getJndiName(final ModelNode modelNode) {

              final String rawJndiName = modelNode.require(JNDI_NAME.getName()).asString();

              return cleanJndiName(rawJndiName, modelNode.hasDefined(USE_JAVA_CONTEXT.getName()) && modelNode.get(USE_JAVA_CONTEXT.getName()).asBoolean());

          }

       

       

          public static String cleanJndiName(String rawJndiName, boolean useJavaContext) {

              final String jndiName;

              if (!rawJndiName.startsWith("java:") && useJavaContext) {

                  if(rawJndiName.startsWith("jboss/")) {

                      // Bind to java:jboss/ namespace

                      jndiName = "java:" + rawJndiName;

                  } else {

                      // Bind to java:/ namespace

                      jndiName= "java:/" + rawJndiName;

                  }

              } else {

                  jndiName = rawJndiName;

              }

              return jndiName;

          }

       

      and jboss-as-datasources_1_1.xsd clearly says:

       

          <xs:attribute default="true" name="use-java-context" type="xs:boolean">

            <xs:annotation>

              <xs:documentation>

                <![CDATA[[

                  Setting this to false will bind the DataSource into global JNDI

                  Ex: use-java-context="true"

                 ]]>

              </xs:documentation>

            </xs:annotation>

          </xs:attribute>

       

       

      so my point is that shoud we remove the validation of java:/ or java:jboss/ prefix since we alreay have the logic of cleanJndiName in org.jboss.as.connector.subsystems.datasources.Util?

      If we have validation of the prefix, then why we provide use-java-context there? use-java-context never have a chance to take effect.

       

      Any ideas?

       

      Regards.