mraible commented on code in PR #320:
URL: https://github.com/apache/roller/pull/320#discussion_r4609101613
##########
app/src/main/java/org/apache/roller/weblogger/config/WebloggerRuntimeConfig.java:
##########
@@ -192,8 +253,44 @@ public static String getAbsoluteContextURL() {
if(absURL != null && !absURL.isBlank()) {
return absURL;
}
-
- return absoluteContextURL;
+
+ if (absoluteURLWarningLogged.compareAndSet(false, true)) {
+ log.warn("The site's absolute URL (site.absoluteurl) is not set,
so "
+ + "links in emails and feeds will use the host name of
each "
+ + "request. Set \"Absolute URL to site\" under Server "
+ + "Administration > Configuration.");
+ }
+
+ return requestAbsoluteContextURL.get();
+ }
+
+
+ /**
+ * Save the given url as site.absoluteurl if that property is empty.
+ * Called when the site is being set up, by the installer and by the
+ * registration of the first administrator.
+ *
+ * @return true if the url was saved; the caller must flush
+ */
+ public static boolean saveAbsoluteContextURLIfUnset(String url)
+ throws WebloggerException {
+
+ if (url == null || url.isBlank()) {
+ return false;
+ }
+ PropertiesManager pmgr =
WebloggerFactory.getWeblogger().getPropertiesManager();
+ RuntimeConfigProperty prop = pmgr.getProperty("site.absoluteurl");
Review Comment:
saveAbsoluteContextURLIfUnset() now writes the empty property with
PropertiesManager.compareAndSetProperty(), so when several requests try at once
only the first URL is kept; a missing row (only possible if startup didn't fill
the properties table) is still inserted, and a second insert would fail on
flush. PropertiesTest.onlyOneConcurrentRequestSavesTheSiteUrl runs two threads
that both read the empty value first and checks that exactly one saves, and
SiteUrlForAdminTest covers the case where another request wins in between. The
same change is on #337.
##########
app/src/main/java/org/apache/roller/weblogger/config/WebloggerRuntimeConfig.java:
##########
@@ -169,21 +178,73 @@ public static String getRuntimeConfigDefsAsString() {
/**
- * Special method which sets the non-persisted absolute url to this site.
+ * Set the absolute url of the request being handled on this thread. The
+ * InitFilter sets this at the start of each request and clears it with
+ * clearRequestAbsoluteContextURL() when the request is done.
*
- * This property is *not* persisted in any way.
+ * This value is *not* persisted or shared with other threads.
*/
- public static void setAbsoluteContextURL(String url) {
- absoluteContextURL = url;
+ public static void setRequestAbsoluteContextURL(String url) {
+ requestAbsoluteContextURL.set(url);
}
-
-
+
+
+ /**
+ * Forget the absolute url of the request handled on this thread.
+ */
+ public static void clearRequestAbsoluteContextURL() {
+ requestAbsoluteContextURL.remove();
+ }
+
+
+ /**
+ * True if getAbsoluteContextURL() has returned the current request's url
+ * on this thread. Output built from that url depends on the request's Host
+ * header, so the rendering caches don't store it.
+ */
+ /**
+ * The cache key to use for content rendered for the current request. While
+ * site.absoluteurl is unset, links are built from the request's own URL,
so
+ * the key includes it: content cached for one host name is only served to
+ * requests for that host name.
+ */
+ public static String cacheKey(String key) {
+ String absURL = getProperty("site.absoluteurl");
+ if (absURL != null && !absURL.isBlank()) {
+ return key;
+ }
+ String requestURL = requestAbsoluteContextURL.get();
+ return requestURL == null ? key : key + "|" + requestURL;
Review Comment:
Content rendered outside a request is no longer cached while the site URL is
unset (cacheKey() returns null and the caches skip it), the warmup job skips
its work until the URL is set, and the page, feed, site-wide and planet caches
are cleared when the URL is first saved. SiteUrlWhileUnsetTest covers a feed
put from outside a request while unset not being served once the URL is set,
and per-host entries being cleared by the save. The same change is on #337.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]