Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dependency to commons.lang for Cloud Service #3422

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com)
### Changed

- #3420 - Redirect Map Manager - enable Redirect Map Manager in AEM CS (would require a specific - not public yet - AEM CS release version, TBA)
- #3421 - Remove dependency on Apache Commons Lang 2 for Cloud Service

## 6.6.4 - 2024-08-14

Expand Down
8 changes: 0 additions & 8 deletions bundle-cloud/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,6 @@ Fragment-Host: com.adobe.acs.acs-aem-commons-bundle
<scope>provided</scope>
</dependency>
<!-- Start Test dependencies -->
<dependency>
<groupId>com.adobe.acs</groupId>
<artifactId>acs-aem-commons-bundle</artifactId>
<version>${project.version}</version>
<classifier>tests</classifier>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -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 extends Email> T getEmail(final MailTemplate template,
final Map<String, String> params,
final Class<T> mailType)
throws IOException, EmailException, MessagingException {
return template.getEmail(params, mailType);
}
}
6 changes: 6 additions & 0 deletions bundle-onprem/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ Fragment-Host: com.adobe.acs.acs-aem-commons-bundle
<dependencies>
<!-- ======================== -->
<!-- START build dependencies -->
<dependency>
<groupId>com.adobe.acs</groupId>
<artifactId>acs-aem-commons-bundle</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.annotation.versioning</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -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 extends Email> T getEmail(final MailTemplate template,
final Map<String, String> params,
final Class<T> mailType)
throws IOException, EmailException, MessagingException {
return template.getEmail(StrLookup.mapLookup(params), mailType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -229,7 +231,7 @@ private Email getEmail(final MailTemplate mailTemplate,
final Class<? extends Email> mailType,
final Map<String, String> 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)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*-
* #%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 com.day.cq.commons.mail.MailTemplate;

/**
* Abstraction to allow different methods to be used between Cloud Service and on prem.
*/
public interface MailTemplateManager {

/**
* Get the email from the template
* @param <T> The email type
* @param template The email template
* @param params Optional parameters used inside the template
* @param mailType The email type
* @return The email object
* @throws IOException If an error occurs handling the text template.
* @throws MessagingException If an error occurs during building the email message.
* @throws EmailException If an error occurs during building the email.
*/
<T extends Email> T getEmail(MailTemplate template, final Map<String, String> params, Class<T> mailType)
throws IOException, EmailException, MessagingException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, Integer> tracker = new ConcurrentHashMap<>();

@Activate
Expand Down Expand Up @@ -145,7 +148,7 @@ public Result execute() {
List<InternetAddress> emailAddresses = new ArrayList<InternetAddress>();
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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 extends Email> T getEmail(MailTemplate template, Map<String, String> params, Class<T> mailType)
throws IOException, EmailException, MessagingException {
return template.getEmail(StrLookup.mapLookup(params), mailType) ;
}
});
context.registerInjectActivateService(emailService);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 extends Email> T getEmail(MailTemplate template, Map<String, String> params, Class<T> mailType)
throws IOException, EmailException, MessagingException {
return template.getEmail(StrLookup.mapLookup(params), mailType) ;
}
});
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
<!-- the minimum AEM 6.5 version being supported -->
<aem.classic.api.version>6.5.10.0002</aem.classic.api.version>
<!-- the minimum AEMaaCS version being supported -->
<aem.sdk.api.version>2023.11.14227.20231108T162349Z-231100</aem.sdk.api.version>
<aem.sdk.api.version>2024.8.17569.20240822T203847Z-240700</aem.sdk.api.version>

<jacoco.version>0.8.11</jacoco.version>
<junit.jupiter.version>5.10.2</junit.jupiter.version> <!-- >= 5.x requires Java 11 -->
Expand Down
Loading