Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

CXF JAX-RS on Apache TomEE

DZone's Guide to

CXF JAX-RS on Apache TomEE

· Java Zone ·
Free Resource

Verify, standardize, and correct the Big 4 + more– name, email, phone and global addresses – try our Data Quality APIs now at Melissa Developer Portal!

Yesterday I got a post comment about some problems with running CXF JAX-RS on Apache Tomcat. But also 2 weeks ago Apache TomEE 1.0 has been officially released. I decided to rework the example without using Spring (which was causing the problems with JAX-RS) and deploy it to TomEE.

My project was based on the original one from this post (published over 3 years ago! April 2009): Dveloping RESTful Web Services using Apache CXF and Maven2.


Updating the original project

I decided to get rid of Spring from my project and to use Apache TomEE Plus (TomEE with additional OpenEJB and CXF jars) to manage my rest service.

To build JavaEE 6 web application I decided to use new Codehaus MOJO archetype. Instead of webapp-jee5 I used newer webapp-javaee6 archetype.

From CXF dependencies I only copied cxf-rt-frontend-jaxrs and updated its version from 2.1.4 to 2.5.2. Also I changed its scope to provided (as CXF is shipped with TomEE Plus).

After I copied and pasted my old code I changed @ProduceMime to @Produces (by the time I wrote my previous post JAX-RS was not final yet).

Setting up TomEE Plus and running the application

I downloaded TomEE Plus (with CXF-powered JAX-WS and JAX-RS runtime). Then, in Eclipse, I added new Tomcat 7 server and pointed it out to TomEE installation directory (TomEE is fully compatibile with Tomcat 7). Next I ran the application, but got the following exception: 

Caused by: java.lang.IllegalArgumentException: Unresolved variables; only 0 value(s) given for 1 unique variable(s)
 at org.apache.cxf.jaxrs.impl.UriBuilderImpl.substituteVarargs(UriBuilderImpl.java:185)
 at org.apache.cxf.jaxrs.impl.UriBuilderImpl.doBuild(UriBuilderImpl.java:82)
 at org.apache.cxf.jaxrs.impl.UriBuilderImpl.build(UriBuilderImpl.java:75)

After a quick playing around it turned out that name path param cannot be defined at the class level. I moved this definition to the first method and added @Path("/greetings") to the class.

I restarted the application and all worked like a charm.

To test I opened the following links in my browser:
http://localhost:8080/cxf-jax-rs-example/greetings/name/lukasz
http://localhost:8080/cxf-jax-rs-example/greetings/name/lukasz/state/poland
http://localhost:8080/cxf-jax-rs-example/greetings/name/lukasz/state/poland/test1/test2/test3
And this time no Spring configuration at all! TomEE and JavaEE 6 rock!

Summary

The source code is here: https://github.com/lukasz-budnik/cxf-jax-rs-example.

There is also one point to note. TomEE is insanely fast!

enjoy,
Łukasz

Developers! Quickly and easily gain access to the tools and information you need! Explore, test and combine our data quality APIs at Melissa Developer Portal – home to tools that save time and boost revenue. Our APIs verify, standardize, and correct the Big 4 + more – name, email, phone and global addresses – to ensure accurate delivery, prevent blacklisting and identify risks in real-time.

Topics:

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}