Some tips for TomEE and JAXRS config


TomEE+ supports JAXRS but some configuration can look a bit hidden.

I’ll try in this post to give you some few hints.

Providers

JAXRS defines several providers. It can be exception mappers or message body writer for instance.

To configure it in TomEE 1.0.0 (or OpenEJB 4.0.0) you have to set the property openejb.cxf.jax-rs.providers to the qualified name of providers (split by space or comma). To specify a provider for a specific class use .providers property.

In next version a new property will be available to ask TomEE to add automatically all available providers. Simply set openejb.jaxrs.providers.auto to true and your providers will automatically be added.

Note: if you set “default” as provider name it will add jaxb and json cxf providers.

Cxf properties

Note: this is refactored to be able to configure webservices (jaxws/jaxrs) through resources.xml, more in another post

Cxf jaxrs services support several configuration throuhg properties. In TomEE (since version > 1.0.0 when it will be released) you’ll be able to set openejb.cxf.rs.properties to the list of properties you want. It is a list of key/value separated by a comma (ex: foo1=bar1,foo2=bar2).

Errors

When you get an error you just get a line saying “something happened”. That’s not very useful in particular when you are debugging your service. That’s why now (version > 1.0.0) you can ask the stacktrace setting the property  openejb.cxf.rs.properties to the value faultStackTraceEnabled=true.

Want more content ? Keep up-to-date on my new blog

Or stay in touch on twitter @rmannibucau

Advertisement

9 thoughts on “Some tips for TomEE and JAXRS config

    1. rmannibucau Post author

      I think you imported a lib using cdi api for rest purpose. That’s often spring oriented libs. Simple exclude this lib from scanning using conf/exclusions.list

      Reply
  1. Talo (@carloschacin)

    I’m using tomee-maven-plugin:

    org.apache.openejb.maven
    tomee-maven-plugin
    1.0-alpha-1

    1.0.0
    plus
    /ims-api
    ${basedir}/src/test/tomcat/conf

    And I added src/test/tomcat/conf/exclusions.list file content:

    ApacheJMeter
    XmlSchema-
    activation-
    activeio-
    activemq-
    aether-
    antlr-
    aopalliance-
    avalon-framework-
    axis-
    axis2-
    bcprov-
    bval-core
    bval-jsr
    c3p0-
    catalina-
    cglib-
    commons-beanutils
    commons-cli-
    commons-codec-
    commons-collections-
    commons-dbcp
    commons-dbcp-all-1.3-
    commons-digester-
    commons-discovery-
    commons-httpclient-
    commons-io-
    commons-lang-
    commons-lang3-
    commons-logging-
    commons-logging-api-
    commons-net-
    commons-pool-
    cssparser-
    cxf-
    deploy.jar
    derby-
    derbyclient-
    derbynet-
    dom4j-
    ecj-
    eclipselink-
    geronimo-
    google-
    gragent.jar
    gson
    guice-
    hibernate-
    howl-
    hsqldb-
    htmlunit-
    httpclient-
    httpcore-
    icu4j-
    idb-
    idea_rt.jar
    jasypt-
    javaee-
    javaee-api
    javassist-
    javaws.jar
    javax.
    jaxb-
    jaxp-
    jboss-
    jbossall-
    jbosscx-
    jbossjts-
    jbosssx-
    jcommander-
    jersey-
    jettison-
    jetty-
    jline
    jmdns-
    joda-time-
    jsoup-
    jsp-api
    jsr299-
    jsr311-
    juli-
    junit-
    kahadb-
    log4j-
    logkit-
    maven-
    mbean-annotation-api-
    mimepull-
    mina-
    myfaces-api
    myfaces-impl
    neethi-
    nekohtml-
    openejb-api
    openejb-client
    openejb-cxf-bundle
    openejb-cxf-transport
    openejb-derby
    openejb-ejbd
    openejb-hsql
    openejb-http
    openejb-javaagent
    openejb-jee
    openejb-jsf
    openejb-jstl
    openejb-loader
    openejb-openwebbeans
    openejb-server
    openjpa-
    opensaml-
    openwebbeans-
    openws-
    ops4j-
    org.eclipse.
    org.junit.
    org.osgi.core-
    pax-
    plexus-
    quartz-
    rmock-
    saaj-
    sac-
    scannotation-
    serializer-
    serp-
    servlet-api-
    slf4j-
    spring-
    sshd-
    stax-api-
    surefire-
    swizzle-
    testng-
    tomee-
    tomcat-
    wagon-
    webbeans-ee
    webbeans-ejb
    webbeans-impl
    webbeans-spi
    woodstox-core-asl-
    wsdl4j-
    wss4j-
    wstx-asl-
    xalan-
    xbean-
    xercesImpl-
    xml-apis-
    xml-resolver-
    xmlrpc-
    xmlschema-
    xmlsec-
    xmltooling-
    xmlunit-
    spring-

    Error persists

    Reply
  2. rmannibucau Post author

    can you share anything?

    maybe post to openejb mailing list too

    i already got this kind of error and it was managed classes which shouldn’t be managed by a cdi container

    Reply
  3. Andy

    This is what I put in the properties file. But I still get “No message body writer has been found for response class Customer.”

    openejb.cxf.jax-rs.providers = com.mycompany.MyMessageBodyWriter
    com.mycompany.Customer.providers = com.mycompany.MyMessageBodyWriter
    openejb.jaxrs.providers.auto = true

    Any idea ?
    Here is MyMessageBodyWriter:

    package com.mycompany;

    @Produces(“my/type”)
    @Provider
    public class MyMessageBodyWriter implements MessageBodyWriter {
    @Override
    public long getSize(Customer obj, Class type, Type genericType,
    Annotation[] annotations, MediaType mediaType) {
    return -1;
    }

    @Override
    public boolean isWriteable(Class type, Type genericType,
    Annotation annotations[], MediaType mediaType) {
    return true;
    }

    @Override
    public void writeTo(Customer target, Class type, Type genericType,
    Annotation[] annotations, MediaType mediaType,
    MultivaluedMap httpHeaders, OutputStream outputStream)
    throws IOException {
    outputStream.write(“Test”.getBytes());
    outputStream.flush();
    }
    }

    Reply
    1. rmannibucau Post author

      Yes the config changed to be more consistent.

      I ll make a new post soon on it. The idea is to define cxf.jaxrs.providers in properties of openejb-jar.xml then set values to id of resources in resources.xml

      Reply
  4. Gregorry

    Hello

    Trying to switch from Jaxb to Aegis in Tomee this way is system.properties :

    # Properties for JAS RS
    # openejb.jaxrs.application =
    openejb.jaxrs.providers.auto = false
    openejb.cxf.jax-rs.providers = org.apache.cxf.jaxrs.provider.aegis.AbstractAegisProvider
    org.apache.openejb.cxf.bus.features = org.apache.cxf.feature.LoggingFeature

    But at tomee’s start it’s always jaxbprovider who is loaded

    Any idea ?

    Reply
    1. Gregorry

      error I meant
      openejb.cxf.jax-rs.providers = org.apache.cxf.provider.AegisElementProvider
      but does’nt change anything

      Reply
      1. rmannibucau Post author

        Hi

        well depend the version, on 1.7.0 you maybe want to add openejb.jaxrs.providers.auto=false in conf/system.properties and you should configure it in WEB-INF/openejb-jar.xml or just add Aegis provider in getClasses() in your Application to ensure you don’t have conflicts with other providers if some conflict exists.

        Best if you still have issues is to send a sample showing your problem on tomee user mailing list

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 )

Facebook photo

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

Connecting to %s