class

Analyzer::Java::HttpServer

Inherits Analyzer < FileHelper < Reference < Object

JDK built-in HTTP server (com.sun.net.httpserver.HttpServer, jdk.httpserver module, available since Java 6). Routes are registered with server.createContext("/path", handler), where the handler is a lambda, an HttpHandler instance/anonymous class, or a method reference.

Unlike declarative frameworks the HTTP verb is not bound at registration — handlers branch on exchange.getRequestMethod() — so this analyzer recovers the path from the createContext call and the verb(s)/params from the resolved handler body. When the handler is a named/anonymous HttpHandler, its handle(...) body is resolved within the same file (cross-file handler classes are out of scope, mirroring the other JVM extractors).

Reference: https://docs.oracle.com/en/java/javase/21/docs/api/jdk.httpserver/com/sun/net/httpserver/HttpServer.html

Constants

BODY_VERBS = ["POST", "PUT", "PATCH", "DELETE"]

Verbs that carry a request body — the body param is attached only to these so a method-dispatching handler doesn't surface a body on its GET branch.

CREATE_CONTEXT = "createContext"
HANDLE_METHOD = "handle"
HTTP_METHODS = ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS", "TRACE", "CONNECT"]
JAVA_EXTENSION = "java"
PACKAGE_MARKER = "com.sun.net.httpserver"
RE_BODY = /getRequestBody\s*\(\s*\)/
RE_CASE_GROUP = /\bcase\s+("[A-Za-z]+"(?:\s*,\s*"[A-Za-z]+")*)\s*(?:->|:)/

A case label group: one or more verb literals (Java allows case "GET", "HEAD":) terminated by a colon or an arrow (Java 14+ case "GET" -> ...).

RE_EQ_GRM = /"([A-Za-z]+)"\s*==\s*[A-Za-z0-9_.\s]*getRequestMethod\s*\(\s*\)/
RE_EQUALS_GRM = /"([A-Za-z]+)"\s*\.\s*equals(?:IgnoreCase)?\s*\(\s*[A-Za-z0-9_.\s]*getRequestMethod\s*\(\s*\)\s*\)/
RE_GRM_EQ = /getRequestMethod\s*\(\s*\)\s*==\s*"([A-Za-z]+)"/
RE_GRM_EQUALS = /getRequestMethod\s*\(\s*\)\s*\.\s*equals(?:IgnoreCase)?\s*\(\s*"([A-Za-z]+)"/

getRequestMethod() verb comparisons. Hoisted as constants because interpolated regexes recompile on every evaluation.

RE_GRM_VAR_ASSIGN = /\b([A-Za-z_]\w*)\s*=\s*[^;=][^;]*getRequestMethod\s*\(\s*\)/
RE_HEADER = /getRequestHeaders\s*\(\s*\)\s*\.\s*(?:getFirst|get)\s*\(\s*"([^"]+)"/
RE_VERB_LITERAL = /"([A-Za-z]+)"/
SET_HANDLER = "setHandler"
SWITCH_KEYWORD = "switch"

Class methods

tech_name
Source

Instance methods

analyze
Source
tech

Instance-side view of the same declaration. The per-file rescues live on this base class, which has no way to name the analyzer that is running inside them, so a skipped file could not be attributed to a tech. Deriving it from analyzer_for keeps the name written exactly once.

Source