Hi-

In a quest to improve the "springyness" of the current spring/restlet
integration I'm using, I've been playing around with some of the new
Spring related classes in the 1.1 development trunk. I think I've
managed to achieve a better fit than I had before, so I thought I'd
share it and get some feedback. This is what I did:


1. Extend org.springframework.web.servlet.FrameworkServlet and
essentially copy the functionality of ServerServlet but get the reslet
bits from spring's bean factory instead of instantiating them itself and
storing them in the servlet context. Source is attached.

2. Added the following constructor to
org.restlet.ext.spring.SpringServer

public SpringServer(String protocol, String address, int port, Restlet
target) {
        super(target.getContext(), Protocol.valueOf(protocol), address,
port, target);}

3. Wire everything up as shown in the attached applicationContext.xml.
Including using the request scope for resources (which necessitates
using org.springframework.web.context.request.RequestContextListener)

 
Does this sound reasonable? As a prototype, it works just fine, but I
haven't tested it in anything close to production.


Cheers,
Michael
<?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:util="http://www.springframework.org/schema/util";
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
		http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd";>



	<bean id="restletComponent"
		class="org.restlet.ext.spring.SpringComponent" />

	<bean id="restletApplication"
		class="org.restlet.ext.spring.SpringApplication">
		<constructor-arg ref="restletComponent" />
		<property name="root" ref="restletRouter" />
	</bean>

	<bean id="restletHttpServer"
		class="org.restlet.ext.spring.SpringServer">
		<constructor-arg value="http" />
		<constructor-arg value="" />
		<constructor-arg value="8080" />
		<constructor-arg ref="restletComponent" />
	</bean>

	<bean id="restletHttpServerHelper"
		class="com.noelios.restlet.http.HttpServerHelper">
		<constructor-arg ref="restletHttpServer" />
	</bean>

	<bean id="restletRouter"
		class="org.restlet.ext.spring.SpringRouter">
		<constructor-arg ref="restletApplication" />
		<property name="attachments">
			<map>
				<entry key="/foo" value-ref="foo" />
			</map>
		</property>
	</bean>
	<bean id="foo" class="org.restlet.ext.spring.SpringFinder">
		<lookup-method name="createResource" bean="fooResource" />
	</bean>

	<bean id="fooResource" scope="request"
		class="FooResource" />

</beans>

Attachment: RestletSpringBridgeServlet.java
Description: RestletSpringBridgeServlet.java

Reply via email to