Featured Post

Applying Email Validation to a JavaFX TextField Using Binding

This example uses the same controller as in a previous post but adds a use case to support email validation.  A Commons Validator object is ...

Saturday, February 2, 2013

Deploying Apache CXF Web Services to JBoss 5

In deploying web services to an old version of JBoss, I ran into a few problems.  The web services are developed using the following Maven archetype

org.apache.cxf.archetype / cxf-javaws-javafirst / 2.7.2

The archetype will create a WAR file containing SOAP-based web services.  There is a Hello World implementation that will echo back an input message.

Off-the-shelf, this archetype produces two errors when deploying to JBoss 5.  Note that the archetype may work without modification on other platforms.  For example, the WAR deployed successfully to Tomcat 7 prior to my suggested modifications.


These are the two deployment errors and the resolutions.


1. Bad version of SLF4J.  

It seems like there is a conflict with the logging subsystem in JBoss.  Although CXF uses Java Logging by default, something in JBoss 5 was causing the CXF code to use SLF4J.  When the CXF did this, I got the following error

java.lang.NoSuchMethodError: org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;[Ljava/lang/Object;Ljava/lang/Throwable;)V

This was solved by explicitly adding the latest SLF4J as a dependency in Maven.  Add this to the pom.xml that was generated by the archetype.

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>1.7.2</version>
</dependency>

2. Spring beans.xml and CDI

beans.xml is a reserved file in the later versions of Java EE, starting with 6.  Although JBoss 5 doesn't implement 6, there appears to be a conflict.  (Maybe with Seam or CDI included in JBoss 5.)  The CXF archetype I used creates a Spring beans file called "beans.xml".  This causes the following error


javax.inject.DefinitionException: Could not find 'import'

JBoss 5 is interpreting the beans.xml file as a CDI file instead of a Spring file.  To resolve this, rename the beans.xml to anything and update the web.xml file.  For example, rename 'beans.xml' to 'appContext.xml'.  See the following from web.xml.

<context-param>
<param-name>contextConfigLocation</param-name>
  <param-value>WEB-INF/appContext.xml</param-value>
</context-param>

To test the deployment, search the log file for errors, particularly stack traces.  You should be able to hit the following URL and call the web service.

http://localhost:8080/${war.file.name}/HelloWorld?wsdl


No comments:

Post a Comment