Hi Jakob,
Thanks for your response.
The following 2 lines of code work perfectly according to my requirement of
forward.
*RequestDispatcher rd =
request.getRequestDispatcher("/content/geometrixx/en/products.html"); *//here
request is SlingHttpServletRequest since it is a sling servlet.
*rd.forward(request, response);*
this code properly resulting in forwarding the request to products page and
does not change the url in the browser.
*Also one more thing I wanted to discuss is the use of servlet vs filter.
Apache webserver hitting my servlet/filter which routes the calls
accordingly to webapp or forward to CQ page logic. I was not able to work
my request dispatcher code with Filter and shifted to Servlet. Does
exposing Servlet vis a vis filter to Apache webserver would have any
security implications?*
*I am not going the Resource route, as Iam not sure how to resolve the
resource with html extension. Only I am able to resolve until the node path
but not the extension .html path.,*
Resource resource =
slingRequest.getResourceResolver().getResource("/content/geometrixx/en/products");
RequestDispatcherOptions requestDispatcherOptions = new
RequestDispatcherOptions();
RequestDispatcher requestDispatcher =
slingRequest.getRequestDispatcher(resource,requestDispatcherOptions);
requestDispatcher.forward(slingRequest, response);
I am getting to that jcr node, but not able to render the products page.
What extra code handling do I need to do render the products,html page. It
is changing the url also in the browser.
*When I hit the servlet
http://localhost:4502/myvanity/forwardVanityresults in the change of
the browser url as
http://localhost:4502/content/geometrixx/en/products/ resulting in the
response as follows:*
products
- .. <http://localhost:4502/content/geometrixx/en>
-
jcr:content<http://localhost:4502/content/geometrixx/en/products/jcr:content>
- triangle<http://localhost:4502/content/geometrixx/en/products/triangle>
- square <http://localhost:4502/content/geometrixx/en/products/square>
- circle <http://localhost:4502/content/geometrixx/en/products/circle>
- mandelbrot<http://localhost:4502/content/geometrixx/en/products/mandelbrot>
Best Regards,
Durga
On Wed, May 2, 2012 at 9:34 PM, Jakob Külzer <[email protected]>wrote:
> Hmm, just from looking at the error message you're getting and the
> javadocs I'd say the problem is the actual path
> "/content/geometrixx/en/products.html". The javadocs for
> SlingHttpServletRequest.getRequestDispatcher(String,
> RequestDispatcherOptions) state:
>
> "Returns a RequestDispatcher object that acts as a wrapper for the
> resource located at the given path. A RequestDispatcher object can be
> used to include the resource in a response."
>
> As far as I see "/content/geometrixx/en/products.html" is not a valid
> path in the JCR, so try it without the .html extension:
> "/content/geometrixx/en/products".
>
> Hope that helps.
>
> Cheers,
> Jakob
>
>
> On Wed, May 2, 2012 at 10:25 PM, durga nuvvula <[email protected]>
> wrote:
> > Hi Jakob,
> >
> > Thanks for your response.
> >
> > First of all the pretty standard requestDispatcher, i was trying with
> > Filter.My filter was registered with Ext.HttpService and did not work.
> The
> > same code worked well with the Sling Servlet.
> >
> > ExtHttpService service = (ExtHttpService) context.getService(sRef);
> > service.registerFilter(new VanityUrlFilter(), "/testVanityFilter", null,
> 0,
> > null);
> > .
> >
> > public void doFilter(ServletRequest request, ServletResponse response,
> >
> > FilterChain chain) throws IOException, ServletException {
> >
> > RequestDispatcher requestDispatcher =
> > request.getRequestDispatcher("/content/geometrixx/en/products.html");
> >
> > requestDispatcher.forward(request, response);
> >
> > }
> >
> >
> > http://localhost:4502/testVanityFilter was yielding me the response
> >
> >
> >
> > *The requested URL /content/geometrixx/en/products.html was not found on
> > this server.*
> >
> >
> >
> > When I look into the logs, I could see this.
> >
> >
> >
> > *30.04.2012 12:39:44.854 *INFO* [0:0:0:0:0:0:0:1 [1335807584851] GET
> > /content/geometrixx/en/products.html HTTP/1.1]
> > org.apache.sling.engine.impl.SlingRequestProcessorImpl service: Resource
> > /testVanityFilter not found*
> >
> > *I have put the same code in the Sling Servlet and could see that the
> > request is forwarded to the products page successfully with no url change
> > in the browser which is desired behaviour.*
> >
> > My scenario is Apache server would hit my filter or servlet now, and
> > filter/servlet would look for whether its a CQ content page or my webapp
> > page and then if it is a CQ page, forward it to CQ page as above. Would
> > there be any difference from the security perspective to use the servlet
> > vis a vis filter.
> >
> > Second thing is I have found examples using the SlingHttpServletRequest
> and
> > the usage. I was not sure how to call the
> content/geometrixx/en/products.html.
> > Of course with out using the SlingHttpServletRequest also I am able to
> > serve the same using servletRequest object.
> >
> > I just want to deal with CQ pages using SlingHttpServletRequest and was
> not
> > able to solve with SlingHttpServletRequest.
> >
> > SlingHttpServletRequest slingRequest = (SlingHttpServletRequest)request;
> >
> > Resource resource =
> > slingRequest.getResourceResolver().getResource("/content/geometrixx/e
> > n/products.html");
> >
> > RequestDispatcherOptions requestDispatcherOptions = new
> > RequestDispatcherOptions();
> >
> > RequestDispatcher requestDispatcher =
> > slingRequest.getRequestDispatcher(resource,requestDispatcherOptions);
> >
> > Best Regards,
> > Durga
> >
> > On Wed, May 2, 2012 at 9:16 PM, Jakob Külzer <[email protected]
> >wrote:
> >
> >> Hello Durga,
> >>
> >> What error are you getting? Can you post the stacktrace, that would
> >> help finding the error tremendously.
> >>
> >> Cheers,
> >> Jakob
> >>
> >> On Tue, May 1, 2012 at 6:24 PM, durga nuvvula <[email protected]>
> >> wrote:
> >> > Hello Team,
> >> >
> >> >
> >> > I am getting 500 error on using the SlingHttpServletRequest
> >> requestDispatcher
> >> > forward. Please suggest. My requirement is to forward the request to
> that
> >> > page once the request comes to filter and filter identifies that as a
> CQ
> >> > content landing page. I am relatively new using sling and CQ. please
> >> help.
> >> >
> >> >
> >> >
> >> > public void doFilter(ServletRequest request, ServletResponse response,
> >> >
> >> > FilterChain chain) throws IOException,
> >> > ServletException {
> >> >
> >> >
> >> > SlingHttpServletRequest slingRequest =
> >> > (SlingHttpServletRequest)request; RequestDispatcherOptions
> >> > requestDispatcherOptions = new RequestDispatcherOptions();
> >> > RequestDispatcher requestDispatcher =
> >> >
> >>
> slingRequest.getRequestDispatcher("/content/geometrixx/en/products.html",requestDispatcherOptions);
> >> > requestDispatcher.forward(request, response);
> >> >
> >> > }
> >> >
> >> >
> >> >
> >> > I have looked into the docuemntation for SlingHttpServletRequest to
> get
> >> the
> >> > dispatcher. but there are no examples as such.
> >> >
> >> >
> >> >
> >> >
> http://dev.day.com/docs/en/cq/current/javadoc/org/apache/sling/api/Sli
> >> > ngHttpServletRequest.html#getRequestDispatcher(org.apache.sling.api.r
> e
> >> > source.Resource,
> >> > org.apache.sling.api.request.RequestDispatcherOptions)<
> >>
> http://dev.day.com/docs/en/cq/current/javadoc/org/apache/sling/api/SlingHttpServletRequest.html#getRequestDispatcher(org.apache.sling.api.resource.Resource,%20org.apache.sling.api.request.RequestDispatcherOptions)
> >> >
> >> >
> >> >
> >> >
> >> > I have looked into the documentation of the sling servlet
> registration to
> >> > understand the terms path, selectors, extensions etc.
> >> >
> >> >
> >> >
> >> > sling.servlet.paths = [ "/libs/sling/sample/html",
> >> > "/libs/sling/sample/txt" ] sling.servlet.resourceTypes = [
> >> > "sling/unused" ] sling.servlet.selectors = [ "img" ]
> >> > sling.servlet.extensions = [ "html", "txt", "json" ]
> >> >
> >> > A Servlet service registered with these properties is registered under
> >> the
> >> > following paths:
> >> >
> >> > - /libs/sling/sample/html
> >> > - /libs/sling/sample/txt
> >> >
> >> >
> >> > RequestDispatcher<
> >>
> http://docs.oracle.com/javaee/1.4/api/javax/servlet/RequestDispatcher.html?is-external=true
> >> >
> >> > *getRequestDispatcher<
> >>
> http://dev.day.com/docs/en/cq/current/javadoc/org/apache/sling/api/SlingHttpServletRequest.html#getRequestDispatcher(org.apache.sling.api.resource.Resource)
> >> >
> >> > *(Resource<
> >>
> http://dev.day.com/docs/en/cq/current/javadoc/org/apache/sling/api/resource/Resource.html
> >> >
> >> > resource)
> >> > Same as
> >> > getRequestDispatcher(Resource,RequestDispatcherOptions)<
> >>
> http://dev.day.com/docs/en/cq/current/javadoc/org/apache/sling/api/SlingHttpServletRequest.html#getRequestDispatcher(org.apache.sling.api.resource.Resource,%20org.apache.sling.api.request.RequestDispatcherOptions)
> >> >
> >> > but
> >> > using empty options.RequestDispatcher<
> >>
> http://docs.oracle.com/javaee/1.4/api/javax/servlet/RequestDispatcher.html?is-external=true
> >> >
> >> > *getRequestDispatcher<
> >>
> http://dev.day.com/docs/en/cq/current/javadoc/org/apache/sling/api/SlingHttpServletRequest.html#getRequestDispatcher(org.apache.sling.api.resource.Resource,%20org.apache.sling.api.request.RequestDispatcherOptions)
> >> >
> >> > *(Resource<
> >>
> http://dev.day.com/docs/en/cq/current/javadoc/org/apache/sling/api/resource/Resource.html
> >> >
> >> > resource, RequestDispatcherOptions<
> >>
> http://dev.day.com/docs/en/cq/current/javadoc/org/apache/sling/api/request/RequestDispatcherOptions.html
> >> >
> >> > options)
> >> > Returns a RequestDispatcher object that acts as a wrapper for
> >> the
> >> > resource located at the given
> >> > resource.RequestDispatcher<
> >>
> http://docs.oracle.com/javaee/1.4/api/javax/servlet/RequestDispatcher.html?is-external=true
> >> >
> >> > *getRequestDispatcher<
> >>
> http://dev.day.com/docs/en/cq/current/javadoc/org/apache/sling/api/SlingHttpServletRequest.html#getRequestDispatcher(java.lang.String,%20org.apache.sling.api.request.RequestDispatcherOptions)
> >> >
> >> > *(String<
> >>
> http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/String.html?is-external=true
> >> >
> >> > path, RequestDispatcherOptions<
> >>
> http://dev.day.com/docs/en/cq/current/javadoc/org/apache/sling/api/request/RequestDispatcherOptions.html
> >> >
> >> > options)
> >> > Returns a RequestDispatcher object that acts as a wrapper for
> >> the
> >> > resource located at the given path.
> >> >
> >> >
> >> >
> >> >
> >> >
> >> > I have tried first 2 api's
> >> >
> >> >
> >> >
> >> > SlingHttpServletRequest slingRequest =
> (SlingHttpServletRequest)request;
> >> >
> >> > Resource resource =
> >> > slingRequest.getResourceResolver().getResource("/content/geometrixx/e
> >> > n/products.html");
> >> >
> >> > RequestDispatcherOptions requestDispatcherOptions = new
> >> > RequestDispatcherOptions();
> >> >
> >> > RequestDispatcher requestDispatcher =
> >> > slingRequest.getRequestDispatcher(resource,requestDispatcherOptions);
> >> >
> >> >
> >> > Also tried the 3rd api above in the doFilter code.
> >> >
> >> >
> >> >
> >> > Should I give the path in the resource with html extension.
> >> >
> >> >
> >> >
> >> > Any pointers/suggestions to solve this requestDispatcher forward
> would be
> >> > appreciable.
> >> >
> >> >
> >> > --Durga
> >>
> >>
> >>
> >> --
> >> Cheers,
> >> Jakob
> >>
>
>
>
> --
> Cheers,
> Jakob
>