Richard Wallace <rwallace <at> thewallacepack.net> writes:

> 
> Hello,
> 
> I've looked at the existing Spring integration work that has gone on and 
> it looks pretty good.  But it doesn't really do what I would like it to 
> do.  The way understand it, it really is only managing the component, 
> application, and routing.
> 
> What I really would like to see is Spring managing the resources 
> themselves.  I actually don't mind wiring up that stuff myself, or 
> creating a simple Application that loads a restlet.xml file and create 
> my uri routing for my application.  But I really want the ability to 
> have Spring manage the creation of my Resources.  This way, I can take 
> full advantage of its dependency injection and and have all the goodness 
> that I'm looking for.
> 
> One project we could probably model such behavior on is the Struts 2 
> framework.  It has a similar idea, where you have your struts.xml file 
> and it contains you configuration for your actions.  By default, Struts2 
> will create your actions from the classnames that you provide.  But you 
> can use the Spring plugin or the Guice plugin or create a plugin for 
> whatever other IoC container you want and have Struts2 use it for 
> managing the creation of action objects.
> 
> I think this would give a ton of power to the Restlet developers, 
> because then you would be able to develop a Restlet and have full access 
> to the Spring framework.  I know I would prefer something like
> 
> public class AccountsResource
>         extends Resource {
>     private List<Accounts> accounts;
> 
>     public AccountsResource (Context context, Request request, Response 
> response, AccountRepository repository) {
>         super (context, request, response);
> 
>         // perform lookup of accounts
>         Accounts accounts = repository.getAll();
>         getVariants ().add (new Variant (MediaType.APPLICATION_XHTML_XML));
>     }
> ...
> }
> 
> over something where I have to use the context to lookup the Spring 
> application context and then lookup the bean of the type or name that I 
> want and then use it.  I think it would certainly spur faster adoption.
> 
> WDYT?
> 
> Rich
> 
> 

Hi
I have  made some changes in "Integration with Spring 2.0 and Apache Tomcat 5.5
by Irfan Jamadar" this examples was vary useful but it didn't do what I was
looking for. First i don't understand why UserRestlet and UsersRestlet are 
extending Restlet class?? i have use Resource (user and users are Resources as
far as i understand rest). 2 - when  send get to .../user/1 all is ok but when i
used .../user/1/ there was no representation (in my opinion its wrong behavior)
now .../user/1 and .../user/1/ are sending correct representation. And finally
spring integration... now applicationContext looks like this and i think its
more useful:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN"
                  "http://www.springframework.org/dtd/spring-beans-2.0.dtd";>
    
<beans>
  
  <bean id="userDAO" class="com.domain.UserDOA" scope="singleton"/>     
  <bean id="userDAOMock" class="com.domain.UserDAOMock" scope="prototype"/>
  
  <bean id="usersResource" class="com.rest.restlet.resource.UsersResource" 
scope="prototype" >
        <property name="userDAO">
                <ref local="userDAO"/>
        </property>
  </bean>
  
  <bean id="userResource" class="com.rest.restlet.resource.UserResource" 
scope="prototype" >
    <property name="userDAO">
        <ref local="userDAOMock"/>
        </property>
  </bean>  
  
  <bean id="usersFinder" class="org.restlet.ext.spring.SpringFinder"> 
              <lookup-method name="createResource" bean="usersResource"/> 
  </bean>
  <bean id="userFinder" class="org.restlet.ext.spring.SpringFinder"> 
              <lookup-method name="createResource" bean="userResource"/> 
  </bean>       
  
  <bean id="manager" class="com.rest.app.RestManager">
    <property name="resourceMappings">
         <bean class="java.util.HashMap">
              <constructor-arg>
                <map>
                  <entry key="/users/{user}"> <ref local="userFinder" /> 
</entry>
                                  <entry key="/users"> <ref local="usersFinder" 
/> </entry>
                       </map>
              </constructor-arg>
            </bean>
        </property>  
    </bean>
  
</beans>

there are four main changes, first i have used SpringFinder class to create
object of resources and those are conf by spring, i have used Resource instead
of Restlet, !DOCTYPE have bean changed (old one was wrong i couldn't use scope
attribute) and i had change resource .../user to .../userS ;) its more proper in
my opinion ;)
Ok for now thats all. It was my first spring and restlet 'project' sow I'm sure
there are things that could be done better I'm looking for more spring-restlet
examples.
I will try to post src on wiki


Reply via email to