From ef1338d6ec7db4d69123d4a2fb8ca375f1e98cca Mon Sep 17 00:00:00 2001 From: lunaiwa Date: Wed, 17 Apr 2024 14:10:46 -0700 Subject: [PATCH 1/3] judge0 building --- judge0-v1.13.0.zip | Bin 0 -> 4608 bytes judge0-v1.13.0/docker-compose.yml | 52 +++++ judge0-v1.13.0/judge0.conf | 358 ++++++++++++++++++++++++++++++ volumes/sqlite.db | Bin 106496 -> 106496 bytes 4 files changed, 410 insertions(+) create mode 100644 judge0-v1.13.0.zip create mode 100644 judge0-v1.13.0/docker-compose.yml create mode 100644 judge0-v1.13.0/judge0.conf diff --git a/judge0-v1.13.0.zip b/judge0-v1.13.0.zip new file mode 100644 index 0000000000000000000000000000000000000000..3b1b227d111baef3772e982caa4f14e110771ef9 GIT binary patch literal 4608 zcma)=byO72+Q)ZUSVDSPV(FCbSh`E;2I&x7YH373LOP^DX_jsf1r!NMNf893SwKR- zrBUkY{oOy_`~Kd0&pUHw=9xd{GtZp!oH^(F)w>VECII|tKmvrpKZAcwBmg=9!q3s! zNs!N9h+jyAUr@l<2p<6IAOI+yYq28zSy}(-#3&AHGIym$DhmJyt|c>Z(i|!%J;UGQJtrK98&NRZvVrH zN$OU(oJ2go}V0Lpz-YedRkGXS3=eTvuhETE!hnom? zax$ljz4k%FRG1qj-UV_X3u~ETlxl%#dBnwPb@U<$P^(C{B3RJm#%c)I{4!?^T)<#6 zfTB7(GCMIZ63w_hR6l^=9a#)l+EFn-Dt4Fh39;Ug^-!)dk3HTghE0Lfz(*U7FA z1~G^?lh`!$6tV9Vwe0(knOs?;3(CFefy_(^R(Xq!@CmaHti=evb!l?K2;AV802RE8 zbgebe+P*l86s4w?FMGER))iMoG!ItOS}RkX%fwA?g3;kyb|8pqQkOQ-saNZ=HEwZ{X=CfVO8|v-a zST}0y)sYN21ePUPte)dX29;5_o)F5CxFdE1dCM!HL+GHm`5Wz({K5uB=bxW3Xv~#> zl+Ben`0z+(;}J)i&n(Q`VdQleH8Uclhkw#yT3F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46R=dpM>(h)L%asBBS2q5v zXNd#S8oFFFB6&bVcY*EkA9n9ZCiYyy`QIWn@T7l1*LSSbm0#xgs2IkpQ!^cay9>( z)JW;D834(F?5|lQ%84O11K2qxMfVIKR855kDZi8*hrUS%P+a9({0t}L&@{jfS2Y}= zc+mOt3|wbGDRW$+%`U8k_Hamd@up$tv-#e^jTy;OnocM&s)0&NQ7={Bb6@Pi@%DP` z*ZVTcx8?Z{WoJ%mxS`)pg&}xrWeY6mLNAdFoCpZ^1d$xHJU-sP=6_n95W#aheJ9R7 z7iKO+drrJ@I>CAq0B(|rw?TXt7I3g>*Z-36ZG{;1dg7KYpiK)WAg^Cc!izuq5a4;- z#*9uEfl(Z_Z4$TNn7A`W@wQu~3z5D|^LieoRMF`gKl~!3s?0mp3RKp?tB+rIB)c~m z)V=y94Se5&FJ*Fj$HQOVMrL_@Yl1{qg#3+vLxsr{_~6N-8Hh9-BhCNVr9wIcOYc4q zivjeX{0!=UIUA&aeZ@cF-`owHzub+#IU9eV|H<3<3;Mfm0HxuYe~12?)A9e~|9c_+ iPyW?!N9BJd{eP9^f4T+-{O8r6-<|GvzT>2ScK-ke<{^&& literal 0 HcmV?d00001 diff --git a/judge0-v1.13.0/docker-compose.yml b/judge0-v1.13.0/docker-compose.yml new file mode 100644 index 0000000..d1a78d4 --- /dev/null +++ b/judge0-v1.13.0/docker-compose.yml @@ -0,0 +1,52 @@ +version: '2' + +x-logging: + &default-logging + logging: + driver: json-file + options: + max-size: 100m + +services: + server: + image: judge0/judge0:1.13.0 + volumes: + - ./judge0.conf:/judge0.conf:ro + ports: + - "2358:2358" + privileged: true + <<: *default-logging + restart: always + + workers: + image: judge0/judge0:1.13.0 + command: ["./scripts/workers"] + volumes: + - ./judge0.conf:/judge0.conf:ro + privileged: true + <<: *default-logging + restart: always + + db: + image: postgres:13.0 + env_file: judge0.conf + volumes: + - postgres-data:/var/lib/postgresql/data/ + <<: *default-logging + restart: always + + redis: + image: redis:6.0 + command: [ + "bash", "-c", + 'docker-entrypoint.sh --appendonly yes --requirepass "$$REDIS_PASSWORD"' + ] + env_file: judge0.conf + volumes: + - redis-data:/data + <<: *default-logging + restart: always + +volumes: + postgres-data: + redis-data: \ No newline at end of file diff --git a/judge0-v1.13.0/judge0.conf b/judge0-v1.13.0/judge0.conf new file mode 100644 index 0000000..ca54eef --- /dev/null +++ b/judge0-v1.13.0/judge0.conf @@ -0,0 +1,358 @@ +################################################################################ +# Judge0 Configuration File +################################################################################ +# Judge0 is a highly configurable which allows you to use it for many +# different use-cases. Please, before deploying Judge0 take a look at this +# configuration file that is divided in several logical sections that will help +# you understand what can you do with Judge0. +# +# This default configuration file is designed to work out of the box for you and +# you can start with it when deploying Judge0 on your server. +# +# If you have any questions please don't hasitate to send an email or open an +# issue on the GitHub page of the project. + + +################################################################################ +# Judge0 Server Configuration +################################################################################ +# Enable or disable Judge0 Telemetry. +# Read more about it here: https://github.com/judge0/judge0/blob/master/TELEMETRY.md +# Default: true +JUDGE0_TELEMETRY_ENABLE= + +# Automatically restart Judge0 server if it fails to start. +# Default: 10 +RESTART_MAX_TRIES= + +# Maintenance mode is a mode in which clients cannot +# create or delete submissions while maintenance is enabled. +# Default: false +MAINTENANCE_MODE= + +# Set custom maintenance message that will be returned to clients +# who try to create or delete submisions. +# Default: Judge0 is currently in maintenance. +MAINTENANCE_MESSAGE= + +# If enabled user can request to synchronically wait for +# submission result on submission create. +# Default: true, i.e. user can request to wait for the result +ENABLE_WAIT_RESULT= + +# If enabled user is allowed to set custom compiler options. +# Default: true +ENABLE_COMPILER_OPTIONS= + +# List language names, separated by space, for which setting compiler options is allowed. +# Note that ENABLE_COMPILER_OPTIONS has higher priority, so this option will be +# ignored if setting compiler options is disabled with ENABLE_COMPILER_OPTIONS. +# For example, ALLOWED_LANGUAGES_FOR_COMPILER_OPTIONS="C C++ Java" would only +# allow setting compiler options for languages C, C++ and Java. +# Default: empty - for every compiled language setting compiler options is allowed. +ALLOWED_LANGUAGES_FOR_COMPILER_OPTIONS= + +# If enabled user is allowed to set custom command line arguments. +# Default: true +ENABLE_COMMAND_LINE_ARGUMENTS= + +# If enabled autorized users can delete a submission. +# Default: false +ENABLE_SUBMISSION_DELETE= + +# If enabled user can GET and POST batched submissions. +# Default: true +ENABLE_BATCHED_SUBMISSIONS= + +# Maximum number of submissions that can be created or get in a batch. +# Default: 20 +MAX_SUBMISSION_BATCH_SIZE= + +# If enabled user can use callbacks. +# Default: true +ENABLE_CALLBACKS= + +# Maximum number of callback tries before giving up. +# Default: 3 +CALLBACKS_MAX_TRIES= + +# Timeout callback call after this many seconds. +# Default: 5 +CALLBACKS_TIMEOUT= + +# If enabled user can preset additional files in the sandbox. +# Default: true +ENABLE_ADDITIONAL_FILES= + +# Duration (in seconds) of submission cache. Decimal numbers are allowed. +# Set to 0 to turn of submission caching. Note that this does not apply to +# batched submissions. +# Default: 1 +SUBMISSION_CACHE_DURATION= + +# If true the documentation page will be used as a homepage, otherwise, the +# homepage will be empty. You can always access the documentation page via /docs. +# Default: false +USE_DOCS_AS_HOMEPAGE= + + +################################################################################ +# Judge0 Workers Configuration +################################################################################ +# Specify polling frequency in seconds. Decimal numbers are allowed. +# Default: 0.1 +INTERVAL= + +# Specify how many parallel workers to run. +# Default: 2*nproc (https://linux.die.net/man/1/nproc) +COUNT= + +# Specify maximum queue size. Represents maximum number of submissions that +# can wait in the queue at once. If request for new submission comes and the +# queue if full then submission will be rejected. +# Default: 100 +MAX_QUEUE_SIZE= + + +################################################################################ +# Judge0 Server Access Configuration +################################################################################ +# Allow only specified origins. +# If left blank, then all origins will be allowed (denoted with '*'). +# Example: +# ALLOW_ORIGIN="www.judge0.com judge0.com www.example.com blog.example.com" +ALLOW_ORIGIN= + +# Disallow only specified origins. +# If left blank, then no origin will be disallowed. +# Example: +# DISALLOW_ORIGIN="www.judge0.com judge0.com www.example.com blog.example.com" +DISALLOW_ORIGIN= + +# Allow only specified IP addresses. +# If left blank, then all IP addresses will be allowed. +# Example: +# ALLOW_IP="192.168.10.10 96.239.226.228 208.23.207.242" +ALLOW_IP= + +# Disallow only specified IP addresses. +# If left blank, then no IP addresses will be disallowed. +# Example: +# DISALLOW_IP="192.168.10.10 96.239.226.228 208.23.207.242" +DISALLOW_IP= + + +################################################################################ +# Judge0 Authentication Configuration +################################################################################ +# You can protect your API with (AUTHN_HEADER, AUTHN_TOKEN) pair. +# Each request then needs to have this pair either in headers or +# query parameters. For example let AUTHN_HEADER=X-Judge0-Token and +# AUTHN_TOKEN=mySecretToken. Then user should authenticate by sending this +# in headers or query parameters in each request, e.g.: +# https://api.judge0.com/system_info?X-Judge0-Token=mySecretToken + +# Specify authentication header name. +# Default: X-Auth-Token +AUTHN_HEADER= + +# Specify valid authentication tokens. +# Default: empty - authentication is disabled +AUTHN_TOKEN= + + +################################################################################ +# Judge0 Authorization Configuration +################################################################################ +# Protected API calls can be issued with (AUTHZ_HEADER, AUTHZ_TOKEN) pair. +# To see exactly which API calls are protected with authorization tokens +# please read the docs at https://api.judge0.com. +# API authorization ensures that only specified users call protected API calls. +# For example let AUTHZ_HEADER=X-Judge0-User and AUTHZ_TOKEN=mySecretToken. +# Then user should authorize be sending this in headers or query parameters in +# each request, e.g.: https://api.judge0.com/system_info?X-Judge0-User=mySecretToken +# Note that if you enabled authentication, then user should also send valid +# authentication token. + +# Specify authorization header name. +# Default: X-Auth-User +AUTHZ_HEADER= + +# Specify valid authorization tokens. +# Default: empty - authorization is disabled, protected API calls cannot be issued +AUTHZ_TOKEN= + + +################################################################################ +# Redis Configuration +################################################################################ +# Specify Redis host +# Default: localhost +REDIS_HOST=redis + +# Specify Redis port. +# Default: 6379 +REDIS_PORT= + +# Specify Redis password. Cannot be blank. +# Default: NO DEFAULT! MUST BE SET! +REDIS_PASSWORD=YourPasswordHere1234 + + +################################################################################ +# PostgreSQL Configuration +################################################################################ +# Specify Postgres host. +# Default: localhost +POSTGRES_HOST=db + +# Specify Postgres port. +# Default: 5432 +POSTGRES_PORT= + +# Name of the database to use. Used only in production. +# Default: postgres +POSTGRES_DB=judge0 + +# User who can access this database. Used only in production. +# Default: postgres +POSTGRES_USER=judge0 + +# Password of the user. Cannot be blank. Used only in production. +# Default: NO DEFAULT, YOU MUST SET YOUR PASSWORD +POSTGRES_PASSWORD=YourPasswordHere1234 + + +################################################################################ +# Submission Configuration +################################################################################ +# Judge0 uses isolate as an sandboxing environment. +# Almost all of the options you see here can be mapped to one of the options +# that isolate provides. For more information about these options please +# check for the isolate documentation here: +# https://raw.githubusercontent.com/ioi/isolate/master/isolate.1.txt + +# Default runtime limit for every program (in seconds). Decimal numbers are allowed. +# Time in which the OS assigns the processor to different tasks is not counted. +# Default: 5 +CPU_TIME_LIMIT= + +# Maximum custom CPU_TIME_LIMIT. +# Default: 15 +MAX_CPU_TIME_LIMIT= + +# When a time limit is exceeded, wait for extra time (in seconds), before +# killing the program. This has the advantage that the real execution time +# is reported, even though it slightly exceeds the limit. +# Default: 1 +CPU_EXTRA_TIME= + +# Maximum custom CPU_EXTRA_TIME. +# Default: 5 +MAX_CPU_EXTRA_TIME= + +# Limit wall-clock time in seconds. Decimal numbers are allowed. +# This clock measures the time from the start of the program to its exit, +# so it does not stop when the program has lost the CPU or when it is waiting +# for an external event. We recommend to use CPU_TIME_LIMIT as the main limit, +# but set WALL_TIME_LIMIT to a much higher value as a precaution against +# sleeping programs. +# Default: 10 +WALL_TIME_LIMIT= + +# Maximum custom WALL_TIME_LIMIT. +# Default: 20 +MAX_WALL_TIME_LIMIT= + +# Limit address space of the program in kilobytes. +# Default: 128000 +MEMORY_LIMIT= + +# Maximum custom MEMORY_LIMIT. +# Default: 512000 +MAX_MEMORY_LIMIT= + +# Limit process stack in kilobytes. +# Default: 64000 +STACK_LIMIT= + +# Maximum custom STACK_LIMIT. +# Default: 128000 +MAX_STACK_LIMIT= + +# Maximum number of processes and/or threads program can create. +# Default: 60 +MAX_PROCESSES_AND_OR_THREADS= + +# Maximum custom MAX_PROCESSES_AND_OR_THREADS. +# Default: 120 +MAX_MAX_PROCESSES_AND_OR_THREADS= + +# If true then CPU_TIME_LIMIT will be used as per process and thread. +# Default: false, i.e. CPU_TIME_LIMIT is set as a total limit for all processes and threads. +ENABLE_PER_PROCESS_AND_THREAD_TIME_LIMIT= + +# If false, user won't be able to set ENABLE_PER_PROCESS_AND_THREAD_TIME_LIMIT. +# Default: true +ALLOW_ENABLE_PER_PROCESS_AND_THREAD_TIME_LIMIT= + +# If true then MEMORY_LIMIT will be used as per process and thread. +# Default: false, i.e. MEMORY_LIMIT is set as a total limit for all processes and threads. +ENABLE_PER_PROCESS_AND_THREAD_MEMORY_LIMIT= + +# If false, user won't be able to set ENABLE_PER_PROCESS_AND_THREAD_MEMORY_LIMIT. +# Default: true +ALLOW_ENABLE_PER_PROCESS_AND_THREAD_MEMORY_LIMIT= + +# Limit size of files created (or modified) by the program in kilobytes. +# Default: 1024 +MAX_FILE_SIZE= + +# Maximum custom MAX_FILE_SIZE. +# Default: 4096 +MAX_MAX_FILE_SIZE= + +# Run each program this many times and take average of time and memory. +# Default: 1 +NUMBER_OF_RUNS= + +# Maximum custom NUMBER_OF_RUNS. +# Default: 20 +MAX_NUMBER_OF_RUNS= + +# Redirect stderr to stdout. +# Default: false +REDIRECT_STDERR_TO_STDOUT= + +# Maximum total size (in kilobytes) of extracted files from additional files archive. +# Default: 10240, i.e. maximum of 10MB in total can be extracted. +MAX_EXTRACT_SIZE= + +# If false, user won't be able to set ENABLE_NETWORK. +# Default: true, i.e. allow user to permit or deny network calls from the submission. +ALLOW_ENABLE_NETWORK= + +# If true submission will by default be able to do network calls. +# Default: false, i.e. programs cannot do network calls. +ENABLE_NETWORK= + + +################################################################################ +# Rails Configuration +################################################################################ +# Specify Rails environment: production or development +# Default: production +RAILS_ENV= + +# Specify maximum number of concurrent Rails threads. +# Default: nproc (https://linux.die.net/man/1/nproc) +RAILS_MAX_THREADS= + +# Specify how many processes will be created for handing requests. Each process +# will aditionally create RAILS_MAX_THREADS threads. +# Default: 2 +RAILS_SERVER_PROCESSES= + +# Secret key base for production, if not set it will be randomly generated +# Default: randomly generated +SECRET_KEY_BASE= diff --git a/volumes/sqlite.db b/volumes/sqlite.db index 589e9a62f65be0d7f5081d30d40bf7f4ad64c1a4..2af356d1e515760b881a8fa2ec650060c34204fc 100644 GIT binary patch delta 613 zcmZoTz}9epZGtqT>qHr6M%RrAOU{dN@-s8=Kj%Nizn*^*e>s07zXiW6Kl5fmftP%y z5}YiIhK!~msl_D<8Tkbc>A8uSIeN+Yxu%jFER4pCCSaM8{G>{Rl*wd^`)7cro?+ns z!~c!{1OF@jC;a#LZ}4B@KLa#%6F(0tGb5uZCx|rRn0({C9?LHV{$D_;_xy?sER0M{ z4AXfT7#KL&g&Fvn_!xN^x&L!Ba{lM|%fZer3{>`$O|G$!Q=E~5lLH9UIT{&+8(En+ z1RK>D897XW&YZ5u#pq%WWT+S=su&umL>c>ey5*Y}`+A2v>iGtT`X=V)1nLz`xOMHvv delta 218 zcmZoTz}9epZGtqT?L--8M%#@EOU?_i^II_RKj%Nizn*^*e>s07zr|)j0VV#)7WdBp zdb{hynW^FPO5pzL#w z?SDBK+1Y`5^BMS$@!#a1$G?%kgFm1D9Z)use|o+=<5c_x%klEBW8lBe|C|3J|5u>H p-t!;kf62dx|1tko{=59^fX4LjPhaQH7_ph{z(4-&ED4N%>;e7>OUnQN From 144a53d0ff9290f586fab4d106b6a958f51c1045 Mon Sep 17 00:00:00 2001 From: lunaiwa Date: Mon, 27 May 2024 22:42:32 -0700 Subject: [PATCH 2/3] judge0 adding in controller ? --- .../mvc/javacompiler/Judge0Controller.java | 48 +++++++++++++++++++ .../mvc/javacompiler/MainApplication.java | 11 +++++ 2 files changed, 59 insertions(+) create mode 100644 src/main/java/com/nighthawk/spring_portfolio/mvc/javacompiler/Judge0Controller.java create mode 100644 src/main/java/com/nighthawk/spring_portfolio/mvc/javacompiler/MainApplication.java diff --git a/src/main/java/com/nighthawk/spring_portfolio/mvc/javacompiler/Judge0Controller.java b/src/main/java/com/nighthawk/spring_portfolio/mvc/javacompiler/Judge0Controller.java new file mode 100644 index 0000000..1c70565 --- /dev/null +++ b/src/main/java/com/nighthawk/spring_portfolio/mvc/javacompiler/Judge0Controller.java @@ -0,0 +1,48 @@ +package com.nighthawk.spring_portfolio.mvc.javacompiler; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.*; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.client.RestTemplate; + +import java.util.HashMap; +import java.util.Map; + +@RestController +@RequestMapping("/api") +public class Judge0Controller { + + @Value("${judge0.api.url}") + private String judge0ApiUrl; + + @Value("${judge0.api.key}") + private String judge0ApiKey; + + @PostMapping("/compile") + public ResponseEntity> compileAndRun(@RequestBody Map request) { + String sourceCode = request.get("code"); + String languageId = "62"; // Language ID for Java in Judge0 + + RestTemplate restTemplate = new RestTemplate(); + + // Prepare request payload + Map payload = new HashMap<>(); + payload.put("source_code", sourceCode); + payload.put("language_id", languageId); + + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + headers.set("X-RapidAPI-Key", judge0ApiKey); // Set your RapidAPI key here if using RapidAPI + + HttpEntity> entity = new HttpEntity<>(payload, headers); + + // Send POST request to Judge0 + ResponseEntity response = restTemplate.postForEntity(judge0ApiUrl + "/submissions?base64_encoded=false&wait=true", entity, Map.class); + + Map responseBody = response.getBody(); + + Map result = new HashMap<>(); + if (responseBody != null && responseBody.containsKey("stdout")) { + result.put("output", responseBody.get("stdout")); + } else if (responseBody != null && responseBody.containsKey("stderr")) { + diff --git a/src/main/java/com/nighthawk/spring_portfolio/mvc/javacompiler/MainApplication.java b/src/main/java/com/nighthawk/spring_portfolio/mvc/javacompiler/MainApplication.java new file mode 100644 index 0000000..29b0a90 --- /dev/null +++ b/src/main/java/com/nighthawk/spring_portfolio/mvc/javacompiler/MainApplication.java @@ -0,0 +1,11 @@ +package com.nighthawk.spring_portfolio.mvc.javacompiler; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class MainApplication { + public static void main(String[] args) { + SpringApplication.run(MainApplication.class, args); + } +} From 02089cb1d519e7abeae68d9d18f38999524cf10a Mon Sep 17 00:00:00 2001 From: lunaiwa Date: Tue, 28 May 2024 00:08:49 -0700 Subject: [PATCH 3/3] fixed version --- .../JudgeController.java} | 16 ++++++++++++---- .../MainApplication.java | 2 +- src/main/resources/application.properties | 4 ++++ 3 files changed, 17 insertions(+), 5 deletions(-) rename src/main/java/com/nighthawk/spring_portfolio/mvc/{javacompiler/Judge0Controller.java => compile/JudgeController.java} (75%) rename src/main/java/com/nighthawk/spring_portfolio/mvc/{javacompiler => compile}/MainApplication.java (83%) diff --git a/src/main/java/com/nighthawk/spring_portfolio/mvc/javacompiler/Judge0Controller.java b/src/main/java/com/nighthawk/spring_portfolio/mvc/compile/JudgeController.java similarity index 75% rename from src/main/java/com/nighthawk/spring_portfolio/mvc/javacompiler/Judge0Controller.java rename to src/main/java/com/nighthawk/spring_portfolio/mvc/compile/JudgeController.java index 1c70565..2d0919a 100644 --- a/src/main/java/com/nighthawk/spring_portfolio/mvc/javacompiler/Judge0Controller.java +++ b/src/main/java/com/nighthawk/spring_portfolio/mvc/compile/JudgeController.java @@ -1,4 +1,4 @@ -package com.nighthawk.spring_portfolio.mvc.javacompiler; +package com.nighthawk.spring_portfolio.mvc.compile; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.*; @@ -10,7 +10,7 @@ @RestController @RequestMapping("/api") -public class Judge0Controller { +public class JudgeController { @Value("${judge0.api.url}") private String judge0ApiUrl; @@ -19,6 +19,7 @@ public class Judge0Controller { private String judge0ApiKey; @PostMapping("/compile") + @CrossOrigin(origins = "*") // This allows requests from any origin. Adjust as needed for security. public ResponseEntity> compileAndRun(@RequestBody Map request) { String sourceCode = request.get("code"); String languageId = "62"; // Language ID for Java in Judge0 @@ -32,7 +33,7 @@ public ResponseEntity> compileAndRun(@RequestBody Map> entity = new HttpEntity<>(payload, headers); @@ -45,4 +46,11 @@ public ResponseEntity> compileAndRun(@RequestBody Map