diff --git a/src/integration/java/org/jlab/epics2web/ConsoleTest.java b/src/integration/java/org/jlab/epics2web/ConsoleTest.java new file mode 100644 index 0000000..6120114 --- /dev/null +++ b/src/integration/java/org/jlab/epics2web/ConsoleTest.java @@ -0,0 +1,62 @@ +package org.jlab.epics2web; + +import static org.junit.Assert.assertTrue; + +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.net.http.WebSocket; +import java.util.regex.Pattern; +import org.junit.Test; + +/** Tests the /console page. */ +public class ConsoleTest { + + private static final HttpClient HTTP = HttpClient.newHttpClient(); + + /** + * A request without Accept-Language, such as from a script, gets the console's time format, not + * Date.toString(), which JSTL falls back to when it finds no locale. HttpClient sends no + * Accept-Language. + */ + @Test + public void timesAreFormattedWithoutAcceptLanguage() throws Exception { + WebSocket socket = + HTTP.newWebSocketBuilder() + .buildAsync( + URI.create("ws://localhost:8080/epics2web/monitor?clientName=console-test"), + new WebSocket.Listener() {}) + .join(); + + try { + socket.sendText("{\"type\": \"monitor\", \"pvs\": [\"channel1\"]}", true).join(); + + // Monitor row cells: PV, state, last update ("MMM dd yyyy HH:mm:ss - value") + Pattern formatted = + Pattern.compile( + "channel1\\s*[^<]*\\s*[A-Z][a-z]{2} \\d{2} \\d{4}" + + " \\d{2}:\\d{2}:\\d{2} - "); + + long deadline = System.currentTimeMillis() + 5_000; + boolean found = false; + + while (!found && System.currentTimeMillis() < deadline) { + found = formatted.matcher(get("console").body()).find(); + if (!found) { + Thread.sleep(100); + } + } + + assertTrue("channel1's last update not formatted on the console", found); + } finally { + socket.abort(); + } + } + + private static HttpResponse get(String path) throws Exception { + return HTTP.send( + HttpRequest.newBuilder().uri(URI.create("http://localhost:8080/epics2web/" + path)).build(), + HttpResponse.BodyHandlers.ofString()); + } +} diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index 87f7a57..fc56cd9 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -20,6 +20,11 @@ java.lang.String @PRODUCTION_RELEASE@ + + jakarta.servlet.jsp.jstl.fmt.fallbackLocale + en-US + Locale of fmt tags when a request has no Accept-Language; without it they fall back to toString() + org.apache.tomcat.websocket.textBufferSize 8192