Mail sent on the 09/02 and apparently lost.
---

Hello Marc,
from what I see in the code, the ServletContextAdapter is automatically passed to the single application created when the default component is used (that is to say when you are in mode 3, see [1]).
So, I think that you have your own component. Its it right?
In this case, I think I have a trick for you.
The problem is that you want to set your own kind of context to any applications attached to the component. The context of an attached application is created by calling the "createChildContext" from the component's context.
Thus, you have to define your own Context class that inherits from Context and override the "createChildContext" in order to provide a ServletContextAdapter. The component's context will be an instance of such new context.
Tell me if my explanations are not clear.

I have a question for you, since I'm not sure to fully understand your need. Why do you need to access the servlet context?
The problem is that it make your application dependent on the servlet technology which avoids you to reuse your Restlet application as a standalone application. 
>Is this a bug or 'by design'? ;)
I think it's due to recent updates made in the purpose to isolate the context of the parent component from contexts of the attached restlets. It avoids an application to update the parent's context. 

   Best regards,
   Thierry Boileau
   --
      Restlet ~ Core developer ~ http://www.restlet.org
      Noelios Technologies ~ Co-founder ~ http://www.noelios.com
[1] http://www.restlet.org/documentation/1.1/ext/com/noelios/restlet/ext/servlet/ServerServlet.html 

Hi,

I've tried to get the ServletContext (for using the freemarker
TemplateResource). For the 1.0.xx it works this way (I think it has done
it in M5 also but I'm not sure):

ServletContext servletContext =
((ServletContextAdapter)this.getContext()).getServletContext();

Now I get a:
org.restlet.Context cannot be cast to
com.noelios.restlet.ext.servlet.ServletContextAdapter

Stacktrace:
01.09.2008 23:25:44 org.apache.catalina.core.ApplicationContext log
SCHWERWIEGEND: Unhandled exception or error intercepted
java.lang.ClassCastException: org.restlet.Context cannot be cast to
com.noelios.restlet.ext.servlet.ServletContextAdapter
	at itf.web.BaseResource.<init>(BaseResource.java:25)
	at
itf.web.IndexStaticContentResource.<init>(IndexStaticContentResource.java:27)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
	at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
	at org.restlet.Finder.createTarget(Finder.java:186)
	at org.restlet.Finder.createTarget(Finder.java:224)
	at org.restlet.Finder.findTarget(Finder.java:238)
	at org.restlet.Finder.handle(Finder.java:327)
	at org.restlet.Filter.doHandle(Filter.java:150)
	at org.restlet.Filter.handle(Filter.java:193)
	at org.restlet.Router.handle(Router.java:502)
	at org.restlet.Filter.doHandle(Filter.java:150)
	at org.restlet.Filter.handle(Filter.java:193)
	at org.restlet.Filter.doHandle(Filter.java:150)
	at org.restlet.Filter.handle(Filter.java:193)
	at org.restlet.Filter.doHandle(Filter.java:150)
	at com.noelios.restlet.StatusFilter.doHandle(StatusFilter.java:130)
	at org.restlet.Filter.handle(Filter.java:193)
	at org.restlet.Filter.doHandle(Filter.java:150)
	at org.restlet.Filter.handle(Filter.java:193)
	at com.noelios.restlet.ChainHelper.handle(ChainHelper.java:124)
	at
com.noelios.restlet.application.ApplicationHelper.handle(ApplicationHelper.java:112)
	at org.restlet.Application.handle(Application.java:342)
	at org.restlet.Filter.doHandle(Filter.java:150)
	at org.restlet.Filter.handle(Filter.java:193)
	at org.restlet.Router.handle(Router.java:502)
	at org.restlet.Filter.doHandle(Filter.java:150)
	at org.restlet.Filter.handle(Filter.java:193)
	at org.restlet.Router.handle(Router.java:502)
	at org.restlet.Filter.doHandle(Filter.java:150)
	at org.restlet.Filter.handle(Filter.java:193)
	at com.noelios.restlet.ChainHelper.handle(ChainHelper.java:124)
	at org.restlet.Component.handle(Component.java:875)
	at org.restlet.Server.handle(Server.java:331)
	at com.noelios.restlet.ServerHelper.handle(ServerHelper.java:68)
	at
com.noelios.restlet.http.HttpServerHelper.handle(HttpServerHelper.java:146)
	at
com.noelios.restlet.ext.servlet.ServerServlet.service(ServerServlet.java:765)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
	at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at
org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:112)
	at
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
	at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
	at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
	at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
	at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
	at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
	at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
	at java.lang.Thread.run(Thread.java:619)
01.09.2008 23:25:44 com.noelios.restlet.LogFilter afterHandle
INFO: 2008-09-01	23:25:44	127.0.0.1	-	127.0.0.1	8080	GET
/itf-web/	-	500	363	-	16	http://localhost:8080	Mozilla/5.0 (Windows; U;
Windows NT 5.1; de; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1	-

Is this a bug or 'by design'? ;)

Marc

Reply via email to