Skip to content

Commit d2db30a

Browse files
Bert-Raristotelos
authored andcommitted
YD-603 Upgrade to Spring Boot 2.1.2 (#533)
This includes an upgrade to Spring Cloud 2.1.0 Two changes were needed to make everything work again: * Add an exception mapping for "Payload Too Large" (we now return the appropriate HTTP status: 413) * Spring Boot autoconfigured an in-memory LDAP when LDAP is disabled through the Yona settings. This autoconfiguration is disabled.
1 parent 1d13e61 commit d2db30a

File tree

5 files changed

+25
-6
lines changed

5 files changed

+25
-6
lines changed

appservice/src/intTest/groovy/nu/yona/server/UserPhotoTest.groovy

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2017, 2018 Stichting Yona Foundation
2+
* Copyright (c) 2017, 2019 Stichting Yona Foundation
33
* This Source Code Form is subject to the terms of the Mozilla Public License,
44
* v.2.0. If a copy of the MPL was not distributed with this file, You can
55
* obtain one at https://mozilla.org/MPL/2.0/.
@@ -114,7 +114,7 @@ class UserPhotoTest extends AbstractAppServiceIntegrationTest
114114
def response = appService.yonaServer.restClient.put(path: richard.editUserPhotoUrl, requestContentType :"multipart/form-data", headers: ["Yona-Password": richard.password], body: multipartEntity)
115115

116116
then:
117-
assertResponseStatus(response, 400)
117+
assertResponseStatus(response, 413)
118118
response.responseData.code == null // As the app should take care for uploading a resized photo, this is not a user error, so it does not need to have a code
119119

120120
cleanup:

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ plugins {
1212
id "eclipse"
1313
id "groovy"
1414
id "io.spring.dependency-management" version "1.0.6.RELEASE"
15-
id "org.springframework.boot" version "2.0.4.RELEASE" apply false
15+
id "org.springframework.boot" version "2.1.2.RELEASE" apply false
1616
id "net.researchgate.release" version "2.6.0"
1717
id "com.bmuschko.docker-remote-api" version "3.6.1" apply false
1818
}

core/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ dependencies {
2828
compile "org.springframework.boot:spring-boot-starter-data-jpa"
2929
compile "org.springframework.boot:spring-boot-starter-web"
3030
compile "org.springframework.boot:spring-boot-starter-actuator"
31-
compile "org.springframework.cloud:spring-cloud-starter-sleuth:2.0.1.RELEASE"
31+
compile "org.springframework.cloud:spring-cloud-starter-sleuth:2.1.0.RELEASE"
3232
compile "org.springframework.metrics:spring-metrics:0.5.1.RELEASE"
3333
compile "io.micrometer:micrometer-registry-prometheus:1.0.6"
3434
compile "org.springframework:spring-context-support"

core/src/main/java/nu/yona/server/CoreConfiguration.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
/*******************************************************************************
2-
* Copyright (c) 2015, 2018 Stichting Yona Foundation This Source Code Form is subject to the terms of the Mozilla Public License,
2+
* Copyright (c) 2015, 2019 Stichting Yona Foundation This Source Code Form is subject to the terms of the Mozilla Public License,
33
* v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
44
*******************************************************************************/
55
package nu.yona.server;
66

77
import java.util.Properties;
88

99
import org.springframework.beans.factory.annotation.Autowired;
10+
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
1011
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
12+
import org.springframework.boot.autoconfigure.ldap.LdapAutoConfiguration;
1113
import org.springframework.context.annotation.Bean;
1214
import org.springframework.context.annotation.Configuration;
1315
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
@@ -34,6 +36,7 @@
3436
@EnableHypermediaSupport(type = HypermediaType.HAL)
3537
@EnableSpringDataWebSupport
3638
@Configuration
39+
@EnableAutoConfiguration(exclude = { LdapAutoConfiguration.class })
3740
public class CoreConfiguration
3841
{
3942
@Autowired

core/src/main/java/nu/yona/server/rest/GlobalExceptionMapping.java

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2016, 2018 Stichting Yona Foundation This Source Code Form is subject to the terms of the Mozilla Public License,
2+
* Copyright (c) 2016, 2019 Stichting Yona Foundation This Source Code Form is subject to the terms of the Mozilla Public License,
33
* v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
44
*******************************************************************************/
55
package nu.yona.server.rest;
@@ -25,6 +25,7 @@
2525
import org.springframework.web.bind.annotation.ResponseBody;
2626
import org.springframework.web.bind.annotation.ResponseStatus;
2727
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
28+
import org.springframework.web.multipart.MaxUploadSizeExceededException;
2829

2930
import nu.yona.server.Translator;
3031
import nu.yona.server.exceptions.YonaException;
@@ -131,6 +132,21 @@ public ErrorResponseDto handleMediaTypeNotAcceptableException(HttpMediaTypeNotAc
131132
return logUnhandledExceptionAndCreateErrorDto("does not accept our supported media types", exception, request);
132133
}
133134

135+
/**
136+
* Maximum upload size exceeded. Such requests result in a 413 (Payload Too Large).
137+
*
138+
* @param exception The exception.
139+
* @return The response object to return.
140+
*/
141+
@ExceptionHandler(MaxUploadSizeExceededException.class)
142+
@ResponseStatus(HttpStatus.PAYLOAD_TOO_LARGE)
143+
@ResponseBody
144+
public ErrorResponseDto handleMaxUploadSizeExceededException(MaxUploadSizeExceededException exception,
145+
HttpServletRequest request)
146+
{
147+
return logUnhandledExceptionAndCreateErrorDto("exceeds the maximum request size", exception, request);
148+
}
149+
134150
private ErrorResponseDto logUnhandledExceptionAndCreateErrorDto(String message, Exception exception,
135151
HttpServletRequest request)
136152
{

0 commit comments

Comments
 (0)