Hi
On Thu, Jul 21, 2011 at 12:23 PM, Carl-Erik Kopseng <[email protected]> wrote:
> In the project I am doing we needed to expose a function through a
> REST interface, and to not pull in any more interfaces than necessary
> I opted to leave Spring out of it and just do the setup
> programmatically. This worked fine until the point of trying to
> register the ParameterHandler. I just cannot get it working - probably
> because I am registering it in the wrong place. So far I have tried
> adding it in the getSingletons() method and in the getClasses() method
> of my Application class. Neither seem to work.
>
> The CXF JAX-RS page http://cxf.apache.org/docs/jax-rs-basics.html says
> "ParameterHandlers can be registered as providers either from Spring
> or programmatically". Where else than the Application class can I
> register them? I have googled and browsed through "RESTful Java with
> JAX-RS" to find out where I am supposed to register them, but I cannot
> find any examples on it (other than through Spring).
>
You can also register them with JAXRSServerFactoryBean...
I haven't tested them registering with Applications but I think it
should work...
I may need to test
Cheers, Sergey
> This is basically the relevant code (it that should matter).
>
> <code>
> public class MyApp extends Application {
> Set<Class<?>> classes;
> Set<Object> singletons;
>
> public MyApp() {
> /* add classes */
> classes = new HashSet<Class<?>>();
> classes.add( GrossAdultInfoHandler.class );
> classes.add( InfoChildHandler.class );
>
> /* add singletons */
> addSingletons();
> }
>
> @Override
> public Set<Class<?>> getClasses() {
> return classes;
> }
>
> @Override
> public Set<Object> getSingletons() {
> return singletons;
> }
>
> private void addSingletons() {
> singletons = new HashSet<Object>();
>
> singletons.add( new MyService() );
>
> /* Add JSON provider */
> singletons.add( new JacksonJsonProvider() );
>
> /* Add handlers */
> singletons.add( new FooHandler() );
> }
> }
>
> class FooHandler extends ParameterHandler<Foo> {
> public Foo fromString(String s) {...}
> }
> </code>
>
> br
> Carl-Erik
>
--
Sergey Beryozkin
http://sberyozkin.blogspot.com
Talend - http://www.talend.com