Skip to content
Snippets Groups Projects
Commit 3995135a authored by OZGCloud's avatar OZGCloud
Browse files

OZG-723 fix Forwarding Mail encoding

parent 8907525c
No related branches found
No related tags found
No related merge requests found
...@@ -33,6 +33,8 @@ ...@@ -33,6 +33,8 @@
<zip.version>2.7.0</zip.version> <zip.version>2.7.0</zip.version>
<jsoup.version>1.13.1</jsoup.version> <jsoup.version>1.13.1</jsoup.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>
<dependencies> <dependencies>
......
mvn spring-boot:run -Dspring-boot.run.profiles=local ./mvnw spring-boot:run -Dspring-boot.run.profiles=local
package de.itvsh.ozg.pluto;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
@Configuration
public class BeansConfig {
@Bean
public FreeMarkerConfigurer freeMarkerConfigurer() {
FreeMarkerConfigurer freeMarkerConfigurer = new FreeMarkerConfigurer();
freeMarkerConfigurer.setTemplateLoaderPath("classpath:/templates");
freeMarkerConfigurer.setDefaultEncoding("UTF-8");
return freeMarkerConfigurer;
}
}
package de.itvsh.ozg.pluto.vorgang.redirect; package de.itvsh.ozg.pluto.vorgang.redirect;
import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStreamWriter; import java.io.StringWriter;
import java.time.ZoneOffset; import java.time.ZoneOffset;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import java.util.HashMap; import java.util.HashMap;
...@@ -18,6 +17,7 @@ import org.springframework.beans.factory.annotation.Value; ...@@ -18,6 +17,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.MimeTypeUtils; import org.springframework.util.MimeTypeUtils;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
import de.itvsh.ozg.mail.email.MailSendRequest; import de.itvsh.ozg.mail.email.MailSendRequest;
import de.itvsh.ozg.mail.email.MailSendRequest.MailAttachment; import de.itvsh.ozg.mail.email.MailSendRequest.MailAttachment;
...@@ -28,7 +28,6 @@ import de.itvsh.ozg.pluto.common.util.ForwardingLandesnetzInfoService; ...@@ -28,7 +28,6 @@ import de.itvsh.ozg.pluto.common.util.ForwardingLandesnetzInfoService;
import de.itvsh.ozg.pluto.vorgang.Vorgang; import de.itvsh.ozg.pluto.vorgang.Vorgang;
import de.itvsh.ozg.pluto.vorgang.VorgangService; import de.itvsh.ozg.pluto.vorgang.VorgangService;
import de.itvsh.ozg.pluto.vorgang.redirect.Forwarding.Status; import de.itvsh.ozg.pluto.vorgang.redirect.Forwarding.Status;
import freemarker.template.Configuration;
import freemarker.template.Template; import freemarker.template.Template;
import freemarker.template.TemplateException; import freemarker.template.TemplateException;
...@@ -62,7 +61,7 @@ public class ForwardingService { ...@@ -62,7 +61,7 @@ public class ForwardingService {
private ForwardingRepository repository; private ForwardingRepository repository;
@Autowired @Autowired
private Configuration freemarkerCfg; private FreeMarkerConfigurer freemarkerCfg;
@Autowired @Autowired
private MailService emailService; private MailService emailService;
...@@ -225,9 +224,12 @@ public class ForwardingService { ...@@ -225,9 +224,12 @@ public class ForwardingService {
} }
private String fillTemplate(String templateName, Object dataModel) { private String fillTemplate(String templateName, Object dataModel) {
try (var outStream = new ByteArrayOutputStream(); var writer = new OutputStreamWriter(outStream)) { try {
getTemplate(templateName).process(dataModel, writer); Template template = getTemplate(templateName);
return new String(outStream.toByteArray()); StringWriter stringWriter = new StringWriter();
template.process(dataModel, stringWriter);
return stringWriter.toString();
} catch (IOException | TemplateException e) { } catch (IOException | TemplateException e) {
throw new TechnicalException("Error filling mail template", e); throw new TechnicalException("Error filling mail template", e);
} }
...@@ -235,7 +237,7 @@ public class ForwardingService { ...@@ -235,7 +237,7 @@ public class ForwardingService {
Template getTemplate(String templateName) { Template getTemplate(String templateName) {
try { try {
return freemarkerCfg.getTemplate(templateName); return freemarkerCfg.getConfiguration().getTemplate(templateName);
} catch (IOException e) { } catch (IOException e) {
throw new TechnicalException("Error loading mail template", e); throw new TechnicalException("Error loading mail template", e);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment