remove debug URL parameter, adopt cache for switching parameter value

#5153
This commit is contained in:
Georg Herdt committed 2020-03-09 14:44:04 +01:00
1 parent 39fe761eb8
commit 52bf66fabb
3 files changed
+22 -24

No files matched your search

@@ -15,25 +15,21 @@ public class ClientConfigurationServlet extends HttpServlet {
/** serial version uid */
private static final long serialVersionUID = -2228462977010198686L;
public static final String DEBRANDING_PROPERTY_NAME = "com.sap.sailing.debranding";
private final ConcurrentHashMap<String, byte[]> cache = new ConcurrentHashMap<>();
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
boolean debugDebranding = false;
if (req.getParameterMap().containsKey("whitelabel")) { // override with url parameter for testing usage only
debugDebranding = true;
}
final boolean deBrandingActive = Boolean.valueOf(System.getProperty(DEBRANDING_PROPERTY_NAME, "false"));
final String servletPath = req.getServletPath();
byte[] value = null;
if (!debugDebranding && (value = cache.get(servletPath)) != null) {
if ((value = cache.get(generateKey(servletPath, deBrandingActive))) != null) {
IOUtils.write(value, resp.getOutputStream());
return;
}
boolean deBrandingActive = Boolean.valueOf(System.getProperty("com.sap.sailing.debranding", "false")) || debugDebranding;
String title = "";
String faviconPath = "images/whitelabel.ico";
@@ -54,10 +50,12 @@ public class ClientConfigurationServlet extends HttpServlet {
byte[] bytes = replaced.getBytes();
IOUtils.write(bytes, resp.getOutputStream());
if (!debugDebranding) {
cache.computeIfAbsent(servletPath, key -> bytes);
}
cache.computeIfAbsent(generateKey(servletPath, deBrandingActive), key -> bytes);
}
}
private String generateKey(String servletPath, boolean active) {
return servletPath + "_" + active;
}
}
@@ -40,19 +40,23 @@ public abstract class HostPage extends PageObject {
throw new IllegalArgumentException(exc);
}
}
private static final void goToPage(WebDriver driver, URI uri) throws URISyntaxException {
String scheme = uri.getScheme(), userInfo = uri.getUserInfo(), host = uri.getHost();
String path = uri.getPath(), query = getGWTCodeServerAndLocale() + "&" + uri.getQuery(), fragment = uri.getFragment();
String scheme = uri.getScheme(), userInfo = uri.getUserInfo(), host = uri.getHost();
String path = uri.getPath(),
query = getGWTCodeServerAndLocale() + (uri.getQuery() != null ? "&" + uri.getQuery() : ""),
fragment = uri.getFragment();
driver.get(new URI(scheme, userInfo, host, uri.getPort(), path, query, fragment).toString());
}
/**
* <p>Creates a new page object with the given web driver. In GWT an entry point is connected to a HTML page in
* which the code for the application is executed, whereby the page is represented by the web driver.</p>
* <p>
* Creates a new page object with the given web driver. In GWT an entry point is connected to a HTML page in which
* the code for the application is executed, whereby the page is represented by the web driver.
* </p>
*
* @param driver
* The web driver to use.
* The web driver to use.
*/
public HostPage(WebDriver driver) {
super(driver);
@@ -58,11 +58,7 @@ public class HomePage extends HostPageWithAuthentication {
* @return the {@link PageObject} for the home page
*/
public static HomePage goToPage(WebDriver driver, String root) {
return goToPage(driver, root, false);
}
public static HomePage goToPage(WebDriver driver, String root, boolean debranded) {
return goToHomeUrl(driver, root + "gwt/Home.html" + (debranded ? "?whitelabel" : ""));
return goToHomeUrl(driver, root + "gwt/Home.html");
}
/**