Class ReportResponses

java.lang.Object
io.leandev.appfuse.report.web.ReportResponses

public final class ReportResponses extends Object

直接把 ReportArtifact 寫入 HTTP 回應(REP-05)

在呼叫者的請求執行緒同步寫出:從第一行起接手 artifact 的 ownership,並在返回前關閉, 不依賴 async executor 或 GC。授權與資料範圍必須在 render 之前完成。

@RequestMapping(path = "/reports/sales", method = {RequestMethod.GET, RequestMethod.HEAD})
void sales(Query query, HttpServletRequest request, HttpServletResponse response) throws IOException {
    var document = template.create(query, context);
    ReportResponses.attachment(renderer.render(document, RenderOptions.defaults()), request, response);
}
請求方法 行為
GET headers(Content-Type、Content-Length、Content-Disposition、Cache-Control: no-store)+ body
HEAD 相同的 headers,不開啟 artifact 串流、不寫 body
其他 IllegalArgumentException

直接串流的內容每次不同,因此不帶 ETag。

Since:
4.0.0
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    attachment(ReportArtifact artifact, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
    以 Content-Disposition: attachment 寫出(瀏覽器下載)
    static void
    inline(ReportArtifact artifact, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
    以 Content-Disposition: inline 寫出(瀏覽器內開啟)

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • attachment

      public static void attachment(ReportArtifact artifact, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws IOException
      以 Content-Disposition: attachment 寫出(瀏覽器下載)
      Parameters:
      artifact - 產物;此方法負責關閉
      request - 目前請求(判斷 GET/HEAD)
      response - 目前回應;不可已提交
      Throws:
      IOException - 寫出失敗(例如用戶端中斷);artifact 已關閉
    • inline

      public static void inline(ReportArtifact artifact, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws IOException
      以 Content-Disposition: inline 寫出(瀏覽器內開啟)
      Parameters:
      artifact - 產物;此方法負責關閉
      request - 目前請求(判斷 GET/HEAD)
      response - 目前回應;不可已提交
      Throws:
      IOException - 寫出失敗(例如用戶端中斷);artifact 已關閉