DZone
Java Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Java Zone > CXF JAX-RS on Apache TomEE

CXF JAX-RS on Apache TomEE

Łukasz Budnik user avatar by
Łukasz Budnik
·
May. 24, 12 · Java Zone · Interview
Like (0)
Save
Tweet
16.83K Views

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/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
Apache TomEE

Published at DZone with permission of Łukasz Budnik, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Java Hashtable, HashMap, ConcurrentHashMap: Performance Impact
  • A Smarter Redis
  • After COVID, Developers Really Are the New Kingmakers
  • Upsert in SQL: What Is an Upsert, and When Should You Use One?

Comments

Java Partner Resources

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo