JAX-RS Integration Testing with Apache CXF

July 14, 2020 by James Carman

The Jakarta RESTful Web Services (formerly Java API for RESTful Web Services) specification provides a robust framework for writing RESTful (and not-so-RESTful) web services in Java. The JAX-RS API allows for Resource (the service itself) and Provider (enrichers providing cross-cutting concerns) implementations to be written in a very modular, testable way.

There are times, however, when the API requires a little “magic” that only works well when the code is running within the context of a real JAX-RS implementation. The Apache CXF project provides a JAX-RS implementation module which we can use to test our JAX-RS code in its native environment. First, we need to set up our local development environment.

Getting Started

An example project has been created for your convenience. To get started, simply clone the project to your local workstation:

The example project uses Apache Maven and it already contains all dependencies you will need for following along with the code in this article. You should just need to import the project into your IDE and we can get started creating our first JAX-RS resource.

A Simple Resource

Although not required, it’s best to define your JAX-RS API using an interface:

 

 

James Carman
James Carman James has served clients both locally and coast to coast in a variety of industries and has been a valued member of the Cincinnati tech community for over two decades. He has also served the Apache Software Foundation as a committer, committee member, and officer. He has a wife and three daughters. He attends church at seven hills church in northern Kentucky. July 14, 2020