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
>

Reply via email to