You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@felix.apache.org by durga nuvvula <du...@gmail.com> on 2012/05/02 00:25:11 UTC

Problem with SlingHttpServletRequest requestDispatcher forward. pls assist

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