File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package windows ;
2+
3+ import com .sun .net .httpserver .HttpExchange ;
4+ import com .sun .net .httpserver .HttpHandler ;
5+
6+ import java .io .IOException ;
7+ import java .nio .charset .StandardCharsets ;
8+ import java .util .Objects ;
9+
10+ /** Minimal HTTP boundary for the Windows execution model. */
11+ public final class WindowsHttpFrontend implements HttpHandler {
12+ private final WindowsFrontendAdapter adapter ;
13+
14+ public WindowsHttpFrontend (WindowsFrontendAdapter adapter ) {
15+ this .adapter = Objects .requireNonNull (adapter , "adapter" );
16+ }
17+
18+ @ Override
19+ public void handle (HttpExchange exchange ) throws IOException {
20+ if (!"POST" .equalsIgnoreCase (exchange .getRequestMethod ())) {
21+ exchange .sendResponseHeaders (405 , -1 );
22+ return ;
23+ }
24+
25+ String body = new String (exchange .getRequestBody ().readAllBytes (), StandardCharsets .UTF_8 );
26+ WindowsCall call = WindowsCall .parse (body );
27+ WindowsExecution .Result result = adapter .accept (call ).toCompletableFuture ().join ();
28+ byte [] response = result .toJson ().getBytes (StandardCharsets .UTF_8 );
29+ exchange .getResponseHeaders ().set ("Content-Type" , "application/json; charset=utf-8" );
30+ exchange .sendResponseHeaders (result .exitCode (), response .length );
31+ try (var output = exchange .getResponseBody ()) {
32+ output .write (response );
33+ }
34+ }
35+ }
You can’t perform that action at this time.
0 commit comments