[jira] [Commented] (SLING-8047) Rendered/exported JSON requested via SlingRequestProcessor is not written to output stream
[ https://issues.apache.org/jira/browse/SLING-8047?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17711197#comment-17711197 ] Carsten Ziegeler commented on SLING-8047: - This is open for over four years now. Is this still a problem or can we resolve? > Rendered/exported JSON requested via SlingRequestProcessor is not written to > output stream > -- > > Key: SLING-8047 > URL: https://issues.apache.org/jira/browse/SLING-8047 > Project: Sling > Issue Type: Bug > Components: Servlets >Reporter: Philip Mundt >Assignee: Jason E Bailey >Priority: Major > Attachments: > SLING-8047-DefaultGetServlet-does-not-write-to-output-stream.patch, > SLING-8047-ExportServlet-does-not-write-to-output-stream.patch > > Time Spent: 2h 50m > Remaining Estimate: 0h > > While trying to facilitate the {{SlingRequestProcessor}} to get a rendered or > exported JSON representation of a resource, we ran into the problem of the > response always being empty. The HTML rendering worked without any issue. > (See example code of [Get the rendered HTML for an AEM resource, component or > page|http://www.nateyolles.com/blog/2015/10/get-rendered-html-for-an-aem-resource-or-component] > or [https://stackoverflow.com/a/34218708]) > Main, observed difference seem to be the method calls to print writer: > h4. JsonRenderer > {{org.apache.sling.servlets.get.impl.helpers.JsonRenderer#render}} uses > {{#write}} method of response's print writer. > h4. ExportServlet (via JacksonExporter) > {{org.apache.sling.models.impl.ExportServlet#doGet}} uses {{#write}} method > of response's print writer. > h4. HTMLRenderer > {{org.apache.sling.servlets.get.impl.helpers.HtmlRenderer#render}} uses > {{#print}} and {{#println}} methods of response's print writer. > h3. Further observations > When the print writer's {{autoFlush}} property is set to true and one uses > the {{#println}} method instead of {{#write}}, the {{JsonRenderer}} will > flush the print writer's buffer to the output stream. Due to wrapping the > response in > {{org.apache.sling.scripting.core.impl.helper.OnDemandWriterResponse}} (where > {{autoFlush=false}}) this does not work for the {{ExportServlet}}. > When adding implicit {{#flush()}} calls to both classes, both request > scenarios will work. According to the servlet specification, it should not be > necessary to flush the print writer, as the container must immediately flush > all remaining content to the client upon "termination of the service method > of the servlet". > Please find two test cases for (where implicit {{#flush()}} calls were added): > * JsonRenderer ({{sling-org-apache-sling-servlets-get}}): > [^SLING-8047-DefaultGetServlet-does-not-write-to-output-stream.patch] > * ExportServlet ({{sling-org-apache-sling-models-impl}}): > [^SLING-8047-ExportServlet-does-not-write-to-output-stream.patch] -- This message was sent by Atlassian Jira (v8.20.10#820010)
[jira] [Commented] (SLING-8047) Rendered/exported JSON requested via SlingRequestProcessor is not written to output stream
[ https://issues.apache.org/jira/browse/SLING-8047?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16698664#comment-16698664 ] Julian Sedding commented on SLING-8047: --- [~mundt], thanks for the test and sorry for the delay. The only other thing you could do t help is give me some time ;) I commented on your github branch. Could you please address the comment and create a PR? Thanks! I'll solicit some feedback on the mailing list, as my proposed change would be a slight change of behaviour in a core passage of the code. > Rendered/exported JSON requested via SlingRequestProcessor is not written to > output stream > -- > > Key: SLING-8047 > URL: https://issues.apache.org/jira/browse/SLING-8047 > Project: Sling > Issue Type: Bug > Components: Servlets >Reporter: Philip Mundt >Assignee: Jason E Bailey >Priority: Major > Attachments: > SLING-8047-DefaultGetServlet-does-not-write-to-output-stream.patch, > SLING-8047-ExportServlet-does-not-write-to-output-stream.patch > > Time Spent: 1.5h > Remaining Estimate: 0h > > While trying to facilitate the {{SlingRequestProcessor}} to get a rendered or > exported JSON representation of a resource, we ran into the problem of the > response always being empty. The HTML rendering worked without any issue. > (See example code of [Get the rendered HTML for an AEM resource, component or > page|http://www.nateyolles.com/blog/2015/10/get-rendered-html-for-an-aem-resource-or-component] > or [https://stackoverflow.com/a/34218708]) > Main, observed difference seem to be the method calls to print writer: > h4. JsonRenderer > {{org.apache.sling.servlets.get.impl.helpers.JsonRenderer#render}} uses > {{#write}} method of response's print writer. > h4. ExportServlet (via JacksonExporter) > {{org.apache.sling.models.impl.ExportServlet#doGet}} uses {{#write}} method > of response's print writer. > h4. HTMLRenderer > {{org.apache.sling.servlets.get.impl.helpers.HtmlRenderer#render}} uses > {{#print}} and {{#println}} methods of response's print writer. > h3. Further observations > When the print writer's {{autoFlush}} property is set to true and one uses > the {{#println}} method instead of {{#write}}, the {{JsonRenderer}} will > flush the print writer's buffer to the output stream. Due to wrapping the > response in > {{org.apache.sling.scripting.core.impl.helper.OnDemandWriterResponse}} (where > {{autoFlush=false}}) this does not work for the {{ExportServlet}}. > When adding implicit {{#flush()}} calls to both classes, both request > scenarios will work. According to the servlet specification, it should not be > necessary to flush the print writer, as the container must immediately flush > all remaining content to the client upon "termination of the service method > of the servlet". > Please find two test cases for (where implicit {{#flush()}} calls were added): > * JsonRenderer ({{sling-org-apache-sling-servlets-get}}): > [^SLING-8047-DefaultGetServlet-does-not-write-to-output-stream.patch] > * ExportServlet ({{sling-org-apache-sling-models-impl}}): > [^SLING-8047-ExportServlet-does-not-write-to-output-stream.patch] -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (SLING-8047) Rendered/exported JSON requested via SlingRequestProcessor is not written to output stream
[ https://issues.apache.org/jira/browse/SLING-8047?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16698593#comment-16698593 ] Philip Mundt commented on SLING-8047: - Is there anything else I could do to help with this issue? > Rendered/exported JSON requested via SlingRequestProcessor is not written to > output stream > -- > > Key: SLING-8047 > URL: https://issues.apache.org/jira/browse/SLING-8047 > Project: Sling > Issue Type: Bug > Components: Servlets >Reporter: Philip Mundt >Assignee: Jason E Bailey >Priority: Major > Attachments: > SLING-8047-DefaultGetServlet-does-not-write-to-output-stream.patch, > SLING-8047-ExportServlet-does-not-write-to-output-stream.patch > > Time Spent: 1.5h > Remaining Estimate: 0h > > While trying to facilitate the {{SlingRequestProcessor}} to get a rendered or > exported JSON representation of a resource, we ran into the problem of the > response always being empty. The HTML rendering worked without any issue. > (See example code of [Get the rendered HTML for an AEM resource, component or > page|http://www.nateyolles.com/blog/2015/10/get-rendered-html-for-an-aem-resource-or-component] > or [https://stackoverflow.com/a/34218708]) > Main, observed difference seem to be the method calls to print writer: > h4. JsonRenderer > {{org.apache.sling.servlets.get.impl.helpers.JsonRenderer#render}} uses > {{#write}} method of response's print writer. > h4. ExportServlet (via JacksonExporter) > {{org.apache.sling.models.impl.ExportServlet#doGet}} uses {{#write}} method > of response's print writer. > h4. HTMLRenderer > {{org.apache.sling.servlets.get.impl.helpers.HtmlRenderer#render}} uses > {{#print}} and {{#println}} methods of response's print writer. > h3. Further observations > When the print writer's {{autoFlush}} property is set to true and one uses > the {{#println}} method instead of {{#write}}, the {{JsonRenderer}} will > flush the print writer's buffer to the output stream. Due to wrapping the > response in > {{org.apache.sling.scripting.core.impl.helper.OnDemandWriterResponse}} (where > {{autoFlush=false}}) this does not work for the {{ExportServlet}}. > When adding implicit {{#flush()}} calls to both classes, both request > scenarios will work. According to the servlet specification, it should not be > necessary to flush the print writer, as the container must immediately flush > all remaining content to the client upon "termination of the service method > of the servlet". > Please find two test cases for (where implicit {{#flush()}} calls were added): > * JsonRenderer ({{sling-org-apache-sling-servlets-get}}): > [^SLING-8047-DefaultGetServlet-does-not-write-to-output-stream.patch] > * ExportServlet ({{sling-org-apache-sling-models-impl}}): > [^SLING-8047-ExportServlet-does-not-write-to-output-stream.patch] -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (SLING-8047) Rendered/exported JSON requested via SlingRequestProcessor is not written to output stream
[ https://issues.apache.org/jira/browse/SLING-8047?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16678258#comment-16678258 ] Philip Mundt commented on SLING-8047: - [~jsedding] thanks again for your alternative fix. I allowed myself to rebase your commit in my fork and add a test case for the underlying issue. I'd be happy to hear/get your input on it. > Rendered/exported JSON requested via SlingRequestProcessor is not written to > output stream > -- > > Key: SLING-8047 > URL: https://issues.apache.org/jira/browse/SLING-8047 > Project: Sling > Issue Type: Bug > Components: Servlets >Reporter: Philip Mundt >Assignee: Jason E Bailey >Priority: Major > Attachments: > SLING-8047-DefaultGetServlet-does-not-write-to-output-stream.patch, > SLING-8047-ExportServlet-does-not-write-to-output-stream.patch > > Time Spent: 1.5h > Remaining Estimate: 0h > > While trying to facilitate the {{SlingRequestProcessor}} to get a rendered or > exported JSON representation of a resource, we ran into the problem of the > response always being empty. The HTML rendering worked without any issue. > (See example code of [Get the rendered HTML for an AEM resource, component or > page|http://www.nateyolles.com/blog/2015/10/get-rendered-html-for-an-aem-resource-or-component] > or [https://stackoverflow.com/a/34218708]) > Main, observed difference seem to be the method calls to print writer: > h4. JsonRenderer > {{org.apache.sling.servlets.get.impl.helpers.JsonRenderer#render}} uses > {{#write}} method of response's print writer. > h4. ExportServlet (via JacksonExporter) > {{org.apache.sling.models.impl.ExportServlet#doGet}} uses {{#write}} method > of response's print writer. > h4. HTMLRenderer > {{org.apache.sling.servlets.get.impl.helpers.HtmlRenderer#render}} uses > {{#print}} and {{#println}} methods of response's print writer. > h3. Further observations > When the print writer's {{autoFlush}} property is set to true and one uses > the {{#println}} method instead of {{#write}}, the {{JsonRenderer}} will > flush the print writer's buffer to the output stream. Due to wrapping the > response in > {{org.apache.sling.scripting.core.impl.helper.OnDemandWriterResponse}} (where > {{autoFlush=false}}) this does not work for the {{ExportServlet}}. > When adding implicit {{#flush()}} calls to both classes, both request > scenarios will work. According to the servlet specification, it should not be > necessary to flush the print writer, as the container must immediately flush > all remaining content to the client upon "termination of the service method > of the servlet". > Please find two test cases for (where implicit {{#flush()}} calls were added): > * JsonRenderer ({{sling-org-apache-sling-servlets-get}}): > [^SLING-8047-DefaultGetServlet-does-not-write-to-output-stream.patch] > * ExportServlet ({{sling-org-apache-sling-models-impl}}): > [^SLING-8047-ExportServlet-does-not-write-to-output-stream.patch] -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (SLING-8047) Rendered/exported JSON requested via SlingRequestProcessor is not written to output stream
[ https://issues.apache.org/jira/browse/SLING-8047?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16668614#comment-16668614 ] Philip Mundt commented on SLING-8047: - [~jsedding] that's what I'm wondering too. I wasn't able to find the root cause yet. But it seems that the buffer is overwritten somewhere, if not flushed in the {{org.apache.sling.servlets.get.impl.helpers.JsonRenderer}}. Regarding your question: it's a fake response implementation that wraps (in our case) a {{java.io.ByteArrayOutputStream}} in a {{java.io.OutputStreamWriter}} and passes it to the {{java.io.PrintWriter}} ({{autoFlush}} is set to {{true}}). The response object does not implement the {{#flushBuffer()}} method, but even if I do (I quickly tried, flushing print writer and output stream) nothing changes. The only working solution up until now was flushing the writer in the JSON renderer. > Rendered/exported JSON requested via SlingRequestProcessor is not written to > output stream > -- > > Key: SLING-8047 > URL: https://issues.apache.org/jira/browse/SLING-8047 > Project: Sling > Issue Type: Bug > Components: Feature Model, Servlets >Reporter: Philip Mundt >Assignee: Jason E Bailey >Priority: Major > Attachments: > SLING-8047-DefaultGetServlet-does-not-write-to-output-stream.patch, > SLING-8047-ExportServlet-does-not-write-to-output-stream.patch > > Time Spent: 20m > Remaining Estimate: 0h > > While trying to facilitate the {{SlingRequestProcessor}} to get a rendered or > exported JSON representation of a resource, we ran into the problem of the > response always being empty. The HTML rendering worked without any issue. > (See example code of [Get the rendered HTML for an AEM resource, component or > page|http://www.nateyolles.com/blog/2015/10/get-rendered-html-for-an-aem-resource-or-component] > or [https://stackoverflow.com/a/34218708]) > Main, observed difference seem to be the method calls to print writer: > h4. JsonRenderer > {{org.apache.sling.servlets.get.impl.helpers.JsonRenderer#render}} uses > {{#write}} method of response's print writer. > h4. ExportServlet (via JacksonExporter) > {{org.apache.sling.models.impl.ExportServlet#doGet}} uses {{#write}} method > of response's print writer. > h4. HTMLRenderer > {{org.apache.sling.servlets.get.impl.helpers.HtmlRenderer#render}} uses > {{#print}} and {{#println}} methods of response's print writer. > h3. Further observations > When the print writer's {{autoFlush}} property is set to true and one uses > the {{#println}} method instead of {{#write}}, the {{JsonRenderer}} will > flush the print writer's buffer to the output stream. Due to wrapping the > response in > {{org.apache.sling.scripting.core.impl.helper.OnDemandWriterResponse}} (where > {{autoFlush=false}}) this does not work for the {{ExportServlet}}. > When adding implicit {{#flush()}} calls to both classes, both request > scenarios will work. According to the servlet specification, it should not be > necessary to flush the print writer, as the container must immediately flush > all remaining content to the client upon "termination of the service method > of the servlet". > Please find two test cases for (where implicit {{#flush()}} calls were added): > * JsonRenderer ({{sling-org-apache-sling-servlets-get}}): > [^SLING-8047-DefaultGetServlet-does-not-write-to-output-stream.patch] > * ExportServlet ({{sling-org-apache-sling-models-impl}}): > [^SLING-8047-ExportServlet-does-not-write-to-output-stream.patch] -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (SLING-8047) Rendered/exported JSON requested via SlingRequestProcessor is not written to output stream
[ https://issues.apache.org/jira/browse/SLING-8047?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16668402#comment-16668402 ] Julian Sedding commented on SLING-8047: --- Thanks [~mundt] for the feedback. That's interesting, I wonder if/how the {{DefaultGetServlet}} is getting special treatment. > Rendered/exported JSON requested via SlingRequestProcessor is not written to > output stream > -- > > Key: SLING-8047 > URL: https://issues.apache.org/jira/browse/SLING-8047 > Project: Sling > Issue Type: Bug > Components: Feature Model, Servlets >Reporter: Philip Mundt >Assignee: Jason E Bailey >Priority: Major > Attachments: > SLING-8047-DefaultGetServlet-does-not-write-to-output-stream.patch, > SLING-8047-ExportServlet-does-not-write-to-output-stream.patch > > Time Spent: 20m > Remaining Estimate: 0h > > While trying to facilitate the {{SlingRequestProcessor}} to get a rendered or > exported JSON representation of a resource, we ran into the problem of the > response always being empty. The HTML rendering worked without any issue. > (See example code of [Get the rendered HTML for an AEM resource, component or > page|http://www.nateyolles.com/blog/2015/10/get-rendered-html-for-an-aem-resource-or-component] > or [https://stackoverflow.com/a/34218708]) > Main, observed difference seem to be the method calls to print writer: > h4. JsonRenderer > {{org.apache.sling.servlets.get.impl.helpers.JsonRenderer#render}} uses > {{#write}} method of response's print writer. > h4. ExportServlet (via JacksonExporter) > {{org.apache.sling.models.impl.ExportServlet#doGet}} uses {{#write}} method > of response's print writer. > h4. HTMLRenderer > {{org.apache.sling.servlets.get.impl.helpers.HtmlRenderer#render}} uses > {{#print}} and {{#println}} methods of response's print writer. > h3. Further observations > When the print writer's {{autoFlush}} property is set to true and one uses > the {{#println}} method instead of {{#write}}, the {{JsonRenderer}} will > flush the print writer's buffer to the output stream. Due to wrapping the > response in > {{org.apache.sling.scripting.core.impl.helper.OnDemandWriterResponse}} (where > {{autoFlush=false}}) this does not work for the {{ExportServlet}}. > When adding implicit {{#flush()}} calls to both classes, both request > scenarios will work. According to the servlet specification, it should not be > necessary to flush the print writer, as the container must immediately flush > all remaining content to the client upon "termination of the service method > of the servlet". > Please find two test cases for (where implicit {{#flush()}} calls were added): > * JsonRenderer ({{sling-org-apache-sling-servlets-get}}): > [^SLING-8047-DefaultGetServlet-does-not-write-to-output-stream.patch] > * ExportServlet ({{sling-org-apache-sling-models-impl}}): > [^SLING-8047-ExportServlet-does-not-write-to-output-stream.patch] -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (SLING-8047) Rendered/exported JSON requested via SlingRequestProcessor is not written to output stream
[ https://issues.apache.org/jira/browse/SLING-8047?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16668381#comment-16668381 ] Philip Mundt commented on SLING-8047: - Hey [~jsedding] thanks for chiming in and providing an alternative fix. I tried it and it works for the model exporter ({{org.apache.sling.models.impl.ExportServlet}}) scenario. However, when using {{org.apache.sling.servlets.get.impl.DefaultGetServlet}} (via {{org.apache.sling.servlets.get.impl.helpers.JsonRenderer}}) the output is still an empty string. > Rendered/exported JSON requested via SlingRequestProcessor is not written to > output stream > -- > > Key: SLING-8047 > URL: https://issues.apache.org/jira/browse/SLING-8047 > Project: Sling > Issue Type: Bug > Components: Feature Model, Servlets >Reporter: Philip Mundt >Assignee: Jason E Bailey >Priority: Major > Attachments: > SLING-8047-DefaultGetServlet-does-not-write-to-output-stream.patch, > SLING-8047-ExportServlet-does-not-write-to-output-stream.patch > > Time Spent: 20m > Remaining Estimate: 0h > > While trying to facilitate the {{SlingRequestProcessor}} to get a rendered or > exported JSON representation of a resource, we ran into the problem of the > response always being empty. The HTML rendering worked without any issue. > (See example code of [Get the rendered HTML for an AEM resource, component or > page|http://www.nateyolles.com/blog/2015/10/get-rendered-html-for-an-aem-resource-or-component] > or [https://stackoverflow.com/a/34218708]) > Main, observed difference seem to be the method calls to print writer: > h4. JsonRenderer > {{org.apache.sling.servlets.get.impl.helpers.JsonRenderer#render}} uses > {{#write}} method of response's print writer. > h4. ExportServlet (via JacksonExporter) > {{org.apache.sling.models.impl.ExportServlet#doGet}} uses {{#write}} method > of response's print writer. > h4. HTMLRenderer > {{org.apache.sling.servlets.get.impl.helpers.HtmlRenderer#render}} uses > {{#print}} and {{#println}} methods of response's print writer. > h3. Further observations > When the print writer's {{autoFlush}} property is set to true and one uses > the {{#println}} method instead of {{#write}}, the {{JsonRenderer}} will > flush the print writer's buffer to the output stream. Due to wrapping the > response in > {{org.apache.sling.scripting.core.impl.helper.OnDemandWriterResponse}} (where > {{autoFlush=false}}) this does not work for the {{ExportServlet}}. > When adding implicit {{#flush()}} calls to both classes, both request > scenarios will work. According to the servlet specification, it should not be > necessary to flush the print writer, as the container must immediately flush > all remaining content to the client upon "termination of the service method > of the servlet". > Please find two test cases for (where implicit {{#flush()}} calls were added): > * JsonRenderer ({{sling-org-apache-sling-servlets-get}}): > [^SLING-8047-DefaultGetServlet-does-not-write-to-output-stream.patch] > * ExportServlet ({{sling-org-apache-sling-models-impl}}): > [^SLING-8047-ExportServlet-does-not-write-to-output-stream.patch] -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (SLING-8047) Rendered/exported JSON requested via SlingRequestProcessor is not written to output stream
[ https://issues.apache.org/jira/browse/SLING-8047?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16667273#comment-16667273 ] Julian Sedding commented on SLING-8047: --- [~mundt] could you please check if the fix on [my fork of Sling Engine|https://github.com/jsedding/sling-org-apache-sling-engine/tree/SLING-8047] addresses your issue? It implements the approach mentioned in my previous comment. > Rendered/exported JSON requested via SlingRequestProcessor is not written to > output stream > -- > > Key: SLING-8047 > URL: https://issues.apache.org/jira/browse/SLING-8047 > Project: Sling > Issue Type: Bug > Components: Feature Model, Servlets >Reporter: Philip Mundt >Assignee: Jason E Bailey >Priority: Major > Attachments: > SLING-8047-DefaultGetServlet-does-not-write-to-output-stream.patch, > SLING-8047-ExportServlet-does-not-write-to-output-stream.patch > > Time Spent: 20m > Remaining Estimate: 0h > > While trying to facilitate the {{SlingRequestProcessor}} to get a rendered or > exported JSON representation of a resource, we ran into the problem of the > response always being empty. The HTML rendering worked without any issue. > (See example code of [Get the rendered HTML for an AEM resource, component or > page|http://www.nateyolles.com/blog/2015/10/get-rendered-html-for-an-aem-resource-or-component] > or [https://stackoverflow.com/a/34218708]) > Main, observed difference seem to be the method calls to print writer: > h4. JsonRenderer > {{org.apache.sling.servlets.get.impl.helpers.JsonRenderer#render}} uses > {{#write}} method of response's print writer. > h4. ExportServlet (via JacksonExporter) > {{org.apache.sling.models.impl.ExportServlet#doGet}} uses {{#write}} method > of response's print writer. > h4. HTMLRenderer > {{org.apache.sling.servlets.get.impl.helpers.HtmlRenderer#render}} uses > {{#print}} and {{#println}} methods of response's print writer. > h3. Further observations > When the print writer's {{autoFlush}} property is set to true and one uses > the {{#println}} method instead of {{#write}}, the {{JsonRenderer}} will > flush the print writer's buffer to the output stream. Due to wrapping the > response in > {{org.apache.sling.scripting.core.impl.helper.OnDemandWriterResponse}} (where > {{autoFlush=false}}) this does not work for the {{ExportServlet}}. > When adding implicit {{#flush()}} calls to both classes, both request > scenarios will work. According to the servlet specification, it should not be > necessary to flush the print writer, as the container must immediately flush > all remaining content to the client upon "termination of the service method > of the servlet". > Please find two test cases for (where implicit {{#flush()}} calls were added): > * JsonRenderer ({{sling-org-apache-sling-servlets-get}}): > [^SLING-8047-DefaultGetServlet-does-not-write-to-output-stream.patch] > * ExportServlet ({{sling-org-apache-sling-models-impl}}): > [^SLING-8047-ExportServlet-does-not-write-to-output-stream.patch] -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (SLING-8047) Rendered/exported JSON requested via SlingRequestProcessor is not written to output stream
[ https://issues.apache.org/jira/browse/SLING-8047?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16665079#comment-16665079 ] Julian Sedding commented on SLING-8047: --- If this same issue affects multiple servlets, then I doubt that the root cause is in the servlets. My hypothesis is the following: the root issue is in the Sling Engine, where responses are not (auto-)flushed after processing if the RequestProcessor is used. I could imagine that this wouldn't be a problem for scenarios where requests are processed via the SlingMainServlet, because the HTTP container (app-server, Felix Jetty, ...) would perform the flush. In the scenario where the RequestProcessor is used, there is no HTTP container, hence we can experience the described issue. > Rendered/exported JSON requested via SlingRequestProcessor is not written to > output stream > -- > > Key: SLING-8047 > URL: https://issues.apache.org/jira/browse/SLING-8047 > Project: Sling > Issue Type: Bug > Components: Feature Model, Servlets >Reporter: Philip Mundt >Assignee: Jason E Bailey >Priority: Major > Attachments: > SLING-8047-DefaultGetServlet-does-not-write-to-output-stream.patch, > SLING-8047-ExportServlet-does-not-write-to-output-stream.patch > > Time Spent: 20m > Remaining Estimate: 0h > > While trying to facilitate the {{SlingRequestProcessor}} to get a rendered or > exported JSON representation of a resource, we ran into the problem of the > response always being empty. The HTML rendering worked without any issue. > (See example code of [Get the rendered HTML for an AEM resource, component or > page|http://www.nateyolles.com/blog/2015/10/get-rendered-html-for-an-aem-resource-or-component] > or [https://stackoverflow.com/a/34218708]) > Main, observed difference seem to be the method calls to print writer: > h4. JsonRenderer > {{org.apache.sling.servlets.get.impl.helpers.JsonRenderer#render}} uses > {{#write}} method of response's print writer. > h4. ExportServlet (via JacksonExporter) > {{org.apache.sling.models.impl.ExportServlet#doGet}} uses {{#write}} method > of response's print writer. > h4. HTMLRenderer > {{org.apache.sling.servlets.get.impl.helpers.HtmlRenderer#render}} uses > {{#print}} and {{#println}} methods of response's print writer. > h3. Further observations > When the print writer's {{autoFlush}} property is set to true and one uses > the {{#println}} method instead of {{#write}}, the {{JsonRenderer}} will > flush the print writer's buffer to the output stream. Due to wrapping the > response in > {{org.apache.sling.scripting.core.impl.helper.OnDemandWriterResponse}} (where > {{autoFlush=false}}) this does not work for the {{ExportServlet}}. > When adding implicit {{#flush()}} calls to both classes, both request > scenarios will work. According to the servlet specification, it should not be > necessary to flush the print writer, as the container must immediately flush > all remaining content to the client upon "termination of the service method > of the servlet". > Please find two test cases for (where implicit {{#flush()}} calls were added): > * JsonRenderer ({{sling-org-apache-sling-servlets-get}}): > [^SLING-8047-DefaultGetServlet-does-not-write-to-output-stream.patch] > * ExportServlet ({{sling-org-apache-sling-models-impl}}): > [^SLING-8047-ExportServlet-does-not-write-to-output-stream.patch] -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (SLING-8047) Rendered/exported JSON requested via SlingRequestProcessor is not written to output stream
[ https://issues.apache.org/jira/browse/SLING-8047?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16664263#comment-16664263 ] Jason E Bailey commented on SLING-8047: --- Thank you for raising this issue! I see you also created a pull request against the models. Could you do one for the default get servlets as well? > Rendered/exported JSON requested via SlingRequestProcessor is not written to > output stream > -- > > Key: SLING-8047 > URL: https://issues.apache.org/jira/browse/SLING-8047 > Project: Sling > Issue Type: Bug > Components: Feature Model, Servlets >Reporter: Philip Mundt >Assignee: Jason E Bailey >Priority: Major > Attachments: > SLING-8047-DefaultGetServlet-does-not-write-to-output-stream.patch, > SLING-8047-ExportServlet-does-not-write-to-output-stream.patch > > Time Spent: 10m > Remaining Estimate: 0h > > While trying to facilitate the {{SlingRequestProcessor}} to get a rendered or > exported JSON representation of a resource, we ran into the problem of the > response always being empty. The HTML rendering worked without any issue. > (See example code of [Get the rendered HTML for an AEM resource, component or > page|http://www.nateyolles.com/blog/2015/10/get-rendered-html-for-an-aem-resource-or-component] > or [https://stackoverflow.com/a/34218708]) > Main, observed difference seem to be the method calls to print writer: > h4. JsonRenderer > {{org.apache.sling.servlets.get.impl.helpers.JsonRenderer#render}} uses > {{#write}} method of response's print writer. > h4. ExportServlet (via JacksonExporter) > {{org.apache.sling.models.impl.ExportServlet#doGet}} uses {{#write}} method > of response's print writer. > h4. HTMLRenderer > {{org.apache.sling.servlets.get.impl.helpers.HtmlRenderer#render}} uses > {{#print}} and {{#println}} methods of response's print writer. > h3. Further observations > When the print writer's {{autoFlush}} property is set to true and one uses > the {{#println}} method instead of {{#write}}, the {{JsonRenderer}} will > flush the print writer's buffer to the output stream. Due to wrapping the > response in > {{org.apache.sling.scripting.core.impl.helper.OnDemandWriterResponse}} (where > {{autoFlush=false}}) this does not work for the {{ExportServlet}}. > When adding implicit {{#flush()}} calls to both classes, both request > scenarios will work. According to the servlet specification, it should not be > necessary to flush the print writer, as the container must immediately flush > all remaining content to the client upon "termination of the service method > of the servlet". > Please find two test cases for (where implicit {{#flush()}} calls were added): > * JsonRenderer ({{sling-org-apache-sling-servlets-get}}): > [^SLING-8047-DefaultGetServlet-does-not-write-to-output-stream.patch] > * ExportServlet ({{sling-org-apache-sling-models-impl}}): > [^SLING-8047-ExportServlet-does-not-write-to-output-stream.patch] -- This message was sent by Atlassian JIRA (v7.6.3#76005)