Continue structural port from Spring Boot to Undertow

- Notification template generator
- Add tests for email notification handler
This commit is contained in:
Max Dor
2018-12-30 16:45:30 +01:00
parent 7ad985fead
commit ace5918342
5 changed files with 100 additions and 15 deletions

View File

@@ -28,10 +28,10 @@ public class EmailTemplateConfig extends GenericTemplateConfig {
private transient final Logger log = LoggerFactory.getLogger(EmailTemplateConfig.class);
public EmailTemplateConfig() {
setInvite("classpath:threepids/email/invite-template.eml");
getGeneric().put("matrixId", "classpath:threepids/email/mxid-template.eml");
getSession().getValidation().setLocal("classpath:threepids/email/validate-local-template.eml");
getSession().getValidation().setRemote("classpath:threepids/email/validate-remote-template.eml");
setInvite("classpath:/threepids/email/invite-template.eml");
getGeneric().put("matrixId", "classpath:/threepids/email/mxid-template.eml");
getSession().getValidation().setLocal("classpath:/threepids/email/validate-local-template.eml");
getSession().getValidation().setRemote("classpath:/threepids/email/validate-remote-template.eml");
}
public EmailTemplateConfig build() {

View File

@@ -28,10 +28,10 @@ public class PhoneSmsTemplateConfig extends GenericTemplateConfig {
private transient final Logger log = LoggerFactory.getLogger(EmailTemplateConfig.class);
public PhoneSmsTemplateConfig() {
setInvite("classpath:threepids/sms/invite-template.txt");
getGeneric().put("matrixId", "classpath:threepids/email/mxid-template.eml");
getSession().getValidation().setLocal("classpath:threepids/sms/validate-local-template.txt");
getSession().getValidation().setRemote("classpath:threepids/sms/validate-remote-template.txt");
setInvite("classpath:/threepids/sms/invite-template.txt");
getGeneric().put("matrixId", "classpath:/threepids/email/mxid-template.eml");
getSession().getValidation().setLocal("classpath:/threepids/sms/validate-local-template.txt");
getSession().getValidation().setRemote("classpath:/threepids/sms/validate-remote-template.txt");
}
public PhoneSmsTemplateConfig build() {

View File

@@ -27,11 +27,16 @@ import io.kamax.mxisd.config.threepid.medium.GenericTemplateConfig;
import io.kamax.mxisd.exception.InternalServerError;
import io.kamax.mxisd.invitation.IThreePidInviteReply;
import io.kamax.mxisd.threepid.session.IThreePidSession;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.nio.charset.StandardCharsets;
public abstract class GenericTemplateNotificationGenerator extends PlaceholderNotificationGenerator implements NotificationGenerator {
@@ -46,13 +51,14 @@ public abstract class GenericTemplateNotificationGenerator extends PlaceholderNo
private String getTemplateContent(String location) {
try {
// FIXME make it work again
/*
InputStream is = StringUtils.startsWith(location, "classpath:") ?
app.getResource(location).getInputStream() : new FileInputStream(location);
URI loc = URI.create(location);
InputStream is;
if (StringUtils.equals("classpath", loc.getScheme())) {
is = getClass().getResourceAsStream(loc.getSchemeSpecificPart());
} else {
is = new FileInputStream(location);
}
return IOUtils.toString(is, StandardCharsets.UTF_8);
*/
throw new IOException("Not implemented!");
} catch (IOException e) {
throw new InternalServerError("Unable to read template content at " + location + ": " + e.getMessage());
}