Warning: Table './petronio_db1/hijack_cache_page' is marked as crashed and should be repaired query: SELECT data, created, headers, expire FROM hijack_cache_page WHERE cid = 'http://hijack.it/node/33' in /accounts/petronio/www/drupal/includes/database.mysql.inc on line 174

Warning: Cannot modify header information - headers already sent by (output started at /accounts/petronio/www/drupal/includes/database.mysql.inc:174) in /accounts/petronio/www/drupal/includes/bootstrap.inc on line 569

Warning: Cannot modify header information - headers already sent by (output started at /accounts/petronio/www/drupal/includes/database.mysql.inc:174) in /accounts/petronio/www/drupal/includes/bootstrap.inc on line 570

Warning: Cannot modify header information - headers already sent by (output started at /accounts/petronio/www/drupal/includes/database.mysql.inc:174) in /accounts/petronio/www/drupal/includes/bootstrap.inc on line 571

Warning: Cannot modify header information - headers already sent by (output started at /accounts/petronio/www/drupal/includes/database.mysql.inc:174) in /accounts/petronio/www/drupal/includes/bootstrap.inc on line 572

Warning: Table './petronio_db1/hijack_watchdog' is marked as crashed and should be repaired query: INSERT INTO hijack_watchdog (uid, type, message, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', '<em>Cannot modify header information - headers already sent by (output started at /accounts/petronio/www/drupal/includes/database.mysql.inc:174)</em> in <em>/accounts/petronio/www/drupal/includes/common.inc</em> on line <em>141</em>.', 2, '', 'http://hijack.it/node/33', '', '54.198.221.13', 1511355683) in /accounts/petronio/www/drupal/includes/database.mysql.inc on line 174

Warning: Table './petronio_db1/hijack_watchdog' is marked as crashed and should be repaired query: INSERT INTO hijack_watchdog (uid, type, message, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', '<em>Table &amp;#039;./petronio_db1/hijack_watchdog&amp;#039; is marked as crashed and should be repaired\nquery: INSERT INTO hijack_watchdog (uid, type, message, severity, link, location, referer, hostname, timestamp) VALUES (0, &amp;#039;flickr&amp;#039;, &amp;#039;Could not connect to Flickr, Error: Forbidden&amp;#039;, 1, &amp;#039;&amp;#039;, &amp;#039;http://hijack.it/node/33&amp;#039;, &amp;#039;&amp;#039;, &amp;#039;54.198.221.13&amp;#039;, 1511355683)</em> in <em>/accounts/petronio/www/drupal/includes/database.mysql.inc</em> on line <em>174</em>.', 2, '', 'http://hijack.it/node/33', '', '54.198.221.13', 1511355683) in /accounts/petronio/www/drupal/includes/database.mysql.inc on line 174
Datasource bindings configuration on JBoss AS 7 and Cloudbees | Hijack.it di Giacomo Petronio

Datasource bindings configuration on JBoss AS 7 and Cloudbees

  • warning: Cannot modify header information - headers already sent by (output started at /accounts/petronio/www/drupal/includes/database.mysql.inc:174) in /accounts/petronio/www/drupal/includes/common.inc on line 141.
  • user warning: Table './petronio_db1/hijack_watchdog' is marked as crashed and should be repaired query: INSERT INTO hijack_watchdog (uid, type, message, severity, link, location, referer, hostname, timestamp) VALUES (0, 'flickr', 'Could not connect to Flickr, Error: Forbidden', 1, '', 'http://hijack.it/node/33', '', '54.198.221.13', 1511355683) in /accounts/petronio/www/drupal/includes/database.mysql.inc on line 174.

I'm writing this article after I tried to configure a web application in a way that the same war package could be deployed in both JBoss and cloudbees with no configuration changes.
I thought it would be possible using the resource-ref element in the web.xml which should decouple the JNDI binding name from the application and the container, but it seems to be not totally true, at least for JBoss and Cloudbees (maybe one of the two is doing it correctly, but I don't know who!)

The final result shoul be a web application which uses a JPA persistence unit defined in the persistence.xml, on top of a MySQL DB.
The web application uses the web.xml to declare a "datasource-type" resource, which will be referenced by the persistence.xml as its jta-datasource.

How to binding the "datasource-type" resource declared in the web.xml to an actual datasource provided by the application container depends on the container.
For the JBoss AS 7 this is done through the jboss-web.xml configuration file, where the web.xml "datasource-type" resource is mapped to an existing JNDI name. This JNDI name should refer to an existing datasource configured in the JBoss standalone.xml file.
With cloudbees, the datasource is simply configured in the cloudbees-web.xml.

So, here is the list of the involved components:

  • A MySQL database named localTaskrDB running locally (for JBoss) and a MySQL database running on cloudbees, named remoteTaskrDB
  • A "datasource-type" resource declared in the web.xml (<res-ref-name>taskrDS</res-ref-name>)
  • The JPA persistence.xml configuration file where we declare a persistence unit which will use the datasource reference declared in the web.xml (<jta-data-source>taskrDS(*)</jta-data-source>)
  • The "real" datasource, which will be configured differently for each container:
    • JBoss AS 7: the "real" datasource is configured in the standalone.xml, while the jboss-web.xml configuration file acts as a "bridge" from the resource declared in the web.xml (taskrDS) and the real datasource declared in the standalone.xml
    • Cloudbees: the "real" datasource is configured simply in the clodubees-web.xml file

(*) The problem is here. I though that the jta-data-source value of the persistence unit should have be the same of the res-ref-name declared in the web.xml. But this works only in cloudbees! In JBoss, the resource declared in the web.xml as a res-ref-name, is registered in the java:comp/env/ context!!

Example:

app.war/WEB-INF/web.xml
Here we declare a "datasource type" resource with the "logical" name taskrDS:

<resource-ref>
	<res-ref-name>taskrDS</res-ref-name>
	<res-type>javax.sql.DataSource</res-type>
	<res-auth>Container</res-auth>
</resource-ref>

app.war/WEB-INF/classes/META-INF/persistence.xml
Here we declare a persistence unit which use the datasource defined in the web.xml, putting it in the jta-data-source element.
The thing is that here I should have expected to simply put the taskrDS value, as declared in the web.xml. But it's not totally true since it works only for cloudbees. For JBoss we have to add the java:comp/env/ prefix:

<persistence-unit name="primary">
	<!-- for JBoss AS 7 -->
	<jta-data-source>java:comp/env/taskrDS</jta-data-source>
	<!-- for cloudbees  -->
	<jta-data-source>taskrDS</jta-data-source>
</persistence-unit>

app.war/WEB-INF/jboss-web.xml
This file is specific for JBoss and it is used to bind the datasource defined in the web.xml to a real JNDI name, specific for the container. The resource-ref element for the jboss-web.xml is similar to the one in the web.xml, but here we add the jndi-name element:

<jboss-web>
      <resource-ref>
        <res-ref-name>taskrDS</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <jndi-name>java:jboss/datasources/localTaskrDS</jndi-name>
    </resource-ref>
</jboss-web>

jboss default.xml configuration file
In this file we configure the datasource used to connect to our MySQL DBMS, and the jndi-name declared here is referenced in the jboss-web.xml:

<datasource jta="true" jndi-name="java:jboss/datasources/localTaskrDS" pool-name="LocalTaskrDS" 
enabled="true" use-java-context="true">
    <connection-url>jdbc:mysql://127.0.0.1:3306/localTaskrDB</connection-url>
    <driver>mysql</driver>
    <security>
        <user-name>root</user-name>
        <password>root</password>
    </security>
</datasource>

app.war/WEB-INF/cloudbees-web.xml
In this file we configure a datasource in cloudbees, used to connect to the remote DB:

<resource name="taskrDS" auth="Container" type="javax.sql.DataSource">
	<param name="username" value="username" />
	<param name="password" value="pwd" />
	<param name="url" value="jdbc:mysql://xxx-yyy.amazonaws.com:3306/remoteTaskrDB" />
</resource>

The summary is that I failed to create a war which is deployable on both cloudbees and JBoss AS7 with no modification. However it's not too bad since we only need to update the jta-data-source value of the persistence.xml, but this conclusion makes me wonder of the utility of declaring a datasource type resource in the web.xml, which adds another layer, but still, container dependent!!


Warning: Table './petronio_db1/hijack_watchdog' is marked as crashed and should be repaired query: INSERT INTO hijack_watchdog (uid, type, message, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', '<em>Table &amp;#039;./petronio_db1/hijack_cache_page&amp;#039; is marked as crashed and should be repaired\nquery: LOCK TABLES hijack_cache_page WRITE</em> in <em>/accounts/petronio/www/drupal/includes/database.mysql.inc</em> on line <em>174</em>.', 2, '', 'http://hijack.it/node/33', '', '54.198.221.13', 1511355683) in /accounts/petronio/www/drupal/includes/database.mysql.inc on line 174

Warning: Table './petronio_db1/hijack_watchdog' is marked as crashed and should be repaired query: INSERT INTO hijack_watchdog (uid, type, message, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', '<em></em> in <em>/accounts/petronio/www/drupal/includes/database.mysql.inc</em> on line <em>174</em>.', 2, '', 'http://hijack.it/node/33', '', '54.198.221.13', 1511355683) in /accounts/petronio/www/drupal/includes/database.mysql.inc on line 174

Warning: Table './petronio_db1/hijack_watchdog' is marked as crashed and should be repaired query: INSERT INTO hijack_watchdog (uid, type, message, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', '<em>Table &amp;#039;./petronio_db1/hijack_sessions&amp;#039; is marked as crashed and should be repaired\nquery: UPDATE hijack_sessions SET uid = 0, cache = 0, hostname = &amp;#039;54.198.221.13&amp;#039;, session = &amp;#039;messages|a:1:{s:5:\\&amp;quot;error\\&amp;quot;;a:2:{i:0;s:225:\\&amp;quot;user warning: Table &amp;amp;#039;./petronio_db1/hijack_cache_page&amp;amp;#039; is marked as crashed and should be repaired\\nquery: LOCK TABLES hijack_cache_page WRITE in /accounts/petronio/www/drupal/includes/database.mysql.inc on line 174.\\&amp;quot;;i:1;s:88:\\&amp;quot;user warning: in /accounts/petronio/www/drupal/includes/database.mysql.inc on line 174.\\&amp;quot;;}}&amp;#039;, timestamp = 1511355683 WHERE s in /accounts/petronio/www/drupal/includes/database.mysql.inc on line 174