diff --git a/bundle-cloud/pom.xml b/bundle-cloud/pom.xml index bd89af91fb..f9d192f1d1 100644 --- a/bundle-cloud/pom.xml +++ b/bundle-cloud/pom.xml @@ -77,14 +77,6 @@ Fragment-Host: com.adobe.acs.acs-aem-commons-bundle provided - - com.adobe.acs - acs-aem-commons-bundle - ${project.version} - tests - test-jar - test - junit junit diff --git a/bundle-cloud/src/main/java/com/adobe/acs/commons/email/impl/MailTemplateManagerImpl.java b/bundle-cloud/src/main/java/com/adobe/acs/commons/email/impl/MailTemplateManagerImpl.java new file mode 100644 index 0000000000..cac0c46790 --- /dev/null +++ b/bundle-cloud/src/main/java/com/adobe/acs/commons/email/impl/MailTemplateManagerImpl.java @@ -0,0 +1,43 @@ +/* + * #%L + * ACS AEM Commons Bundle + * %% + * Copyright (C) 2024 Adobe + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ +package com.adobe.acs.commons.email.impl; + +import java.io.IOException; +import java.util.Map; + +import javax.mail.MessagingException; + +import org.apache.commons.mail.Email; +import org.apache.commons.mail.EmailException; +import org.osgi.service.component.annotations.Component; + +import com.day.cq.commons.mail.MailTemplate; + +@Component(service = MailTemplateManager.class) +public class MailTemplateManagerImpl implements MailTemplateManager { + + @Override + public T getEmail(final MailTemplate template, + final Map params, + final Class mailType) + throws IOException, EmailException, MessagingException { + return template.getEmail(params, mailType); + } +} diff --git a/bundle-onprem/pom.xml b/bundle-onprem/pom.xml index c542483d9f..8211b18c11 100644 --- a/bundle-onprem/pom.xml +++ b/bundle-onprem/pom.xml @@ -71,6 +71,12 @@ Fragment-Host: com.adobe.acs.acs-aem-commons-bundle + + com.adobe.acs + acs-aem-commons-bundle + ${project.version} + provided + org.osgi org.osgi.annotation.versioning diff --git a/bundle-onprem/src/main/java/com/adobe/acs/commons/email/impl/MailTemplateManagerImpl.java b/bundle-onprem/src/main/java/com/adobe/acs/commons/email/impl/MailTemplateManagerImpl.java new file mode 100644 index 0000000000..2edf0c2730 --- /dev/null +++ b/bundle-onprem/src/main/java/com/adobe/acs/commons/email/impl/MailTemplateManagerImpl.java @@ -0,0 +1,44 @@ +/* + * #%L + * ACS AEM Commons Bundle + * %% + * Copyright (C) 2024 Adobe + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ +package com.adobe.acs.commons.email.impl; + +import java.io.IOException; +import java.util.Map; + +import javax.mail.MessagingException; + +import org.apache.commons.lang.text.StrLookup; +import org.apache.commons.mail.Email; +import org.apache.commons.mail.EmailException; +import org.osgi.service.component.annotations.Component; + +import com.day.cq.commons.mail.MailTemplate; + +@Component(service = MailTemplateManager.class) +public class MailTemplateManagerImpl implements MailTemplateManager { + + @Override + public T getEmail(final MailTemplate template, + final Map params, + final Class mailType) + throws IOException, EmailException, MessagingException { + return template.getEmail(StrLookup.mapLookup(params), mailType); + } +} diff --git a/bundle/src/main/java/com/adobe/acs/commons/email/impl/EmailServiceImpl.java b/bundle/src/main/java/com/adobe/acs/commons/email/impl/EmailServiceImpl.java index 82f30c403a..f52ac3c32f 100644 --- a/bundle/src/main/java/com/adobe/acs/commons/email/impl/EmailServiceImpl.java +++ b/bundle/src/main/java/com/adobe/acs/commons/email/impl/EmailServiceImpl.java @@ -22,7 +22,6 @@ import com.day.cq.commons.mail.MailTemplate; import com.day.cq.mailer.MessageGateway; import com.day.cq.mailer.MessageGatewayService; -import org.apache.commons.lang.text.StrLookup; import org.apache.commons.mail.Email; import org.apache.commons.mail.EmailException; import org.apache.commons.mail.HtmlEmail; @@ -79,6 +78,9 @@ public final class EmailServiceImpl implements EmailService { @Reference private ResourceResolverFactory resourceResolverFactory; + @Reference + private MailTemplateManager mailTemplateManager; + public static final int DEFAULT_CONNECT_TIMEOUT = 30000; public static final int DEFAULT_SOCKET_TIMEOUT = 30000; @@ -229,7 +231,7 @@ private Email getEmail(final MailTemplate mailTemplate, final Class mailType, final Map params) throws EmailException, MessagingException, IOException { - final Email email = mailTemplate.getEmail(StrLookup.mapLookup(params), mailType); + final Email email = mailTemplateManager.getEmail(mailTemplate, params, mailType); if (params.containsKey(EmailServiceConstants.SENDER_EMAIL_ADDRESS) && params.containsKey(EmailServiceConstants.SENDER_NAME)) { diff --git a/bundle/src/main/java/com/adobe/acs/commons/email/impl/MailTemplateManager.java b/bundle/src/main/java/com/adobe/acs/commons/email/impl/MailTemplateManager.java new file mode 100644 index 0000000000..b9c855bad0 --- /dev/null +++ b/bundle/src/main/java/com/adobe/acs/commons/email/impl/MailTemplateManager.java @@ -0,0 +1,34 @@ +/* + * ACS AEM Commons + * + * Copyright (C) 2024 Adobe + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.adobe.acs.commons.email.impl; + +import java.io.IOException; +import java.util.Map; + +import javax.mail.MessagingException; + +import org.apache.commons.mail.Email; +import org.apache.commons.mail.EmailException; + +import com.day.cq.commons.mail.MailTemplate; + +public interface MailTemplateManager { + + T getEmail(MailTemplate template, final Map params, Class mailType) + throws IOException, EmailException, MessagingException; +} diff --git a/bundle/src/main/java/com/adobe/acs/commons/hc/impl/SMTPMailServiceHealthCheck.java b/bundle/src/main/java/com/adobe/acs/commons/hc/impl/SMTPMailServiceHealthCheck.java index 5c055736ea..9525fc7cad 100644 --- a/bundle/src/main/java/com/adobe/acs/commons/hc/impl/SMTPMailServiceHealthCheck.java +++ b/bundle/src/main/java/com/adobe/acs/commons/hc/impl/SMTPMailServiceHealthCheck.java @@ -17,13 +17,13 @@ */ package com.adobe.acs.commons.hc.impl; +import com.adobe.acs.commons.email.impl.MailTemplateManager; import com.adobe.acs.commons.util.RequireAem; import com.day.cq.commons.mail.MailTemplate; import com.day.cq.mailer.MessageGateway; import com.day.cq.mailer.MessageGatewayService; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.CharEncoding; -import org.apache.commons.lang.text.StrLookup; import org.apache.commons.lang3.StringUtils; import org.apache.commons.mail.SimpleEmail; import org.apache.felix.scr.annotations.Activate; @@ -112,6 +112,9 @@ public class SMTPMailServiceHealthCheck implements HealthCheck { @Reference(cardinality = ReferenceCardinality.OPTIONAL_UNARY, policyOption = ReferencePolicyOption.GREEDY) private MessageGatewayService messageGatewayService; + @Reference + private MailTemplateManager mailTemplateManager; + private transient ConcurrentHashMap tracker = new ConcurrentHashMap<>(); @Activate @@ -145,7 +148,7 @@ public Result execute() { List emailAddresses = new ArrayList(); emailAddresses.add(new InternetAddress(this.toEmail)); MailTemplate mailTemplate = new MailTemplate(IOUtils.toInputStream(MAIL_TEMPLATE, "UTF-8"), CharEncoding.UTF_8); - SimpleEmail email = mailTemplate.getEmail(StrLookup.mapLookup(Collections.emptyMap()), SimpleEmail.class); + SimpleEmail email = mailTemplateManager.getEmail(mailTemplate, null, SimpleEmail.class); email.setSubject("AEM E-mail Service Health Check"); email.setTo(emailAddresses); diff --git a/bundle/src/test/java/com/adobe/acs/commons/email/impl/EmailServiceImplTest.java b/bundle/src/test/java/com/adobe/acs/commons/email/impl/EmailServiceImplTest.java index f8c419b321..5af3d7845e 100644 --- a/bundle/src/test/java/com/adobe/acs/commons/email/impl/EmailServiceImplTest.java +++ b/bundle/src/test/java/com/adobe/acs/commons/email/impl/EmailServiceImplTest.java @@ -17,11 +17,16 @@ */ package com.adobe.acs.commons.email.impl; +import com.day.cq.commons.mail.MailTemplate; import com.day.cq.mailer.MessageGateway; import com.day.cq.mailer.MessageGatewayService; import junitx.util.PrivateAccessor; + +import org.apache.commons.lang.text.StrLookup; import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.mail.ByteArrayDataSource; +import org.apache.commons.mail.Email; +import org.apache.commons.mail.EmailException; import org.apache.commons.mail.HtmlEmail; import org.apache.commons.mail.SimpleEmail; import org.apache.sling.testing.mock.sling.ResourceResolverType; @@ -37,7 +42,10 @@ import org.mockito.junit.MockitoJUnitRunner; import javax.activation.DataSource; +import javax.mail.MessagingException; import javax.mail.internet.MimeMultipart; + +import java.io.IOException; import java.lang.reflect.Method; import java.util.Collections; import java.util.HashMap; @@ -85,6 +93,13 @@ public final void setUp() throws Exception { when(messageGatewayService.getGateway(HtmlEmail.class)).thenReturn(messageGatewayHtmlEmail); context.registerService(MessageGatewayService.class, messageGatewayService); + context.registerService(MailTemplateManager.class, new MailTemplateManager() { + @Override + public T getEmail(MailTemplate template, Map params, Class mailType) + throws IOException, EmailException, MessagingException { + return template.getEmail(StrLookup.mapLookup(params), mailType) ; + } + }); context.registerInjectActivateService(emailService); } diff --git a/bundle/src/test/java/com/adobe/acs/commons/hc/impl/SMTPMailServiceHealthCheckTest.java b/bundle/src/test/java/com/adobe/acs/commons/hc/impl/SMTPMailServiceHealthCheckTest.java index 18ee1cefbb..7a0b5226d2 100644 --- a/bundle/src/test/java/com/adobe/acs/commons/hc/impl/SMTPMailServiceHealthCheckTest.java +++ b/bundle/src/test/java/com/adobe/acs/commons/hc/impl/SMTPMailServiceHealthCheckTest.java @@ -20,12 +20,23 @@ import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.doReturn; +import java.io.IOException; +import java.util.Map; + +import javax.mail.MessagingException; + +import com.adobe.acs.commons.email.impl.MailTemplateManager; import com.adobe.acs.commons.util.RequireAem; import com.adobe.acs.commons.util.impl.RequireAemImpl; +import com.day.cq.commons.mail.MailTemplate; import com.day.cq.mailer.MessageGateway; import com.day.cq.mailer.MessageGatewayService; +import org.apache.commons.lang.text.StrLookup; +import org.apache.commons.mail.Email; +import org.apache.commons.mail.EmailException; import org.apache.commons.mail.SimpleEmail; +import org.apache.poi.ss.formula.functions.T; import org.apache.sling.hc.api.HealthCheck; import org.apache.sling.hc.api.Result; import org.junit.Before; @@ -52,6 +63,13 @@ public class SMTPMailServiceHealthCheckTest { public void setUp() { ctx.registerService(RequireAem.class, new RequireAemImpl(), "distribution", "classic"); ctx.registerService(MessageGatewayService.class, messageGatewayService); + ctx.registerService(MailTemplateManager.class, new MailTemplateManager() { + @Override + public T getEmail(MailTemplate template, Map params, Class mailType) + throws IOException, EmailException, MessagingException { + return template.getEmail(StrLookup.mapLookup(params), mailType) ; + } + }); } @Test diff --git a/pom.xml b/pom.xml index 32fc0639ed..2164621d12 100644 --- a/pom.xml +++ b/pom.xml @@ -86,7 +86,7 @@ 6.5.10.0002 - 2023.11.14227.20231108T162349Z-231100 + 2024.8.17569.20240822T203847Z-240700 0.8.11 5.10.2