From 39b293b9f66c3c539e180fb2bcf37849335100dc Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 18 May 2023 16:16:10 -0700 Subject: Fix override filter --- src/main/java/org/traccar/web/OverrideFilter.java | 40 ++++++++++++---------- src/main/java/org/traccar/web/ResponseWrapper.java | 3 +- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/main/java/org/traccar/web/OverrideFilter.java b/src/main/java/org/traccar/web/OverrideFilter.java index e6e02514c..70eb80a67 100644 --- a/src/main/java/org/traccar/web/OverrideFilter.java +++ b/src/main/java/org/traccar/web/OverrideFilter.java @@ -50,30 +50,32 @@ public class OverrideFilter implements Filter { chain.doFilter(request, wrappedResponse); byte[] bytes = wrappedResponse.getCapture(); - if (wrappedResponse.getContentType() != null && wrappedResponse.getContentType().contains("text/html") - || ((HttpServletRequest) request).getPathInfo().endsWith("manifest.json")) { + if (bytes != null) { + if (wrappedResponse.getContentType() != null && wrappedResponse.getContentType().contains("text/html") + || ((HttpServletRequest) request).getPathInfo().endsWith("manifest.json")) { - Server server; - try { - server = permissionsServiceProvider.get().getServer(); - } catch (StorageException e) { - throw new RuntimeException(e); - } + Server server; + try { + server = permissionsServiceProvider.get().getServer(); + } catch (StorageException e) { + throw new RuntimeException(e); + } - String title = server.getString("title", "Traccar"); - String description = server.getString("description", "Traccar GPS Tracking System"); - String colorPrimary = server.getString("colorPrimary", "#1a237e"); + String title = server.getString("title", "Traccar"); + String description = server.getString("description", "Traccar GPS Tracking System"); + String colorPrimary = server.getString("colorPrimary", "#1a237e"); - String alteredContent = new String(wrappedResponse.getCapture()) - .replace("${title}", title) - .replace("${description}", description) - .replace("${colorPrimary}", colorPrimary); + String alteredContent = new String(wrappedResponse.getCapture()) + .replace("${title}", title) + .replace("${description}", description) + .replace("${colorPrimary}", colorPrimary); - response.setContentLength(alteredContent.length()); - response.getOutputStream().write(alteredContent.getBytes()); + response.setContentLength(alteredContent.length()); + response.getOutputStream().write(alteredContent.getBytes()); - } else { - response.getOutputStream().write(bytes); + } else { + response.getOutputStream().write(bytes); + } } } diff --git a/src/main/java/org/traccar/web/ResponseWrapper.java b/src/main/java/org/traccar/web/ResponseWrapper.java index 7c06b67b8..c6179a33e 100644 --- a/src/main/java/org/traccar/web/ResponseWrapper.java +++ b/src/main/java/org/traccar/web/ResponseWrapper.java @@ -75,8 +75,9 @@ public class ResponseWrapper extends HttpServletResponseWrapper { public byte[] getCapture() throws IOException { if (output != null) { output.close(); + return capture.toByteArray(); } - return capture.toByteArray(); + return null; } } -- cgit v1.2.3