Skip to content

feat: Add docs for DownloadHandler #4309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: latest
Choose a base branch
from
Open

Conversation

mshabarov
Copy link
Contributor

Adds a documentation for new API for handling downloads in Vaadin 24.8.

Fixes #4303

Copy link

github-actions bot commented May 14, 2025

AI Language Review

Comment on lines +315 to +341
== Using Custom Servlet and Request Parameters

You can create a custom servlet which handles "image" as a relative URL:

[source,java]
----
@WebServlet(urlPatterns = "/image", name = "DynamicContentServlet")
public class DynamicContentServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
resp.setContentType("image/svg+xml");
String name = req.getParameter("name");
if (name == null) {
name = "";
}
String svg = "<?xml version='1.0' encoding='UTF-8' standalone='no'?>"
+ "<svg xmlns='http://www.w3.org/2000/svg' "
+ "xmlns:xlink='http://www.w3.org/1999/xlink'>"
+ "<rect x='10' y='10' height='100' width='100' "
+ "style=' fill: #90C3D4'/><text x='30' y='30' fill='red'>"
+ name + "</text>" + "</svg>";
resp.getWriter().write(svg);
}
}
----
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is from the old article, I'd keep it just in case if someone is interested in a low level servlet way of downloading a content.

@mshabarov mshabarov requested review from Copilot and caalador May 14, 2025 13:45
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds comprehensive documentation for the new DownloadHandler API in Vaadin 24.8, including multiple usage scenarios and API customization examples.

  • Removed the legacy dynamic content documentation.
  • Added detailed documentation for DownloadHandler covering classpath resource downloads, file system downloads, dynamic InputStream downloads, progress tracking, and custom download handlers.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
articles/flow/advanced/dynamic-content.adoc Legacy documentation removed.
articles/flow/advanced/downloads.adoc New documentation added for the DownloadHandler API.
Comments suppressed due to low confidence (1)

articles/flow/advanced/downloads.adoc:241

  • [nitpick] The class name 'LinkWithM5Validation' is ambiguous; consider renaming it to something more descriptive, such as 'LinkWithChecksumValidation'.
private static class LinkWithM5Validation extends Anchor {

Comment on lines +215 to +218
MessageDigest md5 = MessageDigest.getInstance("MD5");
byte[] digest = md5.digest(data);
String base64Md5 = Base64.getEncoder().encodeToString(digest);
event.getResponse().setHeader("Content-MD5", base64Md5);
Copy link
Contributor Author

@mshabarov mshabarov May 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example with calculating MD5 checksum and checking it on the client isn't perhaps a realistic case. I'd think of a better case for when setting a header is useful in download handler, feel free to share a better example if you have any.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Documentation for the new Download API
1 participant