From 189efc3254cf41b878ba69a6a48f1e2d9d31d6ea Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 22 May 2023 17:58:10 +0200 Subject: [server] Restore Java 1.8 compat for now Since this is really the only place so far, refactor to support older Java. Let's move to 11+ after the next release. --- dozentenmodulserver/pom.xml | 6 +++--- .../java/org/openslx/bwlp/sat/thrift/JsonHttpListener.java | 10 +++++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/dozentenmodulserver/pom.xml b/dozentenmodulserver/pom.xml index 3493feb8..26666ac5 100644 --- a/dozentenmodulserver/pom.xml +++ b/dozentenmodulserver/pom.xml @@ -140,9 +140,9 @@ maven-compiler-plugin 3.8.1 - 11 - 11 - 11 + 1.8 + 1.8 + 8 -Xlint:all diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/JsonHttpListener.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/JsonHttpListener.java index 55c09756..cec5dd5f 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/JsonHttpListener.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/JsonHttpListener.java @@ -57,7 +57,15 @@ public class JsonHttpListener extends NanoHTTPD { return new Response(Response.Status.BAD_REQUEST, "text/plain; charset=UTF-8", "No Content-Length provided"); - byte[] buffer = session.getInputStream().readNBytes(len); + byte[] buffer = new byte[len]; + int pos = 0; + while (pos < len) { + int ret = session.getInputStream().read(buffer, pos, len - pos); + if (ret <= 0) + return new Response(Response.Status.BAD_REQUEST, "text/plain; charset=UTF-8", + "Request content truncated (" + pos + "/" + len + ")"); + pos += ret; + } TMemoryBuffer inbuffer = new TMemoryBuffer(buffer.length); inbuffer.write(buffer); TProtocol inprotocol = new TJSONProtocol(inbuffer); -- cgit v1.2.3-55-g7522