Uploaded image for project: 'Sling'
  1. Sling
  2. SLING-11569

Response created with Builders.newResponseBuilder() does not work with RequestDispatcher.include

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • Engine 2.10.2
    • Engine 2.11.0
    • Engine
    • None

    Description

      scenario:

      • we want to use RequestDispatcher.include to include the output of another servlet running in sling to include it's output in the output of the current servlet
      • but this should not be done by passing the response of the current servlet directly into the request dispatcher, but by using a "synthetic response" created with the new Builders.newResponseBuilder feature to be able to validate or post-process the output of the other servlet.
      • when doing this, the include on request dispatcher failes with an exception " SlingHttpServletResponse not of correct type"

      full strack trace:

      java.lang.IllegalArgumentException: SlingHttpServletResponse not of correct type
      	at org.apache.sling.engine.impl.request.RequestData.unwrap(RequestData.java:430)
      	at org.apache.sling.engine.impl.request.RequestData.toSlingHttpServletResponse(RequestData.java:507)
      	at org.apache.sling.engine.impl.SlingRequestProcessorImpl.dispatchRequest(SlingRequestProcessorImpl.java:315)
      	at org.apache.sling.engine.impl.request.SlingRequestDispatcher.dispatch(SlingRequestDispatcher.java:218)
      	at org.apache.sling.engine.impl.request.SlingRequestDispatcher.include(SlingRequestDispatcher.java:104)
      	at org.apache.sling.launchpad.testservices.servlets.requestdispatcher.RequestDispatcherIncludeBufferedServlet.doGet(RequestDispatcherIncludeBufferedServlet.java:64)
      	at org.apache.sling.api.servlets.SlingSafeMethodsServlet.mayService(SlingSafeMethodsServlet.java:266)
      	at org.apache.sling.api.servlets.SlingSafeMethodsServlet.service(SlingSafeMethodsServlet.java:342)
      	at org.apache.sling.api.servlets.SlingSafeMethodsServlet.service(SlingSafeMethodsServlet.java:374)
      	at org.apache.sling.engine.impl.request.RequestData.service(RequestData.java:587)
      	at org.apache.sling.engine.impl.filter.SlingComponentFilterChain.render(SlingComponentFilterChain.java:45)
      	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:88)
      	at org.apache.sling.engine.impl.SlingRequestProcessorImpl.processComponent(SlingRequestProcessorImpl.java:284)
      	at org.apache.sling.engine.impl.filter.RequestSlingFilterChain.render(RequestSlingFilterChain.java:49)
      	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:82)
      	at org.apache.sling.launchpad.testservices.filters.TestFilter.doFilter(TestFilter.java:47)
      	at org.apache.sling.launchpad.testservices.filters.SlingFilter.doFilter(SlingFilter.java:22)
      	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78)
      	at org.apache.sling.launchpad.testservices.filters.TestFilter.doFilter(TestFilter.java:47)
      	at org.apache.sling.launchpad.testservices.filters.NoPropertyFilter.doFilter(NoPropertyFilter.java:22)
      	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78)
      	at org.apache.sling.engine.impl.debug.RequestProgressTrackerLogFilter.doFilter(RequestProgressTrackerLogFilter.java:109)
      	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78)
      	at org.apache.sling.i18n.impl.I18NFilter.doFilter(I18NFilter.java:131)
      	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78)
      	at com.composum.sling.nodes.mount.remote.RemoteRequestFilter.doFilter(RemoteRequestFilter.java:76)
      	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78)
      	at org.apache.sling.engine.impl.SlingRequestProcessorImpl.doProcessRequest(SlingRequestProcessorImpl.java:149)
      	at org.apache.sling.engine.impl.SlingMainServlet.service(SlingMainServlet.java:251)
      	at org.apache.felix.http.base.internal.handler.ServletHandler.handle(ServletHandler.java:126)
      	at org.apache.felix.http.base.internal.dispatch.InvocationChain.doFilter(InvocationChain.java:86)
      	at org.apache.sling.junit.impl.servlet.TestLogServlet$TestNameLoggingFilter.doFilter(TestLogServlet.java:250)
      	at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:142)
      	at org.apache.felix.http.base.internal.dispatch.InvocationChain.doFilter(InvocationChain.java:81)
      	at org.apache.sling.i18n.impl.I18NFilter.doFilter(I18NFilter.java:131)
      	at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:142)
      	at org.apache.felix.http.base.internal.dispatch.InvocationChain.doFilter(InvocationChain.java:81)
      	at org.apache.sling.engine.impl.log.RequestLoggerFilter.doFilter(RequestLoggerFilter.java:73)
      	at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:142)
      	at org.apache.felix.http.base.internal.dispatch.InvocationChain.doFilter(InvocationChain.java:81)
      	at org.apache.sling.engine.impl.parameters.RequestParameterSupportConfigurer.doFilter(RequestParameterSupportConfigurer.java:67)
      	at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:142)
      	at org.apache.felix.http.base.internal.dispatch.InvocationChain.doFilter(InvocationChain.java:81)
      	at org.apache.felix.http.base.internal.dispatch.Dispatcher$1.doFilter(Dispatcher.java:152)
      	at org.apache.felix.http.base.internal.whiteboard.WhiteboardManager$2.doFilter(WhiteboardManager.java:1002)
      	at org.apache.felix.http.sslfilter.internal.SslFilter.doFilter(SslFilter.java:97)
      	at org.apache.felix.http.base.internal.handler.PreprocessorHandler.handle(PreprocessorHandler.java:137)
      	at org.apache.felix.http.base.internal.whiteboard.WhiteboardManager$2.doFilter(WhiteboardManager.java:1008)
      	at org.apache.felix.http.base.internal.whiteboard.WhiteboardManager.invokePreprocessors(WhiteboardManager.java:1012)
      	at org.apache.felix.http.base.internal.dispatch.Dispatcher.dispatch(Dispatcher.java:94)
      	at org.apache.felix.http.base.internal.dispatch.DispatcherServlet.service(DispatcherServlet.java:49)
      	at javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
      	at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:799)
      	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:550)
      	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233)
      	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1624)
      	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233)
      	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1434)
      	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188)
      	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:501)
      	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1594)
      	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186)
      	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1349)
      	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
      	at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:191)
      	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
      	at org.eclipse.jetty.server.Server.handle(Server.java:516)
      	at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:400)
      	at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:645)
      	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:392)
      	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:277)
      	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311)
      	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:105)
      	at org.eclipse.jetty.io.ChannelEndPoint$1.run(ChannelEndPoint.java:104)
      	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:883)
      	at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1034)
      	at java.base/java.lang.Thread.run(Thread.java:834)
      

      the culprit is this code line
      https://github.com/apache/sling-org-apache-sling-engine/blob/f8c698a74f3bf798c331d116794fd817ef6a3e3d/src/main/java/org/apache/sling/engine/impl/request/RequestData.java#L506-L507
      which enforces the response is actually a SlingHttpServletResponseImpl from sling engine - although the following code lines are build in a way to handle also other types of response objects.

      Attachments

        Activity

          People

            sseifert Stefan Seifert
            sseifert Stefan Seifert
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 1h 50m
                1h 50m