Skip to content

Commit 4b780a4

Browse files
committed
Use application name property in startup template
1 parent aff9394 commit 4b780a4

3 files changed

Lines changed: 31 additions & 7 deletions

File tree

src/main/java/eu/openanalytics/containerproxy/util/AppRecoveryFilter.java

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
*/
2121
package eu.openanalytics.containerproxy.util;
2222

23-
import com.google.common.io.ByteStreams;
2423
import eu.openanalytics.containerproxy.service.AppRecoveryService;
2524
import org.apache.commons.io.IOUtils;
25+
import org.springframework.core.env.Environment;
2626
import org.springframework.stereotype.Component;
2727
import org.springframework.web.filter.GenericFilterBean;
2828

@@ -35,6 +35,7 @@
3535
import javax.servlet.http.HttpServletResponse;
3636
import java.io.IOException;
3737
import java.io.InputStream;
38+
import java.nio.charset.StandardCharsets;
3839

3940
/**
4041
* While the recovery is happening, the application may not be used.
@@ -46,6 +47,11 @@ public class AppRecoveryFilter extends GenericFilterBean {
4647
@Inject
4748
public AppRecoveryService appRecoveryService;
4849

50+
@Inject
51+
public Environment environment;
52+
53+
private String renderedTemplate;
54+
4955
@Override
5056
public void doFilter(
5157
ServletRequest request,
@@ -69,11 +75,29 @@ public void doFilter(
6975
}
7076

7177
// ... generate a 503
72-
HttpServletResponse httpResponse = (HttpServletResponse) response;
78+
renderTemplate((HttpServletResponse) response);
79+
}
80+
81+
private void renderTemplate(HttpServletResponse httpResponse ) throws IOException {
82+
if (renderedTemplate == null) {
83+
InputStream template = this.getClass().getResourceAsStream("/templates/startup.html");
84+
if (template == null) {
85+
throw new IllegalStateException("Startup template should be available");
86+
}
87+
88+
String applicationName = environment.getProperty("spring.application.name");
89+
if (applicationName == null) {
90+
throw new IllegalStateException("Application name should be available"); // we provide a default so this should not happen
91+
}
92+
93+
renderedTemplate = IOUtils.toString(template, StandardCharsets.UTF_8.name());
94+
renderedTemplate = renderedTemplate.replace("${application_name}", applicationName);
95+
}
96+
7397
httpResponse.setStatus(503);
7498
httpResponse.setContentType("text/html");
75-
InputStream template = this.getClass().getResourceAsStream("/templates/startup.html");
76-
IOUtils.copy(template, httpResponse.getOutputStream());
99+
100+
IOUtils.write(renderedTemplate, httpResponse.getOutputStream(), StandardCharsets.UTF_8.name());
77101
}
78102

79103
}

src/main/resources/templates/auth-error.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
<div class="container">
3939
<h2>An error occurred during the authentication procedure.</h2>
4040
<p><b>If you are a user of <span th:text="${application_name}"></span>:</b> please report this issue to your administrator and try to log out from your Identity Provider.</p>
41-
<p><b>If you are an administrator of <span th:text="${application_name}"></span>:</b> this error page is typically shown because of an configuration error in the authentication setup. See the ShinyProxy logs for more information.</p>
41+
<p><b>If you are an administrator of <span th:text="${application_name}"></span>:</b> this error page is typically shown because of an configuration error in the authentication setup. See the logs for more information.</p>
4242
</div>
4343

4444
<style>

src/main/resources/templates/startup.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
<!DOCTYPE html>
2424
<html>
2525
<head lang="en">
26-
<title>ShinyProxy</title>
26+
<title>${application_name}</title>
2727
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
2828
</head>
2929
<body>
3030
<div class="container">
31-
<h2>ShinyProxy is starting up, check back in a few seconds.</h2>
31+
<h2>${application_name} is starting up, check back in a few seconds.</h2>
3232
</div>
3333

3434
<style>

0 commit comments

Comments
 (0)