CXF JAX-RS on Apache TomEE
Join the DZone community and get the full member experience.
Join For Free
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/test3And 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
Published at DZone with permission of Łukasz Budnik, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments