RE: spring context - webapplication context in restlet 2
This worked for me. Thanks Jerome. -Arthur Hi there, I've just tried the following code with the latest from SVN trunk: package test; import javax.servlet.ServletContext; import org.restlet.Application; import org.restlet.Request; import org.restlet.Response; import org.restlet.data.MediaType; public class MyApplication1 extends Application { @Override public void handle(Request request, Response response) { ServletContext sc = (ServletContext) getContext().getAttributes().get( org.restlet.ext.servlet.ServletContext); response.setEntity(hello1: + sc.getServerInfo(), MediaType.TEXT_PLAIN); } } And it displayed the following in my browser: hello1: Apache Tomcat/6.0.18 I guess, you might be using an older version of Restlet without the fix. Could you try again with a recent snapshot? Note that while fixing a life cycle issue on 10/28, I broke ServerServlet. This has just been fixed in SVN trunk today, but this wasn't related to ServletContext however. Best regards, Jerome Louvel -- Restlet ~ Founder and Lead developer ~ http://www.restlet.org Noelios Technologies ~ Co-founder ~ http://www.noelios.com -Message d'origine- De : webp...@tigris.org [mailto:webp...@tigris.org] Envoyé : vendredi 16 octobre 2009 15:06 À : discuss@restlet.tigris.org Objet : RE: spring context - webapplication context in restlet 2 No, it doesn't work. I have some spring beans I exported to the servlet context. In my debugger, I can see that the context.parentContext.attributes does contain my exported beans but I can't get to them through the api. -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=24082 15 -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2614562
RE: spring context - webapplication context in restlet 2
Hi there, I've just tried the following code with the latest from SVN trunk: package test; import javax.servlet.ServletContext; import org.restlet.Application; import org.restlet.Request; import org.restlet.Response; import org.restlet.data.MediaType; public class MyApplication1 extends Application { @Override public void handle(Request request, Response response) { ServletContext sc = (ServletContext) getContext().getAttributes().get( org.restlet.ext.servlet.ServletContext); response.setEntity(hello1: + sc.getServerInfo(), MediaType.TEXT_PLAIN); } } And it displayed the following in my browser: hello1: Apache Tomcat/6.0.18 I guess, you might be using an older version of Restlet without the fix. Could you try again with a recent snapshot? Note that while fixing a life cycle issue on 10/28, I broke ServerServlet. This has just been fixed in SVN trunk today, but this wasn't related to ServletContext however. Best regards, Jerome Louvel -- Restlet ~ Founder and Lead developer ~ http://www.restlet.org Noelios Technologies ~ Co-founder ~ http://www.noelios.com -Message d'origine- De : webp...@tigris.org [mailto:webp...@tigris.org] Envoyé : vendredi 16 octobre 2009 15:06 À : discuss@restlet.tigris.org Objet : RE: spring context - webapplication context in restlet 2 No, it doesn't work. I have some spring beans I exported to the servlet context. In my debugger, I can see that the context.parentContext.attributes does contain my exported beans but I can't get to them through the api. -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=24082 15 -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2413654
RE: spring context - webapplication context in restlet 2
No, it doesn't work. I have some spring beans I exported to the servlet context. In my debugger, I can see that the context.parentContext.attributes does contain my exported beans but I can't get to them through the api. -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2408215
RE: spring context - webapplication context in restlet 2
Hi Rahul, In Restlet 2.0, the ServletContext is copied into an org.restlet.ext.servlet.ServletContext attribute of the Restlet application attached to the ServerServlet. You should be able to retrieve it this way: ServletContext sc = (ServletContext) getContext().getAttributes().get(org.restlet.ext.servlet.ServletContext); Let us know if it doesnt work. Best regards, Jerome Louvel -- Restlet ~ Founder and Lead developer ~ http://www.restlet.org/ http://www.restlet.org Noelios Technologies ~ Co-founder ~ http://www.noelios.com/ http://www.noelios.com De : Rahul Juneja [mailto:rahul.jun...@thoughtclicks.com] Envoyé : mercredi 16 septembre 2009 03:16 À : discuss@restlet.tigris.org Objet : Re: spring context - webapplication context in restlet 2 Rhett, But still i guess its good to have an interface or something which can have an implementation in case we are running within the container. maybe inside the jee version of the restlet. Thanks, Rahul On Tue, Sep 15, 2009 at 2:32 PM, Rhett Sutphin rh...@detailedbalance.net wrote: Hi Rahul, On Sep 15, 2009, at 8:54 AM, Rahul Juneja wrote: Rhett, I tried the following things in ServerResource File. anyways thats ok but i have a question about why Restlet doesn't expose the Servlet context which is one of the attributes added to the context of the application. org.restlet.ext.servlet.ServletContext ? Do you mean why doesn't Restlet expose the ServletContext in the ServerResource API? Because that would create a dependency in Restlet core on a JEE class. Restlet core is designed to run without JEE. Rhett Thanks, Rahul On Mon, Sep 14, 2009 at 5:39 PM, Rhett Sutphin rh...@detailedbalance.net wrote: Hi Rahul, On Sep 13, 2009, at 11:39 AM, Rahul Juneja wrote: I wanted to get some spring injected beans in my resource file. and i have looked at the integration with spring in other ways but i would not be very interested in that as i want to keep spring separate from restlet. Also i am aware of the concern that this way my application will be tied to Servlet api. but i think i am fine with that as i will be running on tomcat only. I looked at SpringServerServlet and tried calling getWebApplicationContext() or getServletContext() but in both the cases i am getting exception. I did not do anything else. except calling this method from the resource file. Is there any other steps i need to follow to get the springContext or webappllication context to get the beans from the spring. getServletContext() inside a servlet is provided by the JEE API. If that's throwing an exception, you have a non-restlet-related problem. I'm not so familiar with SpringServerServlet, but it appears that it is loading the spring application context from the standard (for spring) JEE location. Are you loading the application context using ContextLoaderListener? You might also try out RestletFrameworkServlet. It allows you to configure restlet in approximately the same way you configure Spring MVC. Again, though, if you can't invoke getServletContext() from inside a servlet, none of these solutions are going to work for you. Rhett -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447 http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2394 793 dsMessageId=2394793 -- Rahul Juneja Phone : (631) 681-9996 Fax : (206) 339-9047 http://techlabs.thoughtclicks.com http://finance.thoughtclicks.com --- The thing always happens that you really believe in; and the belief in a thing makes it happen. -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447 http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2395 203 dsMessageId=2395203 -- Rahul Juneja Phone : (631) 681-9996 Fax : (206) 339-9047 http://techlabs.thoughtclicks.com http://finance.thoughtclicks.com --- The thing always happens that you really believe in; and the belief in a thing makes it happen. -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2402833
Re: spring context - webapplication context in restlet 2
Rhett, But still i guess its good to have an interface or something which can have an implementation in case we are running within the container. maybe inside the jee version of the restlet. Thanks, Rahul On Tue, Sep 15, 2009 at 2:32 PM, Rhett Sutphin rh...@detailedbalance.netwrote: Hi Rahul, On Sep 15, 2009, at 8:54 AM, Rahul Juneja wrote: Rhett, I tried the following things in ServerResource File. anyways thats ok but i have a question about why Restlet doesn't expose the Servlet context which is one of the attributes added to the context of the application. org.restlet.ext.servlet.ServletContext ? Do you mean why doesn't Restlet expose the ServletContext in the ServerResource API? Because that would create a dependency in Restlet core on a JEE class. Restlet core is designed to run without JEE. Rhett Thanks, Rahul On Mon, Sep 14, 2009 at 5:39 PM, Rhett Sutphin rh...@detailedbalance.net wrote: Hi Rahul, On Sep 13, 2009, at 11:39 AM, Rahul Juneja wrote: I wanted to get some spring injected beans in my resource file. and i have looked at the integration with spring in other ways but i would not be very interested in that as i want to keep spring separate from restlet. Also i am aware of the concern that this way my application will be tied to Servlet api. but i think i am fine with that as i will be running on tomcat only. I looked at SpringServerServlet and tried calling getWebApplicationContext() or getServletContext() but in both the cases i am getting exception. I did not do anything else. except calling this method from the resource file. Is there any other steps i need to follow to get the springContext or webappllication context to get the beans from the spring. getServletContext() inside a servlet is provided by the JEE API. If that's throwing an exception, you have a non-restlet-related problem. I'm not so familiar with SpringServerServlet, but it appears that it is loading the spring application context from the standard (for spring) JEE location. Are you loading the application context using ContextLoaderListener? You might also try out RestletFrameworkServlet. It allows you to configure restlet in approximately the same way you configure Spring MVC. Again, though, if you can't invoke getServletContext() from inside a servlet, none of these solutions are going to work for you. Rhett -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2394793 -- Rahul Juneja Phone : (631) 681-9996 Fax : (206) 339-9047 http://techlabs.thoughtclicks.com http://finance.thoughtclicks.com --- The thing always happens that you really believe in; and the belief in a thing makes it happen. -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2395203 -- Rahul Juneja Phone : (631) 681-9996 Fax : (206) 339-9047 http://techlabs.thoughtclicks.com http://finance.thoughtclicks.com --- The thing always happens that you really believe in; and the belief in a thing makes it happen. -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2395315
Re: spring context - webapplication context in restlet 2
Rhett, I tried the following things in ServerResource File. anyways thats ok but i have a question about why Restlet doesn't expose the Servlet context which is one of the attributes added to the context of the application. org.restlet.ext.servlet.ServletContext ? Thanks, Rahul On Mon, Sep 14, 2009 at 5:39 PM, Rhett Sutphin rh...@detailedbalance.netwrote: Hi Rahul, On Sep 13, 2009, at 11:39 AM, Rahul Juneja wrote: I wanted to get some spring injected beans in my resource file. and i have looked at the integration with spring in other ways but i would not be very interested in that as i want to keep spring separate from restlet. Also i am aware of the concern that this way my application will be tied to Servlet api. but i think i am fine with that as i will be running on tomcat only. I looked at SpringServerServlet and tried calling getWebApplicationContext() or getServletContext() but in both the cases i am getting exception. I did not do anything else. except calling this method from the resource file. Is there any other steps i need to follow to get the springContext or webappllication context to get the beans from the spring. getServletContext() inside a servlet is provided by the JEE API. If that's throwing an exception, you have a non-restlet-related problem. I'm not so familiar with SpringServerServlet, but it appears that it is loading the spring application context from the standard (for spring) JEE location. Are you loading the application context using ContextLoaderListener? You might also try out RestletFrameworkServlet. It allows you to configure restlet in approximately the same way you configure Spring MVC. Again, though, if you can't invoke getServletContext() from inside a servlet, none of these solutions are going to work for you. Rhett -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2394793 -- Rahul Juneja Phone : (631) 681-9996 Fax : (206) 339-9047 http://techlabs.thoughtclicks.com http://finance.thoughtclicks.com --- The thing always happens that you really believe in; and the belief in a thing makes it happen. -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2395087
Re: spring context - webapplication context in restlet 2
Hi Rahul, On Sep 15, 2009, at 8:54 AM, Rahul Juneja wrote: Rhett, I tried the following things in ServerResource File. anyways thats ok but i have a question about why Restlet doesn't expose the Servlet context which is one of the attributes added to the context of the application. org.restlet.ext.servlet.ServletContext ? Do you mean why doesn't Restlet expose the ServletContext in the ServerResource API? Because that would create a dependency in Restlet core on a JEE class. Restlet core is designed to run without JEE. Rhett Thanks, Rahul On Mon, Sep 14, 2009 at 5:39 PM, Rhett Sutphin rh...@detailedbalance.net wrote: Hi Rahul, On Sep 13, 2009, at 11:39 AM, Rahul Juneja wrote: I wanted to get some spring injected beans in my resource file. and i have looked at the integration with spring in other ways but i would not be very interested in that as i want to keep spring separate from restlet. Also i am aware of the concern that this way my application will be tied to Servlet api. but i think i am fine with that as i will be running on tomcat only. I looked at SpringServerServlet and tried calling getWebApplicationContext() or getServletContext() but in both the cases i am getting exception. I did not do anything else. except calling this method from the resource file. Is there any other steps i need to follow to get the springContext or webappllication context to get the beans from the spring. getServletContext() inside a servlet is provided by the JEE API. If that's throwing an exception, you have a non-restlet-related problem. I'm not so familiar with SpringServerServlet, but it appears that it is loading the spring application context from the standard (for spring) JEE location. Are you loading the application context using ContextLoaderListener? You might also try out RestletFrameworkServlet. It allows you to configure restlet in approximately the same way you configure Spring MVC. Again, though, if you can't invoke getServletContext() from inside a servlet, none of these solutions are going to work for you. Rhett -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2394793 -- Rahul Juneja Phone : (631) 681-9996 Fax : (206) 339-9047 http://techlabs.thoughtclicks.com http://finance.thoughtclicks.com --- The thing always happens that you really believe in; and the belief in a thing makes it happen. -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2395203
spring context - webapplication context in restlet 2
I wanted to get some spring injected beans in my resource file. and i have looked at the integration with spring in other ways but i would not be very interested in that as i want to keep spring separate from restlet. Also i am aware of the concern that this way my application will be tied to Servlet api. but i think i am fine with that as i will be running on tomcat only. I looked at SpringServerServlet and tried calling * getWebApplicationContexthttp://www.restlet.org/documentation/snapshot/ext/org/restlet/ext/spring/SpringServerServlet.html#getWebApplicationContext() *() or getServletContexthttp://java.sun.com/javaee/5/docs/api/javax/servlet/GenericServlet.html#getServletContext()() but in both the cases i am getting exception. I did not do anything else. except calling this method from the resource file. Is there any other steps i need to follow to get the springContext or webappllication context to get the beans from the spring. Any help on this is highly appreciated. Thanks, Rahul -- Rahul Juneja http://techlabs.thoughtclicks.com http://finance.thoughtclicks.com --- The thing always happens that you really believe in; and the belief in a thing makes it happen. -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2394316