Loading de.ugoe.cs.swe.T3Q/src/de/ugoe/cs/swe/T3Q/HttpFileServer.java +16 −1 Original line number Diff line number Diff line Loading @@ -60,6 +60,8 @@ public class HttpFileServer { @Override public void handle(HttpExchange exchange) throws IOException { System.out.println("SERVER: Received request: " + exchange.getRequestMethod() + " " + exchange.getRequestURI()); if (!"POST".equalsIgnoreCase(exchange.getRequestMethod())) { sendError(exchange, 405, "Method not allowed"); return; Loading @@ -67,30 +69,37 @@ public class HttpFileServer { Path tempDir = null; try { System.out.println("SERVER: Creating temp directory"); // Create temporary directory for uploaded files tempDir = Files.createTempDirectory(TEMP_DIR_PREFIX); // Parse multipart request String contentType = exchange.getRequestHeaders().getFirst("Content-Type"); System.out.println("SERVER: Content-Type: " + contentType); if (contentType == null || !contentType.startsWith("multipart/form-data")) { sendError(exchange, 400, "Expected multipart/form-data"); return; } String boundary = extractBoundary(contentType); System.out.println("SERVER: Extracted boundary: " + boundary); if (boundary == null) { sendError(exchange, 400, "No boundary found in Content-Type"); return; } System.out.println("SERVER: Starting multipart parse"); MultipartParser parser = new MultipartParser(exchange.getRequestBody(), boundary, tempDir); MultipartData data = parser.parse(); System.out.println("SERVER: Parse complete, files=" + data.files.size() + ", fields=" + data.fields.size()); if (data.files.isEmpty()) { sendError(exchange, 400, "No files uploaded"); return; } System.out.println("SERVER: Processing files"); // Process files with external command Path jsonResult = processor.process(data.files, data.fields); Loading @@ -99,6 +108,7 @@ public class HttpFileServer { return; } System.out.println("SERVER: Sending response"); // Send JSON response byte[] jsonBytes = Files.readAllBytes(jsonResult); exchange.getResponseHeaders().set("Content-Type", "application/json"); Loading @@ -107,15 +117,18 @@ public class HttpFileServer { os.write(jsonBytes); } System.out.println("SERVER: Response sent successfully"); // Cleanup result file Files.deleteIfExists(jsonResult); } catch (Exception e) { System.err.println("SERVER: Error occurred"); e.printStackTrace(); sendError(exchange, 500, "Processing error: " + e.getMessage()); } finally { // Cleanup temp directory if (tempDir != null) { System.out.println("SERVER: Cleaning up temp directory"); cleanupDirectory(tempDir); } } Loading Loading @@ -409,6 +422,8 @@ public class HttpFileServer { String jsonFile = "asn.json"; cmd.add(jsonFile); System.out.println("SERVER: Running "+cmd); // Execute command ProcessBuilder pb = new ProcessBuilder(cmd); pb.directory(workDir.toFile()); Loading @@ -424,7 +439,7 @@ public class HttpFileServer { .reduce((a, b) -> a + "\n" + b) .orElse(""); } System.out.println(output.replaceAll("\n", "\nTITAN: ")); int exitCode = process.waitFor(); if (exitCode != 0) { throw new RuntimeException("Command failed with exit code " + exitCode + ": " + output); Loading Loading
de.ugoe.cs.swe.T3Q/src/de/ugoe/cs/swe/T3Q/HttpFileServer.java +16 −1 Original line number Diff line number Diff line Loading @@ -60,6 +60,8 @@ public class HttpFileServer { @Override public void handle(HttpExchange exchange) throws IOException { System.out.println("SERVER: Received request: " + exchange.getRequestMethod() + " " + exchange.getRequestURI()); if (!"POST".equalsIgnoreCase(exchange.getRequestMethod())) { sendError(exchange, 405, "Method not allowed"); return; Loading @@ -67,30 +69,37 @@ public class HttpFileServer { Path tempDir = null; try { System.out.println("SERVER: Creating temp directory"); // Create temporary directory for uploaded files tempDir = Files.createTempDirectory(TEMP_DIR_PREFIX); // Parse multipart request String contentType = exchange.getRequestHeaders().getFirst("Content-Type"); System.out.println("SERVER: Content-Type: " + contentType); if (contentType == null || !contentType.startsWith("multipart/form-data")) { sendError(exchange, 400, "Expected multipart/form-data"); return; } String boundary = extractBoundary(contentType); System.out.println("SERVER: Extracted boundary: " + boundary); if (boundary == null) { sendError(exchange, 400, "No boundary found in Content-Type"); return; } System.out.println("SERVER: Starting multipart parse"); MultipartParser parser = new MultipartParser(exchange.getRequestBody(), boundary, tempDir); MultipartData data = parser.parse(); System.out.println("SERVER: Parse complete, files=" + data.files.size() + ", fields=" + data.fields.size()); if (data.files.isEmpty()) { sendError(exchange, 400, "No files uploaded"); return; } System.out.println("SERVER: Processing files"); // Process files with external command Path jsonResult = processor.process(data.files, data.fields); Loading @@ -99,6 +108,7 @@ public class HttpFileServer { return; } System.out.println("SERVER: Sending response"); // Send JSON response byte[] jsonBytes = Files.readAllBytes(jsonResult); exchange.getResponseHeaders().set("Content-Type", "application/json"); Loading @@ -107,15 +117,18 @@ public class HttpFileServer { os.write(jsonBytes); } System.out.println("SERVER: Response sent successfully"); // Cleanup result file Files.deleteIfExists(jsonResult); } catch (Exception e) { System.err.println("SERVER: Error occurred"); e.printStackTrace(); sendError(exchange, 500, "Processing error: " + e.getMessage()); } finally { // Cleanup temp directory if (tempDir != null) { System.out.println("SERVER: Cleaning up temp directory"); cleanupDirectory(tempDir); } } Loading Loading @@ -409,6 +422,8 @@ public class HttpFileServer { String jsonFile = "asn.json"; cmd.add(jsonFile); System.out.println("SERVER: Running "+cmd); // Execute command ProcessBuilder pb = new ProcessBuilder(cmd); pb.directory(workDir.toFile()); Loading @@ -424,7 +439,7 @@ public class HttpFileServer { .reduce((a, b) -> a + "\n" + b) .orElse(""); } System.out.println(output.replaceAll("\n", "\nTITAN: ")); int exitCode = process.waitFor(); if (exitCode != 0) { throw new RuntimeException("Command failed with exit code " + exitCode + ": " + output); Loading