From 1449de217cbadf485eb6b97aad8527d2095262ac Mon Sep 17 00:00:00 2001 From: Carol Alexandru Date: Wed, 13 Oct 2021 12:01:12 +0200 Subject: [PATCH] don't construct json manually --- .../lms/impl/olat/OlatLmsRestTemplate.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/olat/OlatLmsRestTemplate.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/olat/OlatLmsRestTemplate.java index 4e759384..bc026a1f 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/olat/OlatLmsRestTemplate.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/olat/OlatLmsRestTemplate.java @@ -9,6 +9,8 @@ package ch.ethz.seb.sebserver.webservice.servicelayer.lms.impl.olat; import java.io.IOException; +import java.util.HashMap; +import java.util.Map; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -68,13 +70,12 @@ public class OlatLmsRestTemplate extends RestTemplate { // Authenticate with OLAT and store the received X-OLAT-TOKEN this.token = "authenticating"; final String authUrl = this.details.getAccessTokenUri(); - final String credentials = String.format( - "{\"username\": \"%s\", \"password\": \"%s\"}", - this.details.getClientId(), - this.details.getClientSecret()); + final Map credentials = new HashMap<>(); + credentials.put("username", this.details.getClientId()); + credentials.put("password", this.details.getClientSecret()); final HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.set("content-type", "application/json"); - final HttpEntity requestEntity = new HttpEntity<>(credentials, httpHeaders); + final HttpEntity> requestEntity = new HttpEntity<>(credentials, httpHeaders); try { final ResponseEntity response = this.postForEntity(authUrl, requestEntity, String.class); final HttpHeaders responseHeaders = response.getHeaders();