Hi Jakob, Yes that is exactly what it is. So while trying to resolve a servlet/script for the resource, sling would use the resourceType value specified in the requestDispatcherOptions instead of the value specified in the resource.
Cheers, Igor. pro!vision GmbH Telefon +49 (69) 8700328-21 Geschäftsführer: Karim Khan, Stefan Seifert Sitz der Gesellschaft: Berlin AG Charlottenburg, HRB78141, USt-IdNr. DE209954974 >-----Original Message----- >From: Jakob Külzer [mailto:[email protected]] >Sent: Wednesday, April 18, 2012 9:19 PM >To: [email protected] >Subject: Re: Using Filter and RequestDispatcher to substitute responses > >Hello Igor, > >thank you for your response. I've looked at the >RequestDispatcherOptions object. However the docs are not quite clear >to me, it says "resource type". Does this refer to a Sling >resourceType, like "myapp/components/comp"? > >On Wed, Apr 18, 2012 at 3:17 AM, Igor Sechyn <[email protected]> >wrote: >> Hi Jakob, >> >> You might want to have a look at the >> >> - getRequestDispatcher(Resource resource, RequestDispatcherOptions >options) >> >> method of the SlingHttpServletRequest. In the options you can actually >force a resource type, which will be used during dispatching instead of the >value in your original resource. >> >> Cheers, Igor. >> >> >> pro!vision GmbH >> Telefon +49 (69) 8700328-21 >> Geschäftsführer: Karim Khan, Stefan Seifert >> Sitz der Gesellschaft: Berlin >> AG Charlottenburg, HRB78141, USt-IdNr. DE209954974 >> >> >>>-----Original Message----- >>>From: Jakob Külzer [mailto:[email protected]] >>>Sent: Tuesday, April 17, 2012 11:06 PM >>>To: [email protected] >>>Subject: Using Filter and RequestDispatcher to substitute responses >>> >>>Hello everybody, >>> >>>I'm just starting to get my head wrapped around Sling and Day CQ 5 and >>>I'm running against an issue that I don't really understand properly. >>>I'm still quite new to Sling, so if you see something where I've got >>>an incorrect understanding feel free to jump in and correct me. >>>Thanks! >>> >>>What I am trying to do is to replace certain request with output from >>>a different JSP. For example, a page contains an embedded component >>>which, as far as I understand, is referenced via a Sling resourceType. >>>When Sling renders this page, the JSP will be included; however, based >>>on certain conditions I'd like to render a different JSP. My naive >>>approach is to register a filter in the include chain, create a >>>RequestDispatcher for the new JSP and call the include() method. >>> >>>My first question is, am I using the appropriate approach for this? >>>Should I look at another mechanism in Sling to do something like this? >>> >>>Second, assuming a filter is the correct approach, why does it not >>>render my JSP? >>> >>>Here're the relevant lines of code: >>> >>>---->8-------------------------------------------------------------- >>>@org.apache.felix.scr.annotations.Component(immediate = true, >metatype = >>>false) >>>@Service(Filter.class) >>>@Properties({ @Property(name = "sling.filter.scope", value = { >>>"include", "forward" }) }) >>>public class ComponentFilter implements Filter { >>> >>> public void doFilter(ServletRequest request, ServletResponse >>>response, FilterChain chain) throws IOException, ServletException { >>> final SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) >>>request; >>> final Resource resource = ...; // Get resource for the JSP. >>> if (localResource != null) { >>> final RequestDispatcher requestDispatcher = >>>slingRequest.getRequestDispatcher(resource); >>> requestDispatcher.include(request, response); >>> } else { >>> chain.doFilter(request, response); >>> } >>> } >>> >>>} >>>---->8-------------------------------------------------------------- >>> >>>The resource is properly resolved: >>> >>>*DEBUG* script: JcrNodeResource, type=nt:file, superType=null, >>>path=/apps/myapp/components/demo/replacment.jsp >>> >>>However, I get this error: >>> >>>17.04.2012 16:13:53.136 *ERROR* [127.0.0.1 [1334693633099] GET >>>/content/geometrixx/en/test.html HTTP/1.1] >>>org.apache.sling.servlets.get.impl.DefaultGetServlet No renderer for >>>extension html, cannot render resource JcrNodeResource, type=nt:file, >>>superType=null, path=/apps/myapp/components/demo/replacment.jsp >>> >>>I'm not sure what to make of this. Any ideas? >>> >>>Any help is appreciated! Thank you. >>> >>> >>>-- >>>Cheers, >>>Jakob > > > >-- >Cheers, >Jakob
