Child pages
  • JAXRS Testing
Skip to end of metadata
Go to start of metadata

JAX-RS Testing  

JAX-RS endpoints can be easily tested using the embedded Jetty or CXF Local Transport.

Embedded Jetty

Maven Dependency




It is quite easy to setup a server and start testing it. The advantage of using the embedded Jetty is that a complete end-to-end round-trip can be exercised, thus stressing all the CXF runtime which comes at the cost of some added complexity to do with setting up the server.

Local Transport

Starting from CXF 2.6.2 it is possible to use CXF Local Transport for testing the JAX-RS endpoints and clients.
This avoids the need to start an embedded servlet container and the tests will run faster.

Maven Dependency

Note that setting a LocalConduit.DIRECT_DISPATCH property to 'true' ensures that the invocation goes immediately into the service chain after the client out chain has completed.
If this property is not set then CXF LocalConduit sets up a pipe which is initiated via an initial write on the client side.

In the above code example Local transport is activated by using a URI "local:" scheme, for example, "local://books".

Alternatively, the address can be set as a relative value such as "/books", with the server and client transportId attribute set to
"". In this case, when creating the clients, use JAXRSClientFactoryBean:


Mocking HTTP contexts

If you test a code which depends on the injected HTTP contexts such as HttpServletRequest then these contexts will have to be mocked.

For example:



  • No labels