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

A servlet to export redirects to a TXT file to use with pipeline-free redirects #3484

Merged
merged 9 commits into from
Dec 13, 2024

Conversation

YegorKozlov
Copy link
Contributor

@krystiannowak @kwin @joerghoh
the PR adds a servlet to export redirects into a text file, e.g. http://localhost:4502/conf/my-site/settings/redirects.txt

# Redirect Map File
/abc2 /content/applications
/xyz /legacy-1
/content/applications1 /legacy-2

This way Redirect Manager can serve redirects for Pipeline-free URL Redirects

src/opt-in/managed-rewrite-maps.yaml in the dispatcher configuration would look like

maps:
- name: my-site.map
  path: /conf/my-site/settings/redirects.txt 
- name: another-site.map
  path: /conf/another-site/settings/redirects.txt 

and vhosts can reference redirects like

# RewriteMap from managed rewrite maps
RewriteMap my-site.foo dbm=sdbm:/tmp/rewrites/my-site.map
RewriteCond ${my-site.foo:$1} !=""
RewriteRule ^(.*)$ ${my-site.foo:$1|/} [L,R=301]

/*
* ACS AEM Commons
*
* Copyright (C) 2013 - 2023 Adobe
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@YegorKozlov you might want to update the year range to include 2024 as current year, too ;)

/*
* ACS AEM Commons
*
* Copyright (C) 2013 - 2023 Adobe
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@YegorKozlov you might want to update the year range to include 2024 as current year, too ;)

Copy link
Contributor

@krystiannowak krystiannowak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@YegorKozlov just small note about copyrights year range, otherwise ok - good to see another source for Pipeline-free URL Redirects map data!

cc: @joerghoh @kwin

@krystiannowak
Copy link
Contributor

@YegorKozlov you might also add an option (e.g. selector or param) to separately generate list of entries for 301 redirection, and separately for 302 ones, so that on Apache HTTPD level they can be treated separately

Copy link
Contributor

@krystiannowak krystiannowak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@YegorKozlov super, thanks!

@YegorKozlov
Copy link
Contributor Author

@YegorKozlov you might also add an option (e.g. selector or param) to separately generate list of entries for 301 redirection, and separately for 302 ones, so that on Apache HTTPD level they can be treated separately

@krystiannowak I added a selector to filter by status code. With this change the yaml configuration would look like

maps:
- name: my-site-301.map
  path: /conf/my-site/settings/redirects.301.txt 
- name: my-site-302.map
  path: /conf/my-site/settings/redirects.302.txt 

@krystiannowak
Copy link
Contributor

@YegorKozlov looks like Windows-based test runs cry now

@@ -62,16 +62,16 @@ protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse r
}
Collection<RedirectRule> rules = RedirectFilter.getRules(request.getResource());
PrintWriter out = response.getWriter();
out.printf("# %s Redirects\n", statusCode == 0 ? "All" : "" + statusCode);
out.printf("# %s Redirects%n", statusCode == 0 ? "All" : "" + statusCode);
Copy link
Contributor

@krystiannowak krystiannowak Dec 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@YegorKozlov after starting to use %n as line separator, splitting still only by \n in tests by

String[] lines = response.getOutputAsString().split("\n");

in https://github.com/Adobe-Consulting-Services/acs-aem-commons/pull/3484/files#diff-36adc0c81c9585f4cadf9e45117faabfdda5ef6d7e197ade7d39e0a896c6853eR87
might not be precise enough anymore on Windows

Maybe by System.lineSeparator() as in:

diff --git a/bundle/src/test/java/com/adobe/acs/commons/redirects/servlets/RewriteMapServletTest.java b/bundle/src/test/java/com/adobe/acs/commons/redirects/servlets/RewriteMapServletTest.java
index acb58e9c5..80799fb3f 100755
--- a/bundle/src/test/java/com/adobe/acs/commons/redirects/servlets/RewriteMapServletTest.java
+++ b/bundle/src/test/java/com/adobe/acs/commons/redirects/servlets/RewriteMapServletTest.java
@@ -107,7 +107,7 @@ public class RewriteMapServletTest {
         servlet.doGet(request, response);
 
         assertEquals(ContentType.TEXT_PLAIN.getMimeType(), response.getContentType());
-        String[] lines = response.getOutputAsString().split("\n");
+        String[] lines = response.getOutputAsString().split(System.lineSeparator());
         assertEquals(2, lines.length); // header + 1 rule
         assertEquals("# 301 Redirects", lines[0]);
         String[] rule1 = lines[1].split(" ");
@@ -124,7 +124,7 @@ public class RewriteMapServletTest {
         servlet.doGet(request, response);
 
         assertEquals(ContentType.TEXT_PLAIN.getMimeType(), response.getContentType());
-        String[] lines = response.getOutputAsString().split("\n");
+        String[] lines = response.getOutputAsString().split(System.lineSeparator());
         assertEquals(3, lines.length); // header + notes + 1st rule
         assertEquals("# 302 Redirects", lines[0]);

would do?

* Copyright (C) 2013 - 2024 Adobe
*
* %%
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@YegorKozlov I'm not sure if that makes sense - or should rather https://github.com/Adobe-Consulting-Services/acs-aem-commons/blob/master/.codeclimate/header.txt be tuned instead? Also the other Java files do not seem to adhere to this pattern.

@kwin @joerghoh @davidjgonzalez WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@krystiannowak this %% thing does not make much sense to me, but I believe we've always had it, since the header check was introduced in #1345 back in 2018

Also the other Java files do not seem to adhere to this pattern.

Yep. We have quite a bit of the header variations across the project.

@kwin
Copy link
Contributor

kwin commented Dec 2, 2024

Look at #2500 for a discussion on license headers.

@krystiannowak
Copy link
Contributor

@YegorKozlov Probably you need to "touch" it to rerun tests, as I can see there are "status code: 504, reason phrase: Gateway Time-out" errors

@krystiannowak
Copy link
Contributor

@YegorKozlov looks like checks passed now, but my ack is not strong enough - maybe it needs an ack from other parties like @kwin @joerghoh @davidjgonzalez etc?

@davidjgonzalez davidjgonzalez added this to the 6.10.0 milestone Dec 5, 2024
@davidjgonzalez davidjgonzalez merged commit 8b89efc into Adobe-Consulting-Services:master Dec 13, 2024
9 of 10 checks passed
@krystiannowak
Copy link
Contributor

@YegorKozlov
Copy link
Contributor Author

@YegorKozlov Don't you want to update https://github.com/Adobe-Consulting-Services/adobe-consulting-services.github.io/blob/master/_acs-aem-commons/features/redirect-manager/index.md as well to reflect those changes?

cc: @davidjgonzalez

Sure thing. I was going to give it shot first, but didn't yet get around.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants