You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Sergey Beryozkin <sb...@gmail.com> on 2015/06/02 12:34:50 UTC

Re: Programatically registering a provider

Hi

On 29/05/15 11:28, Martin Nielsen wrote:
> Hi!
> I need to add a provider to transform some jaxb annotated classes into html.
>
> I found this piece of documentation:
> http://cxf.apache.org/docs/jax-rs-basics.html#JAX-RSBasics-Customizingmediatypesformessagebodyproviders
>
> It says "One can easily register a provider either from Spring
> configuration or programmatically:"
> But i don't see the programatic example.
>
>
> Can someone help me to understand how i can register a provider that can
> transform a number of jaxb objects to htrml without using Spring?
>
> I can write the MessageBodyWriter and MessageBodyReader myself, its more
> the registration part that i don't understand.
>
One option is to do

CustomApplication application = new CustomApplication();
RuntimeDelegate delegate = RuntimeDelegate.getInstance();
JAXRSServerFactoryBean bean = delegate.createEndpoint(application, 
JAXRSServerFactoryBean.class);
bean.setAddress("http://localhost:8080/services");
Server server = bean.create();
server.start();

where CustomApplication is a JAX-RS Application providing custom providers.
Alternatively create only JAXRSServerFactoryBean and set providers on it 
directly using setProviders()...

HTH, Sergey