Skip to content
Snippets Groups Projects
Commit 60e4f71c authored by Hamza Remmal's avatar Hamza Remmal
Browse files

Merge branch 'backport-298' into '1.2.x'

Merge branch 'configure-packet-sizes-from-moodle' into '1.2.x'

See merge request !299
parents 061ec817 3bd89951
No related branches found
No related tags found
1 merge request!299Merge branch 'configure-packet-sizes-from-moodle' into '1.2.x'
Pipeline #232947 passed
package ch.epfl.autograde.config;
import com.fasterxml.jackson.core.StreamReadConstraints;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class JacksonConfig {
@Bean
public ObjectMapper mapper() {
final var mapper = new ObjectMapper();
mapper.getFactory()
.setStreamReadConstraints(
StreamReadConstraints.builder()
.maxStringLength(Integer.MAX_VALUE)
.build()
);
return mapper;
};
}
...@@ -42,6 +42,8 @@ public final class MoodleWebService { ...@@ -42,6 +42,8 @@ public final class MoodleWebService {
/** Config properties for Moodle */ /** Config properties for Moodle */
private final AutogradeMoodleConfig properties; private final AutogradeMoodleConfig properties;
private final ObjectMapper mapper;
// ============================================================================================ // ============================================================================================
// ===================================== GENERIC FUNCTION ===================================== // ===================================== GENERIC FUNCTION =====================================
// ============================================================================================ // ============================================================================================
...@@ -111,7 +113,7 @@ public final class MoodleWebService { ...@@ -111,7 +113,7 @@ public final class MoodleWebService {
final var params = Map.of( final var params = Map.of(
"submissionid", submissionid, "submissionid", submissionid,
"grade", grade, "grade", grade,
"files", new ObjectMapper().writeValueAsString(feedback) "files", mapper.writeValueAsString(feedback)
); );
// HR : Call the moodle web service // HR : Call the moodle web service
var response = call(FUNCTION_NAME, params, ofString()); var response = call(FUNCTION_NAME, params, ofString());
...@@ -163,7 +165,7 @@ public final class MoodleWebService { ...@@ -163,7 +165,7 @@ public final class MoodleWebService {
try { try {
var response = call(FUNCTION_NAME, params, ofString(UTF_8)); var response = call(FUNCTION_NAME, params, ofString(UTF_8));
return new ObjectMapper().readValue(response.body(), new TypeReference<>() {}); return mapper.readValue(response.body(), new TypeReference<>() {});
} catch (URISyntaxException | IOException | InterruptedException e) { } catch (URISyntaxException | IOException | InterruptedException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
...@@ -187,7 +189,7 @@ public final class MoodleWebService { ...@@ -187,7 +189,7 @@ public final class MoodleWebService {
throw new IllegalStateException(); throw new IllegalStateException();
} }
// HR : Deserialize the request // HR : Deserialize the request
return new ObjectMapper().readValue(response.body(), new TypeReference<>() {}); return mapper.readValue(response.body(), new TypeReference<>() {});
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment