Uploaded image for project: 'Hippo Site Toolkit 2'
  1. Hippo Site Toolkit 2
  2. HSTTWO-4367

Allow to write binary output solely in #doBeforeServeResource() method

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Normal
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 5.5.0
    • Component/s: None
    • Labels:
      None
    • Similar issues:

      Description

      At the moment, if you want to write a binary stream to the client on HST Resource URL request (e.g, download PDF link or CSV link...), you must write/configure a servlet as hst:resourcetemplate for the component.

      It turned out this is very inconvenient to developers in most cases. Developers should be able to write a binary stream in #doBeforeServeResource(...) method right away, without having to depend on another external servlet. In most cases when writing somethings through HST Resource URLs, the output is not like HTML page and does not require flexibility through templates at all in reality.

      Therefore, it is more convenient for developers to be able to write a binary stream in their HstComponent code.

      There's also another problem with the current separation of HstComponent and Servlet (or JSP or whatever) as hst:resourcetemplate. If developers set some headers or ContentType in the Servlet (which is how normal Java Web developers would do actually), those headers or ContentType are never passed along back to the original response in HstComponent because the Servlet was dispatched (inclusion). So, the workaround is to do that in HstComponent's doBeforeServeResource(), which I don't think is very clean code.

      As a suggestion, this is easily achievable by doing these:

      • Developers are already able to do anything in #doBeforeServeResource(), including set headers, ContentType and write binary stream.
      • HST Container should NOT dispatch any template if the component doesn't have an explicit @hst:resourcetemplate configuration for the component. It should NOT invoke @hst:template when @hst:resourcetemplate is missing. If @hst:resourcetemplate is missing, HST Container should do nothing, assuming the HstComponent is doing whatever it needs already.

      References:

      • Related community forum thread: title="[hippo-community] Apache POI, forms, Hippo and excel download" started on Jun 15, 2018.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                wko Woonsan Ko
              • Votes:
                2 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: