Skip to content

Tried writing a reference server using jdk httpServer #1026

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 4 commits into
base: main
Choose a base branch
from

Conversation

Vaivaswat2244
Copy link

@Vaivaswat2244 Vaivaswat2244 commented Apr 3, 2025

This PR introduces ReferenceServer.java, a lightweight HTTP server to serve Processing's reference documentation locally. It replaces the previous approach with a more maintainable and efficient solution using Java's built-in HttpServer.

Changes Implemented

  • Used com.sun.net.httpserver.HttpServer from the JDK

  • Handles different MIME types (HTML, CSS, JS, images, etc.).

  • Runs on a separate thread to avoid blocking the main Processing IDE.

Later in this pr I will add the download modifications in the JavaEditor.java file, which is the only file find I found where the WebServer was being used

Maintainer edit: Fixes #980


@SableRaf
Copy link
Collaborator

SableRaf commented Apr 4, 2025

Nice work @Vaivaswat2244!

I didn't have a close look at the code but the server runs fine for me. I left a minor comment about the JDK version. Feel free to mark this as a draft PR and switch it back when it's ready for a review.

Looking forward to seeing the download part!

Thanks for your contribution 💙

@Vaivaswat2244 Vaivaswat2244 marked this pull request as draft April 4, 2025 18:58
@Vaivaswat2244
Copy link
Author

I updated the source link for the download and also replaced the WebServer class.
The download is getting completed and the reference zip folder is getting stored on
/home/[username]/sketchbook/reference.zip (using ubuntu)

Now I'm not sure how to automate this version checking system. I researched a bit and found that using Github apis is the most suitable way for tracking version. I can try that.
Also wanted to know if this is what we intended with the issue originally

@Vaivaswat2244 Vaivaswat2244 marked this pull request as ready for review April 17, 2025 21:04
@Stefterv
Copy link
Collaborator

Hi @Vaivaswat2244 Thank you for your work on this, looking good! The current version of Processing is available to you in your code through Base.getRevision() and Base.getVersionName()

@Vaivaswat2244
Copy link
Author

hey @SableRaf @Stefterv ,
I made this function as suggested using Base.getVersionName(); and Base.getRevision() and used it in the

private void downloadReference() {
    try {
      URL source = new URL(getReferenceDownloadUrl());
private String getReferenceDownloadUrl() {
  String versionName = Base.getVersionName();
  String revision = String.valueOf(Base.getRevision());
  
  System.out.println("Processing Version Name: " + versionName);
  System.out.println("Processing Revision: " + revision);
  
  if (versionName != null && !versionName.isEmpty() && 
      revision != null && !revision.isEmpty()) {
    String url = String.format(
      "https://github.com/processing/processing4/releases/download/processing-%s-%s/processing-%s-reference.zip",
      revision, versionName, versionName);
    System.out.println("Generated URL: " + url);
    return url;
  } else {
    System.out.println("Using fallback URL");
    return "https://github.com/processing/processing4/releases/download/processing-1300-4.4.0/processing-4.4.0-reference.zip";
  }
}

In logs I got Version Name: "unspecified" and Revision: 2147483647 (which is Integer.MAX_VALUE)
I'm not sure as though why is it happening. Is it because the development build doesn't have proper version info or something else

@Stefterv
Copy link
Collaborator

Hey @Vaivaswat2244 that is correct, those are the values that are expected in the development build 😅

@Vaivaswat2244
Copy link
Author

So should I commit the changes?

Copy link
Collaborator

@Stefterv Stefterv left a comment

Choose a reason for hiding this comment

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

Looks good! Thank you!

If you can delete the old WebServer.java as well that would be great, otherwise we'll delete it later.

@Vaivaswat2244 Vaivaswat2244 requested a review from SableRaf April 19, 2025 18:16
@Vaivaswat2244
Copy link
Author

Sure @Stefterv, I have deleted the WebServer class as well.

@Stefterv Stefterv added this to the 4.4.4 milestone Apr 21, 2025
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.

Rework the integrated reference in Processing
3 participants