Re: How to inject a Spring bean service into a Restlet component

2010-07-24 Thread Alexander Kampmann
hi, 

The Servlet is quite right. For me, it works like that: 

web.xml: 

Register a spring- listener: 

listener
listener-class
 org.springframework.web.context.ContextLoaderListener
/listener-class
/listener

Don't forget about the config file: 

context-param
param-namecontextConfigLocation/param-name
param-value
  classpath:spring-beans.xml
/param-value
/context-param

Register the FrameworkServlet and map it to your path: 

servlet
servlet-namerestlet/servlet-name

servlet-classorg.restlet.ext.spring.RestletFrameworkServlet/servlet-class
load-on-startup1/load-on-startup
 /servlet

servlet-mapping
servlet-namerestlet/servlet-name
url-pattern/restlet/*/url-pattern
 /servlet-mapping


Than, you need an spring- config file which is named  
{servletname}-servlet.xml, so, in that case. restlet-servlet.xml. It looks like 
that: 

?xml version=1.0 encoding=UTF-8?
beans 
xmlns=http://www.springframework.org/schema/beans;
xmlns:cxf=http://cxf.apache.org/core;
xmlns:jaxws=http://cxf.apache.org/jaxws;
xmlns:test=http://apache.org/hello_world_soap_http;
xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance;
xsi:schemaLocation=
http://cxf.apache.org/core
http://cxf.apache.org/schemas/core.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://cxf.apache.org/jaxws 
http://cxf.apache.org/schemas/jaxws.xsd;
 
!-- that beans name is important, it must be root --
 bean id=root class=org.restlet.ext.spring.SpringRouter
property name=attachments
map
entry key=/restlet1
bean 
class=org.restlet.ext.spring.SpringFinder
lookup-method name=create
bean=restlet1 /
/bean
/entry
entry key=/test
bean 
class=org.restlet.ext.spring.SpringFinder
lookup-method name=create
bean=restlet2 /
/bean
/entry
/map
/property
/bean
 
 bean name=restlet1 class=ServerResourceClassName
 /bean
 
 bean name=restlet2 class=ServerResourceClassName
 /bean

I hope that'll do, 

Alex

 Original-Nachricht 
 Datum: Tue, 20 Jul 2010 10:05:17 -0600
 Von: Larry Meadors larry.mead...@gmail.com
 An: discuss@restlet.tigris.org
 Betreff: Re: How to inject a Spring bean service into a Restlet component

 Not Spring...but I used a Finder to inject mine with Guice - it only
 required extending Finder and overriding one method:
 
   public GuiceFinder(Context context, Class? targetClass) {
   super(context, targetClass);
   }
 
   @Override
   public ServerResource create(Class? extends ServerResource
 targetClass, Request request, Response response) {
   return InjectorFactory.getInjector().getInstance(targetClass);
   }
 
 Larry
 
 
 On Tue, Jul 20, 2010 at 9:58 AM, Richard Brewster
 richard.brews...@willowtreeapps.com wrote:
  I really need help getting this to work.  The examples I've found refer
 to a
  restlet Resource, which is deprecated.  For example:
 
 
 http://wiki.restlet.org/docs_2.0/13-restlet/28-restlet/70-restlet/196-restlet.html
 
  I think I need to use RestletFrameworkServlet.  But I have not found a
 good
  example.
 
  --
  View this message in context:
 http://restlet-discuss.1400322.n2.nabble.com/How-to-inject-a-Spring-bean-service-into-a-Restlet-component-tp5314211p5317233.html
  Sent from the Restlet Discuss mailing list archive at Nabble.com.
 
  --
 
 http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2635832
 
 
 --
 http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2635842

-- 
GMX DSL: Internet-, Telefon- und Handy-Flat ab 19,99 EUR/mtl.  
Bis zu 150 EUR Startguthaben inklusive! http://portal.gmx.net/de/go/dsl

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


Re: How to inject a Spring bean service into a Restlet component

2010-07-21 Thread Larry Meadors
Not Spring...but I used a Finder to inject mine with Guice - it only
required extending Finder and overriding one method:

public GuiceFinder(Context context, Class? targetClass) {
super(context, targetClass);
}

@Override
public ServerResource create(Class? extends ServerResource
targetClass, Request request, Response response) {
return InjectorFactory.getInjector().getInstance(targetClass);
}

Larry


On Tue, Jul 20, 2010 at 9:58 AM, Richard Brewster
richard.brews...@willowtreeapps.com wrote:
 I really need help getting this to work.  The examples I've found refer to a
 restlet Resource, which is deprecated.  For example:

 http://wiki.restlet.org/docs_2.0/13-restlet/28-restlet/70-restlet/196-restlet.html

 I think I need to use RestletFrameworkServlet.  But I have not found a good
 example.

 --
 View this message in context: 
 http://restlet-discuss.1400322.n2.nabble.com/How-to-inject-a-Spring-bean-service-into-a-Restlet-component-tp5314211p5317233.html
 Sent from the Restlet Discuss mailing list archive at Nabble.com.

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


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


Re: How to inject a Spring bean service into a Restlet component

2010-07-21 Thread Richard Brewster
Now that I'm able to manage ServerResources in Spring and route requests to
them, I have run into yet another problem.  My server resources have no
Restlet Context!  Since Spring is creating them, like this:

!-- restlet resources --
bean id=sampleResource
class=com.willowtreeapps.rest.resource.TestResource scope=prototype
!-- let spring inject your service --
property name=lookupManager ref=lookupManager/property
/bean

The sampleResource has no Context.  So when I call getContext() it returns
null.  What I really need is to get the container ServletContext for use
within my server resource.  The examples I've found for that assume that you
have a Restlet Context available to query.

-- 
View this message in context: 
http://restlet-discuss.1400322.n2.nabble.com/How-to-inject-a-Spring-bean-service-into-a-Restlet-component-tp5314211p5322405.html
Sent from the Restlet Discuss mailing list archive at Nabble.com.

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


How to inject a Spring bean service into a Restlet component

2010-07-19 Thread Richard Brewster
Just starting with Restlet and Spring in Tomcat container.  I have a Spring
MVC web application to which I wish to add Restlet support on some URL
paths.  I have the Restlet In Action MEAP book.  I set up
org.restlet.ext.servlet.ServerServlet in web.xml to init either a restlet
application or component.  All of that works fine.

I want to use Spring to wire beans from my service layer into restlet
applications and components.  I haven't found an example of how to go about
this.  All existing examples show calling 'new' on components and
applications, or having the ones declared in web.xml automatically
instantiated.  How can I take over instantiation of restlet components by
using Spring?

Thanks,

Richard
-- 
View this message in context: 
http://restlet-discuss.1400322.n2.nabble.com/How-to-inject-a-Spring-bean-service-into-a-Restlet-component-tp5314211p5314211.html
Sent from the Restlet Discuss mailing list archive at Nabble.com.

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