Skip to content

Commit

Permalink
CLDR-16838 Follow-up, new optional CLDR_REDIRECT_PORT in cldr.propert…
Browse files Browse the repository at this point in the history
…ies (#3389)

-Enable running with nginx on port other than default 80, flexibility for testing on local machine

-No change in behavior if CLDR_REDIRECT_PORT not specified

-Property is retrieved only once, then cached for performance
  • Loading branch information
btangmu authored Nov 23, 2023
1 parent 94e0382 commit 209888e
Showing 1 changed file with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.unicode.cldr.test.DisplayAndInputProcessor;
import org.unicode.cldr.util.CLDRConfig;
import org.unicode.cldr.util.CLDRLocale;
import org.unicode.cldr.util.Level;
import org.unicode.cldr.util.PathHeader;
Expand Down Expand Up @@ -719,14 +720,39 @@ void print(Throwable t) {
*/
void redirect(String where) {
try {
response.sendRedirect(where);
String port = getRedirectPort();
if (port != null) {
String url =
request.getScheme() + "://" + request.getServerName() + ":" + port + where;
response.sendRedirect(url);
} else {
response.sendRedirect(where);
}
out.close();
close();
} catch (IOException ioe) {
throw new RuntimeException(ioe + " while redirecting to " + where);
}
}

private static final String PORT_NUMBER_NOT_INITIALIZED = "?";

/**
* On first access, this becomes either null (for default port number 80) or a port number such
* as "8888". Ordinarily Survey Tool uses nginx as a load-balancing server, running on the
* default port (80). For development it may be useful to have it on a different port. This can
* be enabled by a line such as this in cldr.properties: CLDR_REDIRECT_PORT=8888
*/
private static String webContextRedirectPort = PORT_NUMBER_NOT_INITIALIZED;

private String getRedirectPort() {
if (PORT_NUMBER_NOT_INITIALIZED.equals(webContextRedirectPort)) {
webContextRedirectPort =
CLDRConfig.getInstance().getProperty("CLDR_REDIRECT_PORT", null);
}
return webContextRedirectPort; // default null
}

/** Close the stream. Normally not called directly, except in outermost processor. */
void close() throws IOException {
if (!dontCloseMe) {
Expand Down

0 comments on commit 209888e

Please sign in to comment.