I'm trying without much success to bootstrap a new project using both
Spring (2.5) and restlet(1.1-M2). The plan goes something like this;
 

*       Restlet resources on the front end which interact with a service
layer. The service layer contains some business logic but mostly passes off 
calls to a bunch of back end legacy systems. The goal is to expose those back 
end systems as a uniform set of RESTful web services.

*       I want to use Spring primarily for IoC, Aspects and JMX ease of
use. Plus being able to fairly easily add thread pools to my back end
adapters is appealing; all the usual Spring container arguments.

*       I can't use the Restlet HTTP server and in all likelihood the
corporate powers will make us deploy on WebSphere for production but for now 
I'm 
trying to deploy Spting+Restlet as a WAR inside Tomcat.
 

I've read all I can find on the restlet site, the faq, the wiki and this list 
about the various integration options but none are working. It seems there were 
some previous integration strategies and some newer options. Various googling 
has produced a confusing list of alternate approaches and I have to say the 
restlet docs need a major boost. 

I'd like to use Spring to inject the service layer into my Resources;
and in general to use its IoC injection across all the beans. Having
restlet config (router config, URL mapping etc) exposed (and manageable) by 
Spring is nice. 

I've had little success with "Spring as the main container" as all I get is the 
NRE logFilter and a 404 from each of the resource URLs. My
web.xml looks like this;

 
    <context-param>
        <param-name>org.restlet.application</param-name>
        <param-value>application</param-value>
    </context-param>
 
    <context-param>
        <param-name>org.restlet.component</param-name>
        <param-value>component</param-value>
    </context-param>
 
    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>
 
    <servlet>
        <servlet-name>springRestletServlet</servlet-name>
<servlet-class>com.noelios.restlet.ext.spring.SpringServerServlet</servlet-
class>
    </servlet>
 
    <servlet-mapping>
        <servlet-name>springRestletServlet</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
 
With an applicationContext.xml that has the named beans "component" and
"application" as follows;

    <bean id="component" class="org.restlet.ext.spring.SpringComponent">
        <property name="defaultTarget" ref="application"/>
        <property name="hosts">
            <list>
                <ref bean="virtualHost"/>
            </list>
        </property>
    </bean>
 
    <bean id="virtualHost" class="org.restlet.ext.spring.SpringHost">
        <property name="hostDomain"
                  value="localhost"/>
        <property name="attachments">
            <map>
                <entry key="/" value-ref="application"/>
            </map>
        </property>
    </bean>
 
    <bean id="application"
class="org.restlet.ext.spring.SpringApplication">
        <constructor-arg ref="component"/>
 
        <property name="root">
            <bean class="org.restlet.ext.spring.SpringRouter">
                <constructor-arg ref="application"/>
 
                <property name="attachments">
                    <map>
                        <entry key="/policies"
value="com.foo.policy.resource.PoliciesResource"/>
                        <entry key="/policy/{policyId}"
value="com.foo.policy.resource.PolicyResource"/>
                    </map>
                </property>
            </bean>
        </property>
    </bean>
 

I also tried the other approach namely "Restlet as the main container"
but that's got it's own errors trying to get the Restlet Application to
load Spring properly and having unwired beans leading to various NPEs.
An earlier example did work but my app resources were 'Restlets' not
'Resources' which didn't feel right either. 

I'd really appreciate if anyone has a complete end-to-end working
example of spring+restlet in tomcat with either approach, or if you can
spot a problem with the config shown above.
 

TIA,

-stephen


Reply via email to