TomEE supports “environment integration” through several solutions (altdd support, external configuration using conf/system.properties 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):
<openejb-jar> <pojo-deployment class-name="org.superbiz.MyJaxRsApplication"> <properties> cxf.jaxrs.skip-provider-scanning = true cxf.jaxrs.providers = johnzon </properties> </pojo-deployment> </openejb-jar>
<resources> <Service id="johnzon" class-name="org.apache.johnzon.jaxrs.ConfigurableJohnzonProvider"> # any config bufferSize = 1048576 </Service> </resources>
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/system.properties. 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 system.properties:
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/system.properties if you want it global for all your dev instances).
But if you want to go further you can use conf/development.system.properties and set in conf/system.properties the environment thanks to openejb.profile property (openejb.profile=development).