Friday, September 28, 2012

Running EclipseLink DBWS 2.4.0 on GlassFish 3.1.2

In a previous blog I explained how to create a web service using the EclipseLink DBWS utility. This blog explains how to deploy this to GlassFish 3.1.2.

The main challenge is getting the right classes to load. But let's start from the beginning: create the war file.

Create the war file

First we create the war file with the DBWSBuilder utility. I defined a builder file on the employees table in the standard hr schema as follows:

<?xml version="1.0" encoding="UTF-8"?>
<dbws-builder xmlns:xsd="">
<property name="projectName">Employee</property>
<property name="driver">oracle.jdbc.OracleDriver</property>
<property name="password">hr</property>
<property name="url">jdbc:oracle:thin:@localhost:1521:ORCL</property>
<property name="username">hr</property>
<property name="platformClassname"></property>
<property name="logLevel">all</property> 
<table schemaPattern="%" tableNamePattern="EMPLOYEES"/>

Second, I created the war file with the DBWS utility:
$ECLIPSELINK_HOME/utils/dbws/ -builderFile EmployeeTableBuilder.xml -stageDir . -packageAs glassfish employee.war

NB: don't forget to set the paths in in $ECLIPSELINK_HOME/utils/dbws/ directory.

Add libraries to the war file

The war file that is created assumes that the correct version of the  eclipselink.jar is on the classpath of the server.  So first we add two libraries to the WEB-INF directory:
  • eclipselink.jar
  • javax.persistence_2.0.4.v201112161009.jar
I would have liked it a lot better if I would have had the option in the DBWSBuilder utility to set a flag to include the eclipselink.jar and the persistence jar in the WEB-INF/lib directory, or to set a flag to tell it not to do that. Similar to the 'provided' property that Maven offers.
If you forget this step, there will be an exception in your $GLASSFISH_DOMAIN/logs/server.log file stating:|_ThreadID=21;_ThreadName=Thread-2;|Deployment failed
java.lang.TypeNotPresentException: Type ProviderHelper not present

Add libraries to your domain

The JDBC driver needs to be added to the lib/ext directory of your glassfish domain. 

cp $ORACLE_HOME/jdbc/lib/ojdbc6.jar $GLASSFISH_DOMAIN/lib/ext

If you skip this step, or put the jar in the WEB-INF lib, you will get a SOAP Fault that is caused by a ClassNotFoundException:

com.sun.enterprise.container.common.spi.util.InjectionException: Error creating managed object for class: class _dbws.DBWSProvider
Caused by: java.lang.NoClassDefFoundError: oracle/sql/TIMESTAMP

Test the service

Glassfish offers a tester for webservices. This does not work, because the container does not recognize the webservice. You get the following (incorrect) error:

Service {urn:EmployeeService}EmployeeService looks like a JAX-RPC based WebService.

Please note that the tester feature is supported for JAXWS based webservices only

Creating a project based on the deployed wsdl does work as expected.

No comments:

Post a Comment