Enterprise Integration Zone is brought to you in partnership with:

Łukasz works as a Technical Architect for an international IT company and is responsible for delivering applications written in Java EE, Spring, and .NET. He has been involved in many various projects ranging from online insurance systems, voice and video solutions, mobile systems (both native and HTML5-based), medical systems, and large system integration projects. Łukasz is an expert in distributed systems, SOA, and cloud. Łukasz holds PhD in Computer Science. Łukasz is a DZone MVB and is not an employee of DZone and has posted 20 posts at DZone. You can read more from them at their website. View Full User Profile

CXF JAX-RS on Apache TomEE

05.23.2012
| 11874 views |
  • submit to reddit

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
Published at DZone with permission of Łukasz Budnik, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Herry Johnson replied on Tue, 2012/06/12 - 1:02pm

Interesting, thanks for the link to the bug report. I never experienced any trouble with it myself for now. If I understand correctly if you are to change the location where Windows stores the user desktop, things will go sour.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.