RE: Re: Unable to access servletContext?
Hi, I'm using the code recently send by Thierry on the list to get the servlet context And it's working great. ServletContextAdapter adapter = (ServletContextAdapter) getContext(); ServletContext servletContext = adapter.getServletContext(); System.out.println(servletContext.getRealPath("")); My web.xml is a little different, i put the params into the "servlet" tag, using the "init-param" instead of "context-param". But as far as i remember, it doesn't matters. ServerServletRouter com.noelios.restlet.ext.servlet.ServerServlet org.restlet.application com.bla.bla.rest.RestletRouter ServerServletRouter /rest/* -- Julien Balas JDAS Rennes -Message d'origine- De : news [mailto:[EMAIL PROTECTED] De la part de Tammy Croteau Envoyé : mercredi 11 juillet 2007 16:13 À : discuss@restlet.tigris.org Objet : Re: Unable to access servletContext? Hi Thierry, Yes, my application does implement the contructor that you are describing. I can successfully cast to an ApplicationContext but not to the ServletContextAdapter. My web.xml is very simple as it only contains the restlet adapter, servlet mapping and context params needed for the ServerServlet. org.restlet.application com.nn.ws.restlet.MyApplication RestletServlet com.noelios.restlet.ext.servlet.ServerServlet 0 RestletServlet /resources/* Anything else to try? Tammy
RE: Re: Multiples rest service using multiples servlet in tomcat.
Ok, I'm going to investigate the 2nd way, seems to fit my need. Thanks for the quick reply. -- Julien Balas JDAS Rennes -Message d'origine- De : Jerome Louvel [mailto:[EMAIL PROTECTED] Envoyé : jeudi 5 juillet 2007 16:59 À : discuss@restlet.tigris.org Objet : Re: Multiples rest service using multiples servlet in tomcat. Julien, The ServerServlet was designed to adapt on Servlet Webapp to exactly one Restlet Application. The ServerServlet caches the instantiated application inside the Webapp context which explains the behavior you observe. This needs to be better documented in the Javadocs. Now, there are different ways to achieve what you need: 1) Create two WARs, on for each Restlet Application, with only one ServerServlet in each 2) Merge your two Restlet Applications into one, and add a Router at the root of this app to handle the routing internally. 3) Rely on the ServletConverter to have a lower level integration between your Servlets and Restlets (but you loose portability to Restlet standalone mode). Hope this helps, Jerome Balas Julien a écrit : >> The Restlet framework is throwing this error because, as it implies, >> it cannot match the URI to anything that it has mapped. >> > > But it match the first servlet called > And if I restart the tomcat server and call the 2nd servlet, the 2nd > servlet works. > > >> When I decompressed your WAR file, there is no web.xml in the main >> > WEB-INF directory, > >> but rather in the EventViewer/WEB-INF, which I don't think Tomcat >> will >> > find. > > I think the web.xml is in the right place as one of the servlet is > working. > And if I call a "foobar" servlet I get a tomcat error. > And I don't get this tomcat error with any of my servlet. > Did you try to deploy the war in tomcat ? Tested with tomcat 5.5 and > 6.0. > > >> Hopefully Jerome will correct me, but can you setup an Application >> per >> > ServerServlet like this: > > I can't find any difference with the web.xml included in my war > Except for the XML header. > >
RE: Re: Multiples rest service using multiples servlet in tomcat.
I'm using 1.0.2 The very strange thing is that I have a previous version of my app and the 2 servlets are working perfectly. (I can prove it with a war) :) But I can't find the differences. The web.xml is the same The .class files are the same. I tried the war on another tomcat (on a Linux box) as well, just to be sure it's not a problem on my machine. I get the same "404 error". Btw, who is sending this error? The restlet framework ? Is there a way to get more information during the execution of the framework ? -- Julien Balas JDAS Rennes -Message d'origine- De : Jerome Louvel [mailto:[EMAIL PROTECTED] Envoyé : jeudi 5 juillet 2007 15:46 À : discuss@restlet.tigris.org Objet : Re: Multiples rest service using multiples servlet in tomcat. Hi Julien, Which version of Restlet are you using? There was a related bug fixed in 1.0.2: - Fixed bug in ServletConverter causing the caching of the base URI and inability to handle requests with various base URI style (IP address and domain names for example). Report by Ryan Daum. Best regards, Jerome Balas Julien a écrit : > > Hi > I'm trying to have 2 servlets using 2 restlet in order to provide 2 > REST services in the same tomcat. > But I have a strange behavior. > The first Servlet called works perfectly, but not the second one. > For the second one, I get a "404 error", but not a "tomcat 404". > If a call a non existing servlet I got a "tomcat 404", but my error is > not this one, the message is "*The server has not found anything > matching the request URI* You can get technical details here. > Please continue your visit at our home page. " > > I tried to isolate as much as possible the issue, with a minimal > example of 2 "Hello world" restlet. > The full war (600Ko) is available at > _http://julien.balas.free.fr/EventViewer.war_ > If anybody has a idea.. > I guess it's a config issue because each servlet/restlet is working > great if alone in a tomcat. > > > The 2 classes are very minimal > - > [package and imports] > public class Hello1 extends Application { public Hello1() { super(); } > public Hello1(Context parentContext) { super(parentContext); } public > Restlet createRoot() { Restlet restlet = new Restlet(getContext()) { > @Override public void handle(Request request, Response response) { > response.setEntity(new StringRepresentation(this.getClass().getName(), > MediaType.TEXT_HTML)); > } > }; > return restlet; > } > } > > The tomcat Logs are below > - server startup > - a successful call to "rest2" service > - a 404 on "rest1" service > - another successful call to "rest2" service > > INFO: Server startup in 4587 ms > 5 juil. 2007 15:15:12 com.noelios.restlet.LogFilter afterHandle > INFO: 2007-07-05 15:15:12 172.23.34.19 - 172.23.34.19 8180 GET > /EventViewer/rest2/456 - 200 42 - 10 _http://172.23.34.19:8180_ > Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.8.1.4) > Gecko/20070515 Firefox/2.0.0.4 - > > 5 juil. 2007 15:15:16 com.noelios.restlet.LogFilter afterHandle > INFO: 2007-07-05 15:15:16 172.23.34.19 - 172.23.34.19 8180 GET > /EventViewer/rest1/456 - 404 331 - 0 _http://172.23.34.19:8180_ > Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.8.1.4) > Gecko/20070515 Firefox/2.0.0.4 - > > 5 juil. 2007 15:15:37 com.noelios.restlet.LogFilter afterHandle > INFO: 2007-07-05 15:15:37 172.23.34.19 - 172.23.34.19 8180 GET > /EventViewer/rest2/456 - 200 42 - 0 _http://172.23.34.19:8180_ > Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.8.1.4) > Gecko/20070515 Firefox/2.0.0.4 - > > -- > Julien Balas > JDAS Rennes >
RE: Re: Multiples rest service using multiples servlet in tomcat.
>The Restlet framework is throwing this error because, as it implies, >it cannot match the URI to anything that it has mapped. But it match the first servlet called And if I restart the tomcat server and call the 2nd servlet, the 2nd servlet works. > When I decompressed your WAR file, there is no web.xml in the main WEB-INF directory, > but rather in the EventViewer/WEB-INF, which I don't think Tomcat will find. I think the web.xml is in the right place as one of the servlet is working. And if I call a "foobar" servlet I get a tomcat error. And I don't get this tomcat error with any of my servlet. Did you try to deploy the war in tomcat ? Tested with tomcat 5.5 and 6.0. > Hopefully Jerome will correct me, but can you setup an Application per ServerServlet like this: I can't find any difference with the web.xml included in my war Except for the XML header. -- Julien Balas
Multiples rest service using multiples servlet in tomcat.
Hi I'm trying to have 2 servlets using 2 restlet in order to provide 2 REST services in the same tomcat. But I have a strange behavior. The first Servlet called works perfectly, but not the second one. For the second one, I get a "404 error", but not a "tomcat 404". If a call a non existing servlet I got a "tomcat 404", but my error is not this one, the message is "The server has not found anything matching the request URI You can get technical details here. Please continue your visit at our home page. " I tried to isolate as much as possible the issue, with a minimal example of 2 "Hello world" restlet. The full war (600Ko) is available at http://julien.balas.free.fr/EventViewer.war If anybody has a idea.. I guess it's a config issue because each servlet/restlet is working great if alone in a tomcat. The 2 classes are very minimal - [package and imports] public class Hello1 extends Application { public Hello1() { super(); } public Hello1(Context parentContext) { super(parentContext); } public Restlet createRoot() { Restlet restlet = new Restlet(getContext()) { @Override public void handle(Request request, Response response) { response.setEntity(new StringRepresentation(this.getClass().getName(), MediaType.TEXT_HTML)); } }; return restlet; } } The tomcat Logs are below - server startup - a successful call to "rest2" service - a 404 on "rest1" service - another successful call to "rest2" service INFO: Server startup in 4587 ms 5 juil. 2007 15:15:12 com.noelios.restlet.LogFilter afterHandle INFO: 2007-07-0515:15:12172.23.34.19- 172.23.34.198180GET /EventViewer/rest2/456 - 200 42 - 10 http://172.23.34.19:8180Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4 - 5 juil. 2007 15:15:16 com.noelios.restlet.LogFilter afterHandle INFO: 2007-07-0515:15:16172.23.34.19- 172.23.34.198180GET /EventViewer/rest1/456 - 404 331 - 0 http://172.23.34.19:8180Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4 - 5 juil. 2007 15:15:37 com.noelios.restlet.LogFilter afterHandle INFO: 2007-07-0515:15:37172.23.34.19- 172.23.34.198180GET /EventViewer/rest2/456 - 200 42 - 0 http://172.23.34.19:8180Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4 - -- Julien Balas JDAS Rennes
RE: Re: access local file in tomcat container
Thanks for the answer, the servletContextAdaptor completely filled my needs. Best regards, -- Julien Balas JDAS Rennes -Message d'origine- De : Thierry Boileau [mailto:[EMAIL PROTECTED] Envoyé : lundi 2 juillet 2007 22:58 À : discuss@restlet.tigris.org Objet : Re: access local file in tomcat container Hello Julien, if you want to access files that are located inside your "WebContent" directory, you can use the integrated war client just as follow: Representation rep = getContext().getDispatcher().get("war:///files/file.xml").getEntity(); and then use the representation as you want. NB: you can reuse parameters used for routing. For example, if your restlet has been reached according to the template "/segment/{myParameter}": Representation rep = getContext().getDispatcher().get("war:///files/file{myParameter}.xml").getEntity(); > What is the relationship between a restlet and a servlet ? none ? > The relation between a servlet and a restlet is made with the ServerServlet extension [1], and more precisely with the ServerServlet class which transmits servlet calls to your restlets, and the ServletContextAdapter that instantiates the war client and transmits all servlet context parameters to the restlet context parameters. > Is there a way to get to javax.servlet.ServletContext from an > org.restlet.Application ? > Here is the way to get the servletContext: ServletContextAdapter adapter = (ServletContextAdapter) getContext(); ServletContext servletContext = adapter.getServletContext(); Please feel free to ask for more details. Best regards, Thierry Boileau [1] http://www.restlet.org/documentation/1.0/ext/com/noelios/restlet/ext/servlet/package-summary.html
access local file in tomcat container
Hi, [note : I'm new to rest and restlet so my terminology may be not very good] I've created a rest service using restlet, it's working great when I use the integrated webserver. When I try to use my restlet in tomcat, it fail because it can't read a file on the disk. My class is called, with the right parameters extracted from the URL, so the mechanism seems to work. In my restlet I'm doing things like new File("/resources/schemas/blabla.xsd") But in tomcat, I get this error \resources\schemas\blabla.xsd (Le chemin d'accès spécifié est introuvable) [file not found in French] How can I find the physical name of a file in a restlet served by tomcat ? What is the relationship between a restlet and a servlet ? none ? Is there a way to get to javax.servlet.ServletContext from an org.restlet.Application ? Best Regards, -- Julien Balas JDAS Rennes