DZone
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
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report

CXF JAX-RS on Apache TomEE

Łukasz Budnik user avatar by
Łukasz Budnik
·
May. 24, 12 · Interview
Like (0)
Save
Tweet
Share
17.07K 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

  • Documentation 101: How to Properly Document Your Cloud Infrastructure Project
  • Demystifying the Infrastructure as Code Landscape
  • Java Concurrency: LockSupport
  • Choosing the Right Framework for Your Project

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • 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: