title: How to list JBoss AS 7 datasource properties in Java code?
body: <p>I'm running JBoss AS 7.1.0.CR1b. I've got several datasources defined in my standalone.xml e.g.</p>
  
  <pre><code>        &lt;subsystem xmlns="urn:jboss:domain:datasources:1.0"&gt;
              &lt;datasources&gt;
                  &lt;datasource jndi-name="java:/MyDS" pool-name="MyDS_Pool" enabled="true" use-java-context="true" use-ccm="true"&gt;
                      &lt;connection-url&gt;some-url&lt;/connection-url&gt;
                      &lt;driver&gt;the-driver&lt;/driver&gt;
                      [etc]
  </code></pre>
  
  <p>Everything works fine.</p>
  
  <p>I'm trying to access the information contained here within my code - specifically the <code>connection-url</code> and <code>driver</code> properties. </p>
  
  <p>I've tried getting the Datasource from JNDI, as normal, but it doesn't appear to provide access to these properties:</p>
  
  <pre><code>// catches removed
  InitialContext context;
  DataSource dataSource = null;
  context = new InitialContext();
  dataSource = (DataSource) context.lookup(jndi);
  </code></pre>
  
  <p>ClientInfo and DatabaseMetadata from a Connection object from this Datasource also don't contain these granular, JBoss properties either.</p>
  
  <p>My code will be running inside the container with the datasource specfied, so all should be available. I've looked at the IronJacamar interface <code>org.jboss.jca.common.api.metadata.ds.DataSource</code>, and its implementing class, and these seem to have accessible hooks to the information I require, but I can't find any information on how to create such objects with these already deployed resources within the container (only constructor on impl involves inputting all properties manually).</p>
  
  <p>JBoss AS 7's Command-Line Interface allows you to navigate and list the datasources as a directory system. <a href="http://www.paykin.info/java/add-datasource-programaticaly-cli-jboss-7/" rel="nofollow">http://www.paykin.info/java/add-datasource-programaticaly-cli-jboss-7/</a> provides an excellent post on how to use what I believe is the Java Management API to interact with the subsystem, but this appears to involve connecting to the target JBoss server. My code is already running <em>within</em> that server, so surely there must be an easier way to do this?</p>
  
  <p>Hope somebody can help. Many thanks.</p>