Question

I would like to use my REST client, developed with CXF, with TomEE/TomEE+ 1.0, but I have a little problem with JAXB JSON marshalling/unmarshalling (with the Jackson library). I tried both Jersey Client 1.1.13 and CXF WebClient (the version included with Tomee+ 1.0), but, I have the same error at deploy time:

org.apache.openejb.OpenEJBException: No provider available for resource-ref 'null' of type 'javax.ws.rs.ext.Providers' for 'localhost/mywebapp.Comp'

I tried also to copy the 'jackson-jaxrs-json-provieder-2.0.4.jar' jar to the TomEE lib directory, but the error is the same. I also tried to set the system property 'openejb.cxf.jax-rs.providers' to 'com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider,com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider', but nothing changed.

Here is a sample of the code I use to make a REST call with CXF:

final List<Object> providers = new ArrayList<Object>();
providers.add(new JacksonJaxbJsonProvider());
WebClient wc = WebClient.create(url, providers);

Anyway this code it's never executed, because the error is at deploy time. My webapp (the version developed with Jersey Client) works on Glassfish 3.1.2.

Where is the problem?

Thank you, bye, Demis

Was it helpful?

Solution 2

I found a good temporary solution to use the CXF rest client and the Jackson JSON marshalling with TomEE+ 1.0.0. I moved these libraries from the webapp lib to the TomEE lib directory:

  • jackson-annotations-2.0.4.jar
  • jackson-jaxrs-json-provider-2.0.4.jar
  • jackson-module-jaxb-annotations-2.0.4.jar
  • jackson-core-2.0.4.jar
  • jackson-databind-2.0.4.jar

And this is my code to make a rest call:

final ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
objectMapper.configure(SerializationFeature.WRITE_DATE_KEYS_AS_TIMESTAMPS, false);
objectMapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true);
objectMapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);
objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, true);  
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);

final JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider(objectMapper, JacksonJaxbJsonProvider.DEFAULT_ANNOTATIONS);
provider.setAnnotationsToUse(JacksonJaxbJsonProvider.DEFAULT_ANNOTATIONS);
provider.setMapper(objectMapper);

final List<Object> providers = new ArrayList<Object>();
providers.add(provider);

WebClient wc = WebClient.create(_request.getUrl(), providers);
wc = wc.type(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON);

try {
  res = (ElasticResponse) wc.invoke(_request.getHttpVerb(), _request.getMessage(), _request.getElasticResponseClass());
} catch (final ServerWebApplicationException _e) {
  this._log.log(Level.FINE, "http response code > 400", _e);
}

I hope that with the next release of TomEE I do not need to add the Jackson's libraries to the container but only to the webapp.

OTHER TIPS

Found and fixed this bug:

Try the latest TomEE snapshot.

I use jacskon (yes jars needs to be added and the provider to be set) and it works.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top