| Subcribe via RSS

Eclipse + Maven + AppEngine: Invalid classpath publish/export dependency

September 3rd, 2009 | 1 Comment | Posted in Software Development

While working with Eclipse and Google Plugin for Eclipse the Maven Integration Plugin I ran into the problem that the dependency on the JDO API library jdo2-api-2.3-ea.jar appears in the App Engine SDK and in the Maven dependencies imported from another project. The Eclipse Classpath Dependency Validator showed the following error message:

Invalid classpath publish/export dependency /local/eclipse/galileo/plugins/com.google.appengine.eclipse.sdkbundle_1.2.2.v200907291526/appengine-java-sdk-1.2.2/lib/user/orm/jdo2-api-2.3-ea.jar. The project contains another dependency with the same archive name.

The solution for this problem was using the notion of explicit dependency exclusion of Maven 2.x in the pom.xml.

Tags: , ,

ConversionException when parsing XML with XStream: Element is not defined

May 27th, 2009 | No Comments | Posted in Software Development

XStream is an easy to use Java library to serialize objects to XML and back again. Yesterday I wanted to parse a XML document generated by a third party software with the following structure:

<?xml version="1.0" encoding="UTF-8"?>
<AuditTrail>
    <Entry type="ExecutionReport" msgId="2544804979">
        <field tag="35" val="8"/>
        <field tag="34" val="000023"/>
        <field tag="43" val="N"/>
        <field tag="52" val="20090526-20:08:31"/>
        <field tag="6556" val="today12"/>
        <field tag="17" val="73740.1243368511.0"/>
        <field tag="32" val="*"/>
    </Entry>
    <Entry type="Acknowledged" msgId="1540251818">
    </Entry>
</AuditTrail>

I created three classes AuditTrail, AuditTrailEntry and AuditTrailEntryField for the elements AuditTrail, Entry, and field, respectively. In addition, I set the aliases accordingly:

XStream xStream = new XStream ();
xStream.alias ("AuditTrail", AuditTrail.class);
xStream.alias ("Entry", AuditTrailEntry.class);
xStream.alias ("field", AuditTrailEntryField.class);

A call to the method fromXml() of the XStream object resulted in the following exception:

ConversionException: Element [NAME] of type [TYPE]
                     is not defined as [NAME] in type [TYPE]

Because I did not find a quick solution via a Google search I was forced to read the XStream documentation. ;-) There I learned something about Implicit Collections in XStream. Whenever you have a collection which does not display it’s root tag, you can map it as an implicit collection:

xStream.addImplicitCollection (AuditTrailEntry.class, "fields");
xStream.addImplicitCollection (AuditTrail.class, "entries");

with

private List <AuditTrailEntryField> fields;

in class AuditTrailEntry and

private List <AuditTrailEntry> entries;

in class AuditTrail.

Tags: , ,

Tomcat + Hibernate + C3P0 + MySQL: Communications link failure

December 30th, 2008 | No Comments | Posted in Software Development

After deploying a Google GWT application using Hibernate and C3P0 connection pooling backed by a MySQL database server to a test server running Tomcat everything seemed to run correctly. But letting the server run over night a login attempt failed the next day. A quick search showed me that I am not the only one on this planet who ran into the following error:

org.hibernate.exception.JDBCConnectionException:
  could not execute query
[...]
com.mysql.jdbc.CommunicationsException:
  Communications link failure due to underlying exception:
[...]

This problem occurs because MySQL drops idle JDBC connection after 8 hours, but the C3P0 connection pooling mechanism still considers these connection as alive and valid.

I found several possible solution on the Internet. Some people recommend to set the “autoReconnect” parameter in the JDBC URL, but this is not recommended by the MySQL team.

Others recommend to set the C3P0 properties accordingly in order to check and close idle database connections. In most cases the proposed solution looks like the “official” configuration provided by the Hibernate crew:

<property name="c3p0.min_size">3</property>
<property name="c3p0.max_size">25</property>
<property name="c3p0.acquire_increment">1</property>
<property name="c3p0.max_statements">50</property>
<property name="c3p0.timeout">14400</property>
<property name="c3p0.idle_test_period">3600</property>

But as I have found in many, many comments in discussion groups this also did not work in a large number of cases. In order to get C3P0 connection pooling in Hibernate3 work correctly with a MySQL database one important property setting is still missing. I found this hint in a comment to the above “official” configuration. In addition one has to explicitly set the connection provider class:

<property name="connection.provider_class">
  org.hibernate.connection.C3P0ConnectionProvider
</property>

After setting this property the above C3P0 configuration works correctly. At least for me.

Tags: , , ,

How to write untestable code

November 7th, 2008 | No Comments | Posted in Software Development

In the talk “Unit Testing” within the series of Google “Clean Code Talks” Miško Hevery first asks the audience how they would write untestable code. There were not much answers although we are all very good at it. Question: “How to write untestable code?” Answer: “I don’t know. It just works.” Fortunately he also offers ideas how to write testable code during the talk.

Tags: ,

XPP3 pull-parser causing an ArrayIndexOutOfBoundsException: Google GWT with Eclipse, Maven and Hibernate

October 17th, 2008 | No Comments | Posted in Software Development

Today I lost almost two hours of productive work because I had problems compiling a simple Google GWT application. For software development I use Eclipse 3.4 (Ganymede) with the Maven Integration plugin. In case of GWT I also use the Cypal Studio.

My GWT application makes RPCs to a server backed by Hibernate. Including Hibernate (org.hibernate:hibernate-core-3.3.1.GA from the JBoss repository) into the classpath via Maven also includes XPP3 and the pull-parser-2 libraries. Then for some reason the Google GWT compiler uses the pull-parser-2 to parse the XML of the inherited modules.

The module com.google.gwt.user.User includes the module com.google.gwt.i18n.I18N which causes an ArrayIndexOutOfBoundsException:

[ERROR] Line 29: Unexpected exception while processing element 'inherits'
java.lang.ArrayIndexOutOfBoundsException: null
    at java.lang.System.arraycopy(Native Method)
    at org.gjt.xpp.impl.tokenizer.Tokenizer.next(Tokenizer.java:1274)
    at org.gjt.xpp.impl.pullparser.PullParser.next(PullParser.java:392)
    at org.gjt.xpp.sax2.Driver.parseSubTree(Driver.java:415)
    at org.gjt.xpp.sax2.Driver.parse(Driver.java:310)
    at com.google.gwt.dev.util.xml.ReflectiveParser$Impl.parse(ReflectiveParser.java:310)

This seems to be a bug in the pull-parser-2. Excluding the pull-parser from the hibernate-core dependency removes it from the class path, but the GWT compiler continues using it for parsing its XML modules. The solution was to include the pull-parser-2.1.10 in the Java Build Path of Eclipse and put it to the first position in the build class path order in Eclipse.

Tags: , , , , ,