Skip to content

Commit

Permalink
Merge pull request #111 from Onlineberatung/TSYSTEMS-196-upgrade-spri…
Browse files Browse the repository at this point in the history
…ng-boot-to-3.3.X-mailservice

Tsystems 196 upgrade spring boot to 3.3.x mailservice
  • Loading branch information
tkuzynow authored Feb 7, 2025
2 parents f7acaa7 + 9bdcc22 commit 7e81a5c
Show file tree
Hide file tree
Showing 25 changed files with 253 additions and 242 deletions.
64 changes: 42 additions & 22 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.6</version>
<version>3.3.8</version>
<relativePath/>
</parent>

Expand All @@ -29,7 +29,7 @@
<openapi-generator-maven-plugin.version>6.6.0</openapi-generator-maven-plugin.version>
<springfox-swagger2.version>3.0.0</springfox-swagger2.version>
<jackson-databind-nullable.version>0.2.3</jackson-databind-nullable.version>
<spring-security.version>6.0.5</spring-security.version>
<spring-security.version>6.3.4</spring-security.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<hibernate.validator.version>8.0.0.Final</hibernate.validator.version>
Expand Down Expand Up @@ -68,12 +68,10 @@
<dependency>
<groupId>javax.cache</groupId>
<artifactId>cache-api</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>${hibernate-validator.version}</version>
</dependency>

<!-- OpenApi/Swagger dependencies -->
Expand Down Expand Up @@ -109,22 +107,20 @@
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.4.0</version>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>${javax.ws.rs-api.version}</version>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
</dependency>
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.3.1</version>
<groupId>jakarta.xml.ws</groupId>
<artifactId>jakarta.xml.ws-api</artifactId>
<version>2.3.3</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>${spring-security.version}</version>
</dependency>


Expand All @@ -145,7 +141,6 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
Expand Down Expand Up @@ -193,12 +188,10 @@
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-to-slf4j</artifactId>
<version>${log4j.version}</version>
</dependency>

<dependency>
Expand All @@ -221,7 +214,12 @@
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>4.0.3</version>
<scope>provided</scope>
</dependency>

<!-- Spring actuator -->
Expand All @@ -242,13 +240,17 @@
</exclusion>
</exclusions>
</dependency>

<!-- test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-junit</artifactId>
<version>2.0.0.0</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

Expand Down Expand Up @@ -300,7 +302,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.1</version>
<version>3.6.0</version>
<executions>
<execution>
<id>validate</id>
Expand Down Expand Up @@ -356,6 +358,24 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.openrewrite.maven</groupId>
<artifactId>rewrite-maven-plugin</artifactId>
<version>6.0.4</version>
<configuration>
<exportDatatables>true</exportDatatables>
<activeRecipes>
<recipe>org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_3</recipe>
</activeRecipes>
</configuration>
<dependencies>
<dependency>
<groupId>org.openrewrite.recipe</groupId>
<artifactId>rewrite-spring</artifactId>
<version>6.0.2</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import de.caritas.cob.mailservice.api.exception.InternalServerErrorException;
import de.caritas.cob.mailservice.api.service.LogService;
import java.net.UnknownHostException;
import javax.validation.ConstraintViolationException;
import jakarta.validation.ConstraintViolationException;
import lombok.NoArgsConstructor;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import de.caritas.cob.mailservice.api.model.MailsDTO;
import de.caritas.cob.mailservice.api.service.MailService;
import de.caritas.cob.mailservice.generated.api.controller.MailsApi;
import io.swagger.annotations.Api;
import javax.validation.Valid;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
Expand All @@ -18,8 +18,8 @@

/** Controller for mail requests. */
@RestController
@Tag(name = "mails-controller")
@RequiredArgsConstructor
@Api(tags = "mails-controller")
public class MailController implements MailsApi {

private final @NonNull MailService mailService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import javax.annotation.PostConstruct;
import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.thymeleaf.TemplateEngine;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public String fetchDefaultTranslations(
return String.join("", fileLines);
} catch (IOException ex) {
throw new IllegalStateException(
String.format(
"Json file with translations could not be loaded, translation component name: %s",
"Json file with translations could not be loaded, translation component name: %s".formatted(
translationComponentName),
ex);
}
Expand All @@ -60,8 +59,7 @@ private FileInputStream buildStreamForExternalPath(
String translationComponentName, String languageCode, Dialect dialect) {
try {
String filename =
String.format(
"%s/%s.%s%s.json",
"%s/%s.%s%s.json".formatted(
customTranslationsPath,
translationComponentName.toLowerCase(),
languageCode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private void prepareAndSendMail(
LogService.logDebug("email sent");
} catch (Exception e) {
throw new ExchangeMailServiceException(
String.format("Error while sending Exchange email: %s", msg.toString()), e);
"Error while sending Exchange email: %s".formatted(msg.toString()), e);
} finally {
exchangeService.close();
}
Expand All @@ -115,7 +115,7 @@ private void setupExchangeService(ExchangeService exchangeService)
} catch (URISyntaxException e) {
exchangeService.close();
throw new ExchangeMailServiceException(
String.format("Could not set ExchangeMailService URL %s ", this.exchangeUrl), e);
"Could not set ExchangeMailService URL %s ".formatted(this.exchangeUrl), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class MailErrorMessageBuilder {
*/
public String buildEmailErrorMessage(MailDTO mail, Exception ex) {
String errorMessage =
String.format("Mail request for template %s could not be executed.", mail.getTemplate());
"Mail request for template %s could not be executed.".formatted(mail.getTemplate());

return "Error message:" + errorMessage + "\n" + replaceMailAddresses(getStackTrace(ex));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private Consumer<MailDTO> renderAndSendHtmlMail() {

private void logAndSendErrorMessage(MailDTO mail) {
String errorMessage =
String.format("Template description %s could not be found.", mail.getTemplate());
"Template description %s could not be found.".formatted(mail.getTemplate());
LogService.logError(errorMessage);
sendErrorMail(errorMessage);
}
Expand All @@ -83,7 +83,7 @@ private void renderAndSend(MailDTO mail, TemplateDescription desc, Map<String, O
.render(desc, mail, data)
.ifPresent(text -> sendHtmlMail(mail, desc, text, subject));
} catch (TemplateServiceException e) {
var message = String.format("Could not load template: %s", e.getMessage());
var message = "Could not load template: %s".formatted(e.getMessage());
throw new InternalServerErrorException(message, e);
}
}
Expand All @@ -100,7 +100,7 @@ private void sendHtmlMail(
}
} catch (SmtpMailServiceException | ExchangeMailServiceException e) {
throw new InternalServerErrorException(
String.format("Could not send HTML mail: %s", e.getMessage()), e);
"Could not send HTML mail: %s".formatted(e.getMessage()), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.io.FileInputStream;
import java.util.List;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.ClassPathResource;
Expand Down Expand Up @@ -42,7 +41,6 @@ public class SmtpMailService {
private boolean useCustomResourcesPath;

/** Standard constructor for mail service */
@Autowired
public SmtpMailService(JavaMailSender javaMailSender) {
this.javaMailSender = javaMailSender;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ private TemplateDescription loadTemplateDescription(String templateName)
return mapper.readValue(templateDescriptionJson, TemplateDescription.class);
} catch (Exception ex) {
throw new TemplateDescriptionServiceException(
String.format(
"Json file with template description could not be parsed, template name: %s",
"Json file with template description could not be parsed, template name: %s".formatted(
templateName),
ex);
}
Expand All @@ -78,8 +77,7 @@ private String loadTemplateDescriptionFile(String templateName)
return String.join("", fileLines);
} catch (Exception ex) {
throw new TemplateDescriptionServiceException(
String.format(
"Json file with template description could not be loaded, template name: %s",
"Json file with template description could not be loaded, template name: %s".formatted(
templateName),
ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ public Optional<String> render(TemplateDescription desc, MailDTO mail, Map<Strin

if (!CollectionUtils.isEmpty(missingFieldList)) {
throw new TemplateServiceException(
String.format(
"Mail request for template %s could not be executed due to missing fields for template processing. Missing fields: %s",
"Mail request for template %s could not be executed due to missing fields for template processing. Missing fields: %s".formatted(
mail.getTemplate(), String.join(",", missingFieldList)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ public Map<String, String> fetchTranslations(String languageCode, Dialect dialec
return fetchTranslationAsMap(languageCode, dialect);
} catch (JsonProcessingException ex) {
throw new TranslationServiceException(
String.format(
"Json file with translations could not be parsed, translation component name: %s",
"Json file with translations could not be parsed, translation component name: %s".formatted(
component),
ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,18 @@ public class SecurityConfig {
public SecurityFilterChain configure(HttpSecurity http) throws Exception {

var httpSecurity =
http.csrf()
.disable()
http.csrf(csrf -> csrf
.disable())
.addFilterBefore(
new StatelessCsrfFilter(csrfCookieProperty, csrfHeaderProperty), CsrfFilter.class);

httpSecurity
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.sessionAuthenticationStrategy(new NullAuthenticatedSessionStrategy())
.and()
.authorizeRequests()
.anyRequest()
.permitAll();
.sessionManagement(management -> management
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.sessionAuthenticationStrategy(new NullAuthenticatedSessionStrategy()))
.authorizeHttpRequests(requests -> requests
.anyRequest()
.permitAll());

return httpSecurity.build();
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ spring.profiles.active=@activeSpringProfile@
# General app settings
server.port=8080

spring.mvc.locale=de_DE
spring.web.locale=de_DE
spring.jackson.time-zone=Europe/Berlin

# Logging: SLF4J (via Lombok)
Expand Down Expand Up @@ -73,7 +73,7 @@ weblate.component=mailing
management.endpoint.health.enabled=true
management.endpoint.health.show-details=never
management.endpoints.web.exposure.include=health
management.health.probes.enabled=true
management.endpoint.health.probes.enabled=true
spring.cache.jcache.config=classpath:ehcache.xml

logging.level.net.sf.ehcache=info
Expand Down
3 changes: 1 addition & 2 deletions src/test/java/de/caritas/cob/mailservice/api/ResourceIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ void descriptionShouldHaveSubjectKey() throws IOException {
var subjectKey = desc.getSubject();
assertNotNull(
subjectKey,
String.format(
"Json file with resource description does not contain subject key: %s",
"Json file with resource description does not contain subject key: %s".formatted(
jsonFile.getFilename()));
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package de.caritas.cob.mailservice.api.controller;

import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static jakarta.ws.rs.core.MediaType.APPLICATION_JSON;
import static org.hamcrest.Matchers.is;
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
Expand Down
Loading

0 comments on commit 7e81a5c

Please sign in to comment.