Skip to content
This repository was archived by the owner on Dec 4, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,25 +82,9 @@ public void handle(HttpExchange httpExchange) throws IOException {
}
}

private String getRequestBody(HttpExchange httpExchange) throws IOException {
StringBuilder buffer = new StringBuilder();
InputStream stream = httpExchange.getRequestBody();
int rByte;
while ((rByte = stream.read()) != -1) {
buffer.append((char)rByte);
}
stream.close();
if (buffer.length() > 0) {
return URLDecoder.decode(buffer.toString(), "UTF-8");
}
return "";
}

private Activity getActivity(HttpExchange httpExchange) {
try {
String body = getRequestBody(httpExchange);
LOGGER.log(Level.INFO, body);
return objectMapper.readValue(body, Activity.class);
try (InputStream is = httpExchange.getRequestBody()) {
return objectMapper.readValue(is, Activity.class);
} catch (Exception ex) {
LOGGER.log(Level.WARNING, "Failed to get activity", ex);
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,22 +82,8 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)

// Creates an Activity object from the request
private Activity getActivity(HttpServletRequest request) throws IOException {
String body = getRequestBody(request);
return objectMapper.readValue(body, Activity.class);
}

private String getRequestBody(HttpServletRequest request) throws IOException {
StringBuilder buffer = new StringBuilder();
try (InputStream stream = request.getInputStream()) {
int rByte;
while ((rByte = stream.read()) != -1) {
buffer.append((char) rByte);
}
stream.close();
if (buffer.length() > 0) {
return buffer.toString();
}
return "";
try(InputStream is = request.getInputStream()) {
return objectMapper.readValue(is, Activity.class);
}
}
}