Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Eclipse Communications Framework (ECF) » Register MessageBodyWriter Provider for use with jersey jax-rs
Register MessageBodyWriter Provider for use with jersey jax-rs [message #1739672] Wed, 03 August 2016 16:33 Go to next message
Erdal Karaca is currently offline Erdal KaracaFriend
Messages: 854
Registered: July 2009
Senior Member
I want to transform EMF models to JSON for use in the client.

How do I register a MessageBodyWriter Provider for my web services?

Official docs are here:
https://jersey.java.net/documentation/latest/message-body-workers.html#d0e6826

But not sure how to use the ECF jersey integration to do this, i.e. pick up the provider.
Re: Register MessageBodyWriter Provider for use with jersey jax-rs [message #1739687 is a reply to message #1739672] Wed, 03 August 2016 19:46 Go to previous messageGo to next message
Scott Lewis is currently offline Scott LewisFriend
Messages: 1038
Registered: July 2009
Senior Member
Hi Erdal,

Erdal Karaca wrote on Wed, 03 August 2016 12:33
I want to transform EMF models to JSON for use in the client.

How do I register a MessageBodyWriter Provider for my web services?

Official docs are here:
https://jersey.java.net/documentation/latest/message-body-workers.html#d0e6826

But not sure how to use the ECF jersey integration to do this, i.e. pick up the provider.


This is a very timely question as I'm working this week on changes and additions to both CXF and Jersey JaxRS distribution providers. FWIW I just tested out the CXF provider on Karaf 4 + ECF RSA impl. Also I created a build of the CXF provider and the student host example (note also that for the moment I changed the default provider to be CXF instead of Jersey...I may change it back as I work on the Jersey provider.

So...to answer your question: Jax-RS lets one register extension modules via Configurable objects. For Jersey this is provided by the org.glassfish.jersey.server.ResourceConfig.ResourceConfig class.

ECF jax-rs distribution providers (jersey and cxf, client and server), have an optional 'configuration' service property that allows one to configure the Jax-RS implementation. For example:

// This sets the OSGi standard service.exported.config to the Jersey provider
props.put("service.exported.configs","ecf.jaxrs.jersey.server");
// create a Jersey ResourceConfig configuration
ResourceConfig config = new ResourceConfig();
// Register our impl of (e.g.) MessageBodyReader component...and any others
config.register(new MyMessageBodyReader(),MessageBodyReader.class);
// Set 'configuration' service property. Note that it uses the config id with '.configuration' suffix
props.put("ecf.jaxrs.jersey.server.configuration",config);

// Now using our config for exporting the remote service:
bundleContext.registerService(MyServiceInterface.class,new MyServiceImpl(),props)

This will result in using the supplied config for the Jersey server configuration rather than the default config.

Note that in my own tests it's necessary to declare the MyMessageBodyReader for each Param or return type like this:

public class MyMessageBodyReader implements MessageBodyReader<Student> {

	@Override
	public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
		// TODO Auto-generated method stub...your impl here
		return false;
	}

        @Override
	public Student readFrom(Class<Student> type, Type genericType, Annotation[] annotations,
			MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream)
		throws IOException, WebApplicationException {
		// TODO Auto-generated method stub....your impl here
		return null;
	}
}


I've been messing around with Jersey provider code since your posting and I just checked in a small fix resulting from my tests.

Alternatively, you could create your own new distribution provider, with all the custom extensions built in. If you wish you can extend the existing Jersey distribution provider and I will make any necessary changes in supporting Jax-RS dist provider code (org.eclipse.ecf.provider.jaxrs and org.eclipse.ecf.provider.jaxrs.server/client).

Re: Register MessageBodyWriter Provider for use with jersey jax-rs [message #1739688 is a reply to message #1739687] Wed, 03 August 2016 20:00 Go to previous messageGo to next message
Erdal Karaca is currently offline Erdal KaracaFriend
Messages: 854
Registered: July 2009
Senior Member
Hi Scott,
Thanks for the sample code!
I think I got the point.

I am sure by consuming the OSGi service registry for media type providers (MessageBodyWriter/Reader) , the consumer of ECF jersey will not have to deal with the details.
Let me see if I can provide/contribute that additional code.
Re: Register MessageBodyWriter Provider for use with jersey jax-rs [message #1739689 is a reply to message #1739688] Wed, 03 August 2016 20:12 Go to previous message
Scott Lewis is currently offline Scott LewisFriend
Messages: 1038
Registered: July 2009
Senior Member
Erdal Karaca wrote on Wed, 03 August 2016 16:00
Hi Scott,
Thanks for the sample code!
I think I got the point.

I am sure by consuming the OSGi service registry for media type providers (MessageBodyWriter/Reader) , the consumer of ECF jersey will not have to deal with the details.
Let me see if I can provide/contribute that additional code.


I like this idea!

BTW, I should let you know...I would like to move up to a more recent version of Jersey thatn 2.14, and have been discussing with the Orbit Jersey maintainer (Rolund). He intends to do so relatively soon, but is resource constrained.

I might do some work to build using Tycho, and move up to something around 2.23 on my own. Please LMK what your views are on this.
Previous Topic:ECF r-osgi : NPEs in proxies during startup
Next Topic:org.eclipse.ecf not contained in ECF SDK
Goto Forum:
  


Current Time: Fri Apr 19 00:38:06 GMT 2024

Powered by FUDForum. Page generated in 0.01993 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top