| 42 | } |
| 43 | |
| 44 | @Override |
| 45 | public HttpResponse execute(HttpRequest req) throws UncheckedIOException { |
| 46 | // We're not using ImmutableMap for the outer map because it disallows null values. |
| 47 | Map<String, @Nullable Object> responseMap = new HashMap<>(); |
| 48 | responseMap.put("sessionId", null); |
| 49 | responseMap.put( |
| 50 | "value", |
| 51 | Map.of( |
| 52 | "error", "unknown command", |
| 53 | "message", |
| 54 | String.format( |
| 55 | "Unable to find command matching %s to %s", req.getMethod(), req.getUri()), |
| 56 | "stacktrace", "")); |
| 57 | responseMap = Collections.unmodifiableMap(responseMap); |
| 58 | |
| 59 | byte[] payload = json.toJson(responseMap).getBytes(UTF_8); |
| 60 | |
| 61 | return new HttpResponse() |
| 62 | .setStatus(HTTP_NOT_FOUND) |
| 63 | .setHeader("Content-Type", JSON_UTF_8.toString()) |
| 64 | .setHeader("Content-Length", String.valueOf(payload.length)) |
| 65 | .setContent(bytes(payload)); |
| 66 | } |
| 67 | } |