Thanks to Kevin and Jerome's help, I was able to get a working Spring 
configuration. It still uses the deprecated Resource class, but it works for 
now and that's good
enough for my needs. In case anyone is following this thread, here are the 
details:


applicationContext.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans";
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xmlns:aop="http://www.springframework.org/schema/aop";
        xmlns:tx="http://www.springframework.org/schema/tx";
        xsi:schemaLocation="
        http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/tx 
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
        http://www.springframework.org/schema/aop 
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd";>

        <bean id="springComponent" 
class="org.restlet.ext.spring.SpringComponent" init-method="start" 
destroy-method="stop">
                <property name="server">
                        <bean class="org.restlet.ext.spring.SpringServer">
                                <constructor-arg value="http" />
                                <constructor-arg value="8182" />
                        </bean>
                </property>
                <property name="defaultTarget" ref="springRouter" />
        </bean>

        <bean id="springRouter" 
class="org.example.uniq.rest.UniqSpringBeanRouter" />

        <bean name="/uniq" autowire="byName" id="uniqResource" 
class="org.example.uniq.rest.UniqResource" scope="prototype">
                <property name="nextUniqDao" ref="nextUniqDao" />
        </bean>
</beans>


UniqResource.java:

public class UniqResource extends Resource {
        
        private NextUniqDao nextUniqDao;
        
        public final void setNextUniqDao(NextUniqDao nextUniqDao) {
                this.nextUniqDao = nextUniqDao;
        }
        
        /** @see 
org.restlet.resource.Resource#represent(org.restlet.representation.Variant) */
        @Override
        public Representation represent(Variant variant) throws 
ResourceException {
                Long next = this.nextUniqDao.pop();
                this.getResponse().setStatus(Status.SUCCESS_OK);
                return new ReaderRepresentation(new 
StringReader(next.toString()), MediaType.TEXT_PLAIN);
        }

    /** @see org.restlet.resource.Resource#init(org.restlet.Context, 
org.restlet.data.Request, org.restlet.data.Response) */
    @Override
    public void init(Context context, Request request, Response response) {
        super.init(context, request, response);
        getVariants().add(new Variant(MediaType.TEXT_PLAIN));  
    }
}

And finally, UniqSpringBeanRouter.java:

public class UniqSpringBeanRouter extends SpringBeanRouter {
    
    /** @see 
org.restlet.ext.spring.SpringBeanRouter#createFinder(org.springframework.beans.factory.BeanFactory,
 java.lang.String) */
    protected Finder createFinder(BeanFactory beanFactory, String beanName) {
        SpringBeanFinder springBeanFinder = new SpringBeanFinder(beanFactory, 
beanName);
        springBeanFinder.setTargetClass(UniqResource.class);
                return springBeanFinder;
    }
}

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=1827988

Reply via email to