Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseifert committed Sep 2, 2022
2 parents 92ce54d + 25e52ff commit 46c6492
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<img src="https://wcm.io/images/favicon-16@2x.png"/> Media Handler
======
[![Build](https://github.com/wcm-io/io.wcm.handler.media/workflows/Build/badge.svg?branch=develop)](https://github.com/wcm-io/io.wcm.handler.media/actions?query=workflow%3ABuild+branch%3Adevelop)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.wcm/io.wcm.handler.media/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.wcm/io.wcm.handler.media)
[![Maven Central](https://img.shields.io/maven-central/v/io.wcm/io.wcm.handler.media)](https://repo1.maven.org/maven2/io/wcm/io.wcm.handler.media/)
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=wcm-io_io.wcm.handler.media&metric=coverage)](https://sonarcloud.io/summary/new_code?id=wcm-io_io.wcm.handler.media)

Media resolving, processing and markup generation.
Expand Down
6 changes: 6 additions & 0 deletions changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
xsi:schemaLocation="http://maven.apache.org/changes/1.0.0 http://maven.apache.org/plugins/maven-changes-plugin/xsd/changes-1.0.0.xsd">
<body>

<release version="1.14.6" date="2022-09-02">
<action type="fix" dev="sseifert"><![CDATA[
Dynamic Media Support: Apply Site URL detection with <code>&lt;auto&gt;</code> when building Dynamic Media URLs in author instance.
]]></action>
</release>

<release version="1.14.4" date="2022-06-16">
<action type="update" dev="sseifert">
Switch to AEM 6.5.7 as minimum version.
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

<groupId>io.wcm</groupId>
<artifactId>io.wcm.handler.media</artifactId>
<version>1.14.4</version>
<version>1.14.6</version>
<packaging>jar</packaging>

<name>Media Handler</name>
Expand All @@ -49,7 +49,7 @@
<site.url.module.prefix>handler/media</site.url.module.prefix>

<!-- Enable reproducible builds -->
<project.build.outputTimestamp>2022-06-16T17:46:34Z</project.build.outputTimestamp>
<project.build.outputTimestamp>2022-09-02T08:01:37Z</project.build.outputTimestamp>
</properties>

<dependencies>
Expand All @@ -69,7 +69,7 @@
<dependency>
<groupId>io.wcm</groupId>
<artifactId>io.wcm.handler.url</artifactId>
<version>1.5.0</version>
<version>1.9.0</version>
<scope>compile</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public boolean isDynamicMediaAsset() {
*/
public @Nullable String getDynamicMediaServerUrl() {
if (dynamicMediaServerUrl == null) {
dynamicMediaServerUrl = dynamicMediaSupportService.getDynamicMediaServerUrl(asset, urlMode);
dynamicMediaServerUrl = dynamicMediaSupportService.getDynamicMediaServerUrl(asset, urlMode, adaptable);
}
return dynamicMediaServerUrl;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
package io.wcm.handler.mediasource.dam.impl.dynamicmedia;

import org.apache.sling.api.adapter.Adaptable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -69,10 +70,12 @@ public interface DynamicMediaSupportService {
/**
* Get scene7 host/URL prefix for publish environment.
* @param asset DAM asset
* @param urlMode URL mode
* @param adaptable Adaptable
* @return Protocol and hostname of scene7 host or null.
* If author preview mode is enabled, returns empty string.
*/
@Nullable
String getDynamicMediaServerUrl(@NotNull Asset asset, @Nullable UrlMode urlMode);
String getDynamicMediaServerUrl(@NotNull Asset asset, @Nullable UrlMode urlMode, @NotNull Adaptable adaptable);

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import javax.jcr.RepositoryException;

import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.adapter.Adaptable;
import org.apache.sling.api.resource.LoginException;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
Expand All @@ -49,6 +50,7 @@

import io.wcm.handler.media.Dimension;
import io.wcm.handler.url.SiteConfig;
import io.wcm.handler.url.UrlHandler;
import io.wcm.handler.url.UrlMode;
import io.wcm.handler.url.UrlModes;
import io.wcm.sling.commons.adapter.AdaptTo;
Expand Down Expand Up @@ -188,13 +190,15 @@ public boolean isAemFallbackDisabled() {
}

@Override
public @Nullable String getDynamicMediaServerUrl(@NotNull Asset asset, @Nullable UrlMode urlMode) {
public @Nullable String getDynamicMediaServerUrl(@NotNull Asset asset, @Nullable UrlMode urlMode, @NotNull Adaptable adaptable) {
Resource assetResource = AdaptTo.notNull(asset, Resource.class);
if (authorPreviewMode && !forcePublishMode(urlMode)) {
// route dynamic media requests through author instance for preview
// return configured author URL, or empty string if none configured
SiteConfig siteConfig = AdaptTo.notNull(assetResource, SiteConfig.class);
return StringUtils.defaultString(siteConfig.siteUrlAuthor());
SiteConfig siteConfig = AdaptTo.notNull(adaptable, SiteConfig.class);
String siteUrlAUthor = StringUtils.defaultString(siteConfig.siteUrlAuthor());
UrlHandler urlHandler = AdaptTo.notNull(adaptable, UrlHandler.class);
return urlHandler.applySiteUrlAutoDetection(siteUrlAUthor);
}
try {
String[] productionAssetUrls = dynamicMediaPublishUtils.externalizeImageDeliveryAsset(assetResource);
Expand Down
14 changes: 7 additions & 7 deletions src/site/markdown/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Media resolving, processing and markup generation.

[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.wcm/io.wcm.handler.media/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.wcm/io.wcm.handler.media)
[![Maven Central](https://img.shields.io/maven-central/v/io.wcm/io.wcm.handler.media)](https://repo1.maven.org/maven2/io/wcm/io.wcm.handler.media/)


### Documentation
Expand Down Expand Up @@ -57,12 +57,12 @@ Read the [general concepts][general-concepts] to get an overview of the function
To use this module you have to deploy also:

|---|---|---|
| [wcm.io Sling Commons](https://maven-badges.herokuapp.com/maven-central/io.wcm/io.wcm.sling.commons) | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.wcm/io.wcm.sling.commons/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.wcm/io.wcm.sling.commons) |
| [wcm.io AEM Sling Models Extensions](https://maven-badges.herokuapp.com/maven-central/io.wcm/io.wcm.sling.models) | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.wcm/io.wcm.sling.models/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.wcm/io.wcm.sling.models) |
| [wcm.io WCM Commons](https://maven-badges.herokuapp.com/maven-central/io.wcm/io.wcm.wcm.commons) | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.wcm/io.wcm.wcm.commons/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.wcm/io.wcm.wcm.commons) |
| [wcm.io WCM Granite UI Extensions](https://maven-badges.herokuapp.com/maven-central/io.wcm/io.wcm.wcm.ui.granite) | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.wcm/io.wcm.wcm.ui.granite/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.wcm/io.wcm.wcm.ui.granite) |
| [wcm.io Handler Commons](https://maven-badges.herokuapp.com/maven-central/io.wcm/io.wcm.handler.commons) | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.wcm/io.wcm.handler.commons/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.wcm/io.wcm.handler.commons) |
| [wcm.io URL Handler](https://maven-badges.herokuapp.com/maven-central/io.wcm/io.wcm.handler.url) | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.wcm/io.wcm.handler.url/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.wcm/io.wcm.handler.url) |
| [wcm.io Sling Commons](https://repo1.maven.org/maven2/io/wcm/io.wcm.sling.commons/) | [![Maven Central](https://img.shields.io/maven-central/v/io.wcm/io.wcm.sling.commons)](https://repo1.maven.org/maven2/io/wcm/io.wcm.sling.commons/) |
| [wcm.io AEM Sling Models Extensions](https://repo1.maven.org/maven2/io/wcm/io.wcm.sling.models/) | [![Maven Central](https://img.shields.io/maven-central/v/io.wcm/io.wcm.sling.models)](https://repo1.maven.org/maven2/io/wcm/io.wcm.sling.models/) |
| [wcm.io WCM Commons](https://repo1.maven.org/maven2/io/wcm/io.wcm.wcm.commons/) | [![Maven Central](https://img.shields.io/maven-central/v/io.wcm/io.wcm.wcm.commons)](https://repo1.maven.org/maven2/io/wcm/io.wcm.wcm.commons/) |
| [wcm.io WCM Granite UI Extensions](https://repo1.maven.org/maven2/io/wcm/io.wcm.wcm.ui.granite/) | [![Maven Central](https://img.shields.io/maven-central/v/io.wcm/io.wcm.wcm.ui.granite)](https://repo1.maven.org/maven2/io/wcm/io.wcm.wcm.ui.granite/) |
| [wcm.io Handler Commons](https://repo1.maven.org/maven2/io/wcm/io.wcm.handler.commons/) | [![Maven Central](https://img.shields.io/maven-central/v/io.wcm/io.wcm.handler.commons)](https://repo1.maven.org/maven2/io/wcm/io.wcm.handler.commons/) |
| [wcm.io URL Handler](https://repo1.maven.org/maven2/io/wcm/io.wcm.handler.url/) | [![Maven Central](https://img.shields.io/maven-central/v/io.wcm/io.wcm.handler.url)](https://repo1.maven.org/maven2/io/wcm/io.wcm.handler.url/) |


### GitHub Repository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void testDefaultConfig() {
DynamicMediaSupportService underTest = context.registerInjectActivateService(new DynamicMediaSupportServiceImpl());
assertTrue(underTest.isDynamicMediaEnabled());
assertEquals(new Dimension(2000, 2000), underTest.getImageSizeLimit());
assertEquals("https://dummy.scene7.com", underTest.getDynamicMediaServerUrl(asset, null));
assertEquals("https://dummy.scene7.com", underTest.getDynamicMediaServerUrl(asset, null, context.request()));
}

@Test
Expand All @@ -97,22 +97,68 @@ void testAuthorPreviewMode() {
"imageSizeLimitHeight", 3000);
assertTrue(underTest.isDynamicMediaEnabled());
assertEquals(new Dimension(4000, 3000), underTest.getImageSizeLimit());
assertEquals("", underTest.getDynamicMediaServerUrl(asset, null));
assertEquals("https://author.dummysite.org", underTest.getDynamicMediaServerUrl(asset, null, context.request()));
}

@Test
void testAuthorPreviewMode_SiteConfig() {
activateDynamicMediaFeature();

MockCAConfig.contextPathStrategyAbsoluteParent(context, 1);
MockContextAwareConfig.writeConfiguration(context, "/content/dam", SiteConfig.class,
"siteUrlAuthor", "https://author");
MockContextAwareConfig.writeConfiguration(context, AppAemContext.ROOTPATH_CONTENT, SiteConfig.class,
"siteUrlAuthor", "https://author-dm");

DynamicMediaSupportService underTest = context.registerInjectActivateService(new DynamicMediaSupportServiceImpl(),
"authorPreviewMode", true);
assertTrue(underTest.isDynamicMediaEnabled());
assertEquals(new Dimension(2000, 2000), underTest.getImageSizeLimit());
assertEquals("https://author-dm", underTest.getDynamicMediaServerUrl(asset, null, context.request()));
}

/**
* Ensure Site URL auto-detection with &lt;auto&gt; placeholder works.
*/
@Test
void testAuthorPreviewMode_SiteConfig_AutoDetection() {
context.request().setServerName("servername-dm");
context.request().setServerPort(8443);
context.request().setScheme("https");

activateDynamicMediaFeature();

MockCAConfig.contextPathStrategyAbsoluteParent(context, 1);
MockContextAwareConfig.writeConfiguration(context, AppAemContext.ROOTPATH_CONTENT, SiteConfig.class,
"siteUrlAuthor", "<auto>https://author-dm");

DynamicMediaSupportService underTest = context.registerInjectActivateService(new DynamicMediaSupportServiceImpl(),
"authorPreviewMode", true);
assertTrue(underTest.isDynamicMediaEnabled());
assertEquals(new Dimension(2000, 2000), underTest.getImageSizeLimit());
assertEquals("https://servername-dm:8443", underTest.getDynamicMediaServerUrl(asset, null, context.request()));
}

/**
* Ensure Site URL auto-detection with &lt;auto&gt; placeholder works with using the fallback URL
* when media handler is used outside request context (adapted from resource).
*/
@Test
@SuppressWarnings("null")
void testAuthorPreviewMode_SiteConfig_AutoDetection_Fallback() {
context.request().setServerName("servername-dm");
context.request().setServerPort(8443);
context.request().setScheme("https");

activateDynamicMediaFeature();

MockCAConfig.contextPathStrategyAbsoluteParent(context, 1);
MockContextAwareConfig.writeConfiguration(context, AppAemContext.ROOTPATH_CONTENT, SiteConfig.class,
"siteUrlAuthor", "<auto>https://author-dm-fallback");

DynamicMediaSupportService underTest = context.registerInjectActivateService(new DynamicMediaSupportServiceImpl(),
"authorPreviewMode", true);
assertTrue(underTest.isDynamicMediaEnabled());
assertEquals(new Dimension(2000, 2000), underTest.getImageSizeLimit());
assertEquals("https://author", underTest.getDynamicMediaServerUrl(asset, null));
assertEquals("https://author-dm-fallback", underTest.getDynamicMediaServerUrl(asset, null, context.currentResource()));
}

/**
Expand Down Expand Up @@ -180,7 +226,7 @@ void testAuthorPreviewMode_SiteConfig_FourcePublish(UrlMode urlMode) {
"authorPreviewMode", true);
assertTrue(underTest.isDynamicMediaEnabled());
assertEquals(new Dimension(2000, 2000), underTest.getImageSizeLimit());
assertEquals("https://dummy.scene7.com", underTest.getDynamicMediaServerUrl(asset, urlMode));
assertEquals("https://dummy.scene7.com", underTest.getDynamicMediaServerUrl(asset, urlMode, context.request()));
}

private static Stream<Arguments> forcePublicshUrlModes() {
Expand Down

0 comments on commit 46c6492

Please sign in to comment.