Configuring CXF bus in TomEE or OpenEJB standalone


Configuring the CXF bus is a common need in particular in development where we often activate the logging. The key point here is to add the LoggingFeature of CXF.

To do so in TomEE (same for OpenEJB) you can of course configure either your endpoint (webservice jaxws or jaxrs) or your application (jaxrs) to add this feature but it is done in openejb-jar.xml in the application.

However when looking CXF samples on the Internet it is often done on the CXF bus directly which is a more global configuration which can make it easier to do.

The other drawback of openejb-jar.xml for such a need is to need to package it with the application where in fact you just want it in dev.

The solution is however quite trivial since you can now configure the CXF bus in TomEE.

Just add to conf/system.properties (or as system properties or in tomee.json system-properties) the property:

org.apache.openejb.cxf.bus.features = org.apache.cxf.feature.LoggingFeature

Note: it will work too with properties, in-interceptors, in-fault-interceptors, out-interceptors, out-fault-interceptors…just use the “org.apache.openejb.cxf.bus.” prefix to configure it globally for the CXF bus.

Note 2: it can even be added in ~/.openejb/system.properties to be done on all your local instances.

Advertisement

6 thoughts on “Configuring CXF bus in TomEE or OpenEJB standalone

  1. Jimmy

    Thanks for this – I’ve been able to log raw input / output by enabling this. However, if I want to take it a step further and extend LoggingOutInterceptor, how do I get tomee/cxf to use it?

    In system.properties, I have org.apache.openejb.cxf.bus.outInterceptors = org.superbiz.myLoggingOutInterceptor

    myLoggingOutInterceptor looks like this:
    http://stackoverflow.com/questions/11038313/how-to-get-incoming-outgoing-soap-xml-in-a-simple-way-using-apache-cxf/11053289#11053289

    I added myLoggingOutInterceptor to getClasses() in ApplicationConfig

    Reply
      1. Jimmy

        Thanks, I think I’m making progress. Now I get:
        SEVERE: error invoking Observer{class=org.apache.tomee.webservices.TomeeJaxRsService}
        org.apache.openejb.OpenEJBRuntimeException: interceptors should implement
        org.apache.cxf.interceptor.Interceptor
        I’m using:
        Apache Tomcat (TomEE)/7.0.53 (1.6.0.2)

        I’ve tried it with mine and with the example from this page:

        http://cxf.apache.org/docs/interceptors.html

        import java.io.IOException;

        import org.apache.cxf.attachment.AttachmentDeserializer;
        import org.apache.cxf.message.Message;
        import org.apache.cxf.phase.AbstractPhaseInterceptor;
        import org.apache.cxf.phase.Phase;

        public class AttachmentInInterceptor extends AbstractPhaseInterceptor {

        }

  2. Jimmy

    That was it! The pom.xml we had was built with a jersey archetype and I was including cxf to make eclipse find those jars. I used a pom the arquillian jax-rs example as a template to fix ours, and things are working way better. THANK YOU!!!!

    Reply
  3. Michael

    Romain,
    thanks a lot for sharing all your knowledge regarding cxf and tomee all accross the web. In my current project, I’ve been using CXF’s LoggingInterceptors. However, I didn’t want the content of a dynamically created PDF to appear in the logs of my jax-rs service. CXFs LoggingOutInterceptor already has a check for binary content-types – however, the verbose contents of “application/pdf” documents are being written to the logs.

    For anybody that might have the same requirement: I was able to fulfil my requirement by creating my own implementation of org.apache.cxf.interceptor.LoggingOutInterceptor and overriding the “isBinaryContent(String contentType”) method to include the check for “application/pdf”.

    To enable (standard) LoggingInInterceptor and my (custom) LoggingOutInterceptor, I added the following to my openejb-jar.xml:

    cxf.jaxrs.out-interceptors = my.project.MyCustomLoggingOutInterceptor
    cxf.jaxrs.in-interceptors = org.apache.cxf.interceptor.LoggingInInterceptor

    Also – make sure, you don’t use the org.apache.cxf.annotations.Logging annotation in your project. Because if a single Resource is annotated with it CXF will use the standard LoggingOutInterceptor.

    Maybe this will help somebody 🙂

    Again, Thank you Romain for all your efforts in sharing your knowledge!

    Reply

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Connecting to %s