TomEE and JAXRS provider configuration depending on environment

TomEE supports “environment integration” through several solutions (altdd support, external configuration using conf/ etc….). But how to configure a JAXRS provider depending the environment?

First why should I need it? Suppose you configured a JSON provider, quite common for a JAX-RS application no? You want your application to be efficient in production so you use “flat” JSON but in dev you surely prefer to get formatted (“pretty”) JSON to keep it readable.

How to do it with TomEE?

This needs a little setup if you only rely on defaults but it is then actually quite simple.

First you need to configure your provider using openejb-jar.xml + resources.xml.

As a reminder these files will be in WEB-INF and look like (I use johnzon as a sample provider):

  <pojo-deployment class-name="org.superbiz.MyJaxRsApplication">
      cxf.jaxrs.skip-provider-scanning = true
      cxf.jaxrs.providers = johnzon
  <Service id="johnzon" class-name="org.apache.johnzon.jaxrs.ConfigurableJohnzonProvider">
    # any config
    bufferSize = 1048576

So now I have these files, they are packaged in my war and I deploy my war as an unmodifiable unit (I suppose I can’t even touch web.xml since it is part of the deployment).

However I can modify tomee/conf/*. So I can modify conf/ And here is the trick, because we are using resources.xml we can use the id to set some more properties. So if I add in

johnzon.Pretty = true

Then my JSON will be formatted 🙂 – cause johnzon support pretty option on ConfigurableJohnzonProvider.

For some environments it is enough (in particular since you can even put this in ~/.openejb/ if you want it global for all your dev instances).

But if you want to go further you can use conf/ and set in conf/ the environment thanks to openejb.profile property (openejb.profile=development).


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s