Hi all, As this issue of declaring client connectors in Servlet deployment mode is coming back often, I think we need to simplify this for 1.1 RC. I've entered a new RFE.
"Facilitate the declaration of client connectors" http://restlet.tigris.org/issues/show_bug.cgi?id=509 Feel free to comment/contribute! Best regards, Jerome -----Message d'origine----- De : [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Envoye : mercredi 4 juin 2008 10:20 A : [email protected] Objet : Re: Wrapping Application in Servlet Hi, Yesterday I had the same problem so here is the solution: ---------------- a component that configures a FILE client ------------ /** * @author Gal Nitzan ([EMAIL PROTECTED]) * * 04/06/2008 06:28:34 */ public class ServletComponent extends Component { /** * */ public ServletComponent() { this.getClients().add(Protocol.FILE); } /** * @param xmlConfigReference */ public ServletComponent(Reference xmlConfigReference) { super(xmlConfigReference); } }------------------------------- ebd of component ------------------------------ --------------- the application ---------------------- /** * @author Gal * */ public class ApiApplication extends Application { public ApiApplication(Context parentContext) { super(parentContext); } /** * Creates a root Restlet that will receive all incoming calls. */ @Override public synchronized Restlet createRoot() { // Create a router Restlet that routes each call to a // new instance of Resource. // here we get the param configured in web.xml String rootPath = getContext().getParameters().getFirstValue("com.meuhedet.app.root"); Router router = new Router(getContext()); LocalReference lr = LocalReference.createFileReference(rootPath + "/static/"); Directory dir = new Directory(getContext(), lr); router.attach("/docs/", dir); router.attach("/programs/", PcmlProgramsResource.class); return router; } }--------------- end of application ----------------- -------------- web.xml ------------- <?xml version="1.0" encoding="UTF-8"?> <web-app id="WebApp_ID" version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <display-name>api</display-name> <context-param> <description>a parameter that tells restlet to load our component</description> <param-name>com.meuhedet.app.root</param-name> <param-value>C:/jboss-4.2.2.GA/server/default/deploy/api.war</param-value> </context-param> <context-param> <description>a parameter that tells restlet to load our component</description> <param-name>org.restlet.component</param-name> <param-value>com.meuhedet.api.ServletComponent</param-value> </context-param> <context-param> <description>a parameter that tells restlet to load our ApiApplication class</description> <param-name>org.restlet.application</param-name> <param-value>com.meuhedet.api.ApiApplication</param-value> </context-param> <servlet> <display-name>Restlet Servlet</display-name> <servlet-name>RestletServlet</servlet-name> <servlet-class>com.noelios.restlet.ext.servlet.ServerServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>RestletServlet</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> <login-config> <auth-method>BASIC</auth-method> </login-config> </web-app>------------- end of web.xml ------------------ "Stephane Fellah" <[EMAIL PROTECTED]> wrote on 03/06/2008 17:06:27: > Hi, > > I am trying to wrap a custom Restlet application in a Servlet to > facilitate its deployment in a WAR file. The application needs to be > initialized with some parameters using the standard web.xml file. > My understanding is that it is possible to do it in 2 ways: > Subclassing ServletServer or writing a Servlet using > ServletConverter class. I decided to use the second approach because > it seems cleaner to me. > > I tried to initialize the Application with the context of the > ServletConverter but it seems that application does not work > properly to serve files from directory. What type of context needs > to be created in this case. Do I need to create a component for > this Servlet ? The usage of Context is pretty confusing in Restlet. > Inheritance of attributes from parent context are not automatic. > Passing context in constructor of Restlet does not behave the same > way than calling setContext() afterwards. Can anyone provide some > guideline to make this wrapping successful and provide some snippet > of code to illustrate the wrapping of an Application. > > Thank you in advance > Stephane Fellah > Image Matters LLC

