From f67cdc5f9f181e198a3bc2d76b702d2ceb17d1e9 Mon Sep 17 00:00:00 2001 From: sebr72 Date: Thu, 9 May 2024 14:38:29 +0200 Subject: [PATCH 01/17] Fix Post commands in the test CLI, and minor fixes --- .../org/mapfish/print/processor/AbstractProcessor.java | 2 +- .../java/org/mapfish/print/processor/ExecutionStats.java | 6 +++--- .../main/resources/mapfish-spring-application-context.xml | 2 +- core/src/main/webapp/index.html | 8 ++++---- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/org/mapfish/print/processor/AbstractProcessor.java b/core/src/main/java/org/mapfish/print/processor/AbstractProcessor.java index 6676968f58..8bd8fd099a 100644 --- a/core/src/main/java/org/mapfish/print/processor/AbstractProcessor.java +++ b/core/src/main/java/org/mapfish/print/processor/AbstractProcessor.java @@ -206,7 +206,7 @@ public String toString() { public static final class Context implements ExecutionContext { @Nonnull private final Map mdcContext; private volatile boolean canceled = false; - private ExecutionStats stats = new ExecutionStats(); + private final ExecutionStats stats = new ExecutionStats(); /** * @param mdcContext The MDC context. diff --git a/core/src/main/java/org/mapfish/print/processor/ExecutionStats.java b/core/src/main/java/org/mapfish/print/processor/ExecutionStats.java index f89bcac1de..bc00600cc5 100644 --- a/core/src/main/java/org/mapfish/print/processor/ExecutionStats.java +++ b/core/src/main/java/org/mapfish/print/processor/ExecutionStats.java @@ -13,9 +13,9 @@ /** Statisctics about the execution of a print job. */ public class ExecutionStats { - private List mapStats = new ArrayList<>(); - private List pageStats = new ArrayList<>(); - private List emailDests = new ArrayList<>(); + private final List mapStats = new ArrayList<>(); + private final List pageStats = new ArrayList<>(); + private final List emailDests = new ArrayList<>(); private boolean storageUsed = false; /** diff --git a/core/src/main/resources/mapfish-spring-application-context.xml b/core/src/main/resources/mapfish-spring-application-context.xml index 7b69183cb7..ff4ced5242 100644 --- a/core/src/main/resources/mapfish-spring-application-context.xml +++ b/core/src/main/resources/mapfish-spring-application-context.xml @@ -42,7 +42,7 @@ - + diff --git a/core/src/main/webapp/index.html b/core/src/main/webapp/index.html index 5c0e62e2f0..22cddb3aff 100644 --- a/core/src/main/webapp/index.html +++ b/core/src/main/webapp/index.html @@ -54,7 +54,7 @@ $.ajax({ type: 'GET', url: 'print/' + appId + '/exampleRequest.json', - dataType: 'json', + dataType: 'Json', success: function (data) { var setExample = true; requestExamples = data; @@ -111,13 +111,13 @@ url: 'print/' + appId + '/report.' + format, data: data, success: function (data) { - downloadWhenReady(startTime, $.parseJSON(data)); + downloadWhenReady(startTime, data); }, error: function (data) { $('#messages').text('Error creating report: ' + data.statusText); disableUI(false); }, - dataType: 'application/json', + dataType: 'Json', }); } @@ -142,7 +142,7 @@ $('#messages').text('Error creating report: ' + data.statusText); disableUI(false); }, - dataType: 'application/json', + dataType: 'Json', }); } From ef7bf21dff0de37aa0af885f4becdd1a33542f2b Mon Sep 17 00:00:00 2001 From: sebr72 Date: Thu, 9 May 2024 14:41:58 +0200 Subject: [PATCH 02/17] Autoclose timers and refactor code --- .../http/ErrorResponseClientHttpResponse.java | 42 +++++++++++ .../print/http/HttpRequestFetcher.java | 74 ++++++------------- 2 files changed, 64 insertions(+), 52 deletions(-) create mode 100644 core/src/main/java/org/mapfish/print/http/ErrorResponseClientHttpResponse.java diff --git a/core/src/main/java/org/mapfish/print/http/ErrorResponseClientHttpResponse.java b/core/src/main/java/org/mapfish/print/http/ErrorResponseClientHttpResponse.java new file mode 100644 index 0000000000..9fbf768fc6 --- /dev/null +++ b/core/src/main/java/org/mapfish/print/http/ErrorResponseClientHttpResponse.java @@ -0,0 +1,42 @@ +package org.mapfish.print.http; + +import java.io.InputStream; +import javax.annotation.Nonnull; +import org.springframework.http.HttpHeaders; +import org.springframework.http.client.AbstractClientHttpResponse; +import org.springframework.util.StreamUtils; + +public class ErrorResponseClientHttpResponse extends AbstractClientHttpResponse { + private final Exception exception; + + public ErrorResponseClientHttpResponse(final Exception e) { + assert e != null; + this.exception = e; + } + + @Override + @Nonnull + public HttpHeaders getHeaders() { + return new HttpHeaders(); + } + + @Override + @Nonnull + public InputStream getBody() { + return StreamUtils.emptyInput(); + } + + @Override + public int getRawStatusCode() { + return 500; + } + + @Override + @Nonnull + public String getStatusText() { + return exception.getMessage(); + } + + @Override + public void close() {} +} diff --git a/core/src/main/java/org/mapfish/print/http/HttpRequestFetcher.java b/core/src/main/java/org/mapfish/print/http/HttpRequestFetcher.java index 57b723f584..f49b46a144 100644 --- a/core/src/main/java/org/mapfish/print/http/HttpRequestFetcher.java +++ b/core/src/main/java/org/mapfish/print/http/HttpRequestFetcher.java @@ -24,7 +24,6 @@ import org.springframework.http.client.AbstractClientHttpResponse; import org.springframework.http.client.ClientHttpRequest; import org.springframework.http.client.ClientHttpResponse; -import org.springframework.util.StreamUtils; /** * Schedule tasks for caching Http Requests that can be run simultaneously. @@ -139,7 +138,7 @@ private final class CachedClientHttpRequest implements ClientHttpRequest, Callab private final ClientHttpRequest originalRequest; private final Processor.ExecutionContext context; @Nullable private ClientHttpResponse response; - @Nullable private ForkJoinTask future; + private ForkJoinTask future; private CachedClientHttpRequest( final ClientHttpRequest request, final Processor.ExecutionContext context) { @@ -155,7 +154,7 @@ public HttpMethod getMethod() { @Override @Nonnull public String getMethodValue() { - final HttpMethod method = this.originalRequest.getMethod(); + final HttpMethod method = getMethod(); return method != null ? method.name() : ""; } @@ -182,13 +181,10 @@ public OutputStream getBody() { @Nonnull public ClientHttpResponse execute() { assert this.future != null; - final Timer.Context timerWait = - HttpRequestFetcher.this - .registry - .timer(HttpRequestFetcher.class.getName() + ".waitDownloader") - .time(); - this.future.join(); - timerWait.stop(); + Timer timerWait = HttpRequestFetcher.this.registry.timer(buildMetricName(".waitDownloader")); + try (Timer.Context ignored = timerWait.time()) { + this.future.join(); + } assert this.response != null; LOGGER.debug("Loading cached URI resource {}", this.originalRequest.getURI()); @@ -200,58 +196,32 @@ public ClientHttpResponse execute() { return result; } + private String buildMetricName(final String suffix) { + return HttpRequestFetcher.class.getName() + suffix; + } + @Override public Void call() throws Exception { return context.mdcContextEx( () -> { final String baseMetricName = - HttpRequestFetcher.class.getName() - + ".read." - + StatsUtils.quotePart(getURI().getHost()); - final Timer.Context timerDownload = - HttpRequestFetcher.this.registry.timer(baseMetricName).time(); - try { - context.stopIfCanceled(); - this.response = new CachedClientHttpResponse(this.originalRequest.execute()); - } catch (IOException e) { - LOGGER.error("Request failed {}", this.originalRequest.getURI(), e); - this.response = - new AbstractClientHttpResponse() { - @Override - @Nonnull - public HttpHeaders getHeaders() { - return new HttpHeaders(); - } - - @Override - @Nonnull - public InputStream getBody() { - return StreamUtils.emptyInput(); - } - - @Override - public int getRawStatusCode() { - return 500; - } - - @Override - @Nonnull - public String getStatusText() { - return e.getMessage(); - } - - @Override - public void close() {} - }; - HttpRequestFetcher.this.registry.counter(baseMetricName + ".error").inc(); - } finally { - timerDownload.stop(); + buildMetricName(".read." + StatsUtils.quotePart(getURI().getHost())); + Timer timerDownload = HttpRequestFetcher.this.registry.timer(baseMetricName); + try (Timer.Context ignored = timerDownload.time()) { + try { + context.stopIfCanceled(); + this.response = new CachedClientHttpResponse(this.originalRequest.execute()); + } catch (IOException | RuntimeException e) { + LOGGER.error("Request failed {}", this.originalRequest.getURI(), e); + this.response = new ErrorResponseClientHttpResponse(e); + HttpRequestFetcher.this.registry.counter(baseMetricName + ".error").inc(); + } } return null; }); } - public void setFuture(final ForkJoinTask future) { + public void setFuture(final @Nonnull ForkJoinTask future) { this.future = future; } } From 31ea0d2fa22a758413314e61eb1b5ba7fb3bc8f0 Mon Sep 17 00:00:00 2001 From: sebr72 Date: Thu, 9 May 2024 17:10:41 +0200 Subject: [PATCH 03/17] Improved logging and object creation. Minor fixes. --- .../print/servlet/MapPrinterServlet.java | 38 +++++++++---------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/core/src/main/java/org/mapfish/print/servlet/MapPrinterServlet.java b/core/src/main/java/org/mapfish/print/servlet/MapPrinterServlet.java index 920b163b79..6c92419e76 100644 --- a/core/src/main/java/org/mapfish/print/servlet/MapPrinterServlet.java +++ b/core/src/main/java/org/mapfish/print/servlet/MapPrinterServlet.java @@ -21,6 +21,7 @@ import java.util.Arrays; import java.util.Enumeration; import java.util.List; +import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.UUID; @@ -250,18 +251,17 @@ public MapPrinterServlet( LOGGER.info( "Sentry event, logger: {}, message: {}", event.getLogger(), - event.getMessage().getMessage()); - if (event.getLogger().equals("org.hibernate.engine.jdbc.spi.SqlExceptionHelper") - && (event - .getMessage() - .getMessage() - .equals( + event.getMessage() != null ? event.getMessage().getMessage() : null); + if (Objects.equals( + event.getLogger(), "org.hibernate.engine.jdbc.spi.SqlExceptionHelper") + && ((event.getMessage() != null) + && (Objects.equals( + event.getMessage().getMessage(), "ERROR: could not obtain lock on row in relation" + " \"print_job_statuses\"") - || event - .getMessage() - .getMessage() - .equals("SQL Error: 0, SQLState: 55P03"))) { + || Objects.equals( + event.getMessage().getMessage(), + "SQL Error: 0, SQLState: 55P03")))) { return null; } return event; @@ -696,7 +696,7 @@ public final void createReportAndGet( } final HandleReportLoadResult handler = - new HandleReportLoadResult() { + new HandleReportLoadResult<>() { @Override public Boolean unknownReference( @@ -891,7 +891,7 @@ public final void getCapabilities( if (pretty) { final JSONObject jsonObject = - new JSONObject(new String(prettyPrintBuffer.toByteArray(), Constants.DEFAULT_CHARSET)); + new JSONObject(prettyPrintBuffer.toString(Constants.DEFAULT_CHARSET)); capabilitiesResponse.getOutputStream().print(jsonObject.toString(JSON_INDENT_FACTOR)); } } @@ -948,8 +948,7 @@ public final void getExampleRequest( for (File child : children) { if (child.isFile()) { - String requestData = - new String(Files.readAllBytes(child.toPath()), Constants.DEFAULT_CHARSET); + String requestData = Files.readString(child.toPath(), Constants.DEFAULT_CHARSET); try { final JSONObject jsonObject = new JSONObject(requestData); jsonObject.remove(JSON_OUTPUT_FORMAT); @@ -1168,20 +1167,19 @@ private String createAndSubmitPrintJob( if (specJson == null) { return null; } - String ref = + final String ref = maybeAddRequestId( - UUID.randomUUID().toString() + "@" + this.servletInfo.getServletId(), - httpServletRequest); + UUID.randomUUID() + "@" + this.servletInfo.getServletId(), httpServletRequest); MDC.put(Processor.MDC_APPLICATION_ID_KEY, appId); MDC.put(Processor.MDC_JOB_ID_KEY, ref); - LOGGER.debug("{}", specJson); + LOGGER.debug("Created Ref:{} for {}", ref, specJson); specJson.getInternalObj().remove(JSON_OUTPUT_FORMAT); specJson.getInternalObj().put(JSON_OUTPUT_FORMAT, format); specJson.getInternalObj().remove(JSON_APP); specJson.getInternalObj().put(JSON_APP, appId); final JSONObject requestHeaders = getHeaders(httpServletRequest); - if (requestHeaders.length() > 0) { + if (!requestHeaders.isEmpty()) { specJson .getInternalObj() .getJSONObject(JSON_ATTRIBUTES) @@ -1205,7 +1203,7 @@ private String createAndSubmitPrintJob( this.jobManager.submit(jobEntry); } catch (RuntimeException exc) { LOGGER.error("Error when creating job on {}: {}", appId, specJson, exc); - ref = null; + return null; } return ref; } From dfea2639a7c1980e7dc6a9d12b3fc14908461913 Mon Sep 17 00:00:00 2001 From: sebr72 Date: Thu, 9 May 2024 23:29:44 +0200 Subject: [PATCH 04/17] Remove anonymous inner classes. Move code to where it is needed --- .../mapfish/print/servlet/BaseMapServlet.java | 52 ------ .../BooleanHandleReportLoadResult.java | 59 +++++++ .../print/servlet/HandleReportLoadResult.java | 91 +++++++++- .../print/servlet/MapPrinterServlet.java | 159 ++---------------- .../servlet/VoidHandleReportLoadResult.java | 64 +++++++ 5 files changed, 218 insertions(+), 207 deletions(-) create mode 100644 core/src/main/java/org/mapfish/print/servlet/BooleanHandleReportLoadResult.java create mode 100644 core/src/main/java/org/mapfish/print/servlet/VoidHandleReportLoadResult.java diff --git a/core/src/main/java/org/mapfish/print/servlet/BaseMapServlet.java b/core/src/main/java/org/mapfish/print/servlet/BaseMapServlet.java index a56e1ce55d..1675be4b09 100644 --- a/core/src/main/java/org/mapfish/print/servlet/BaseMapServlet.java +++ b/core/src/main/java/org/mapfish/print/servlet/BaseMapServlet.java @@ -2,9 +2,6 @@ import java.io.IOException; import java.io.PrintWriter; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Date; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.mapfish.print.PrintException; @@ -17,38 +14,6 @@ public abstract class BaseMapServlet { private static final Logger LOGGER = LoggerFactory.getLogger(BaseMapServlet.class); private int cacheDurationInSeconds = 3600; - /** - * Remove commas and whitespace from a string. - * - * @param original the starting string. - */ - protected static String cleanUpName(final String original) { - return original.replace(",", "").replaceAll("\\s+", "_"); - } - - /** - * Update a variable name with a date if the variable is detected as being a date. - * - * @param variableName the variable name. - * @param date the date to replace the value with if the variable is a date variable. - */ - public static String findReplacement(final String variableName, final Date date) { - if (variableName.equalsIgnoreCase("date")) { - return cleanUpName(DateFormat.getDateInstance().format(date)); - } else if (variableName.equalsIgnoreCase("datetime")) { - return cleanUpName(DateFormat.getDateTimeInstance().format(date)); - } else if (variableName.equalsIgnoreCase("time")) { - return cleanUpName(DateFormat.getTimeInstance().format(date)); - } else { - try { - return new SimpleDateFormat(variableName).format(date); - } catch (Exception e) { - LOGGER.error("Unable to format timestamp according to pattern: {}", variableName, e); - return "${" + variableName + "}"; - } - } - } - /** * Send an error to the client with a message. * @@ -82,23 +47,6 @@ protected static void setNoCache(final HttpServletResponse response) { response.setHeader("Cache-Control", "max-age=0, must-revalidate, no-cache, no-store"); } - /** - * Send an error to the client with an exception. - * - * @param httpServletResponse the http response to send the error to - * @param e the error that occurred - */ - protected final void error(final HttpServletResponse httpServletResponse, final Throwable e) { - httpServletResponse.setContentType("text/plain"); - httpServletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); - try (PrintWriter out = httpServletResponse.getWriter()) { - out.println("Error while processing request:"); - LOGGER.warn("Error while processing request", e); - } catch (IOException ex) { - throw new PrintException("", e); - } - } - /** * Returns the base URL of the print servlet. * diff --git a/core/src/main/java/org/mapfish/print/servlet/BooleanHandleReportLoadResult.java b/core/src/main/java/org/mapfish/print/servlet/BooleanHandleReportLoadResult.java new file mode 100644 index 0000000000..64fd3dbccd --- /dev/null +++ b/core/src/main/java/org/mapfish/print/servlet/BooleanHandleReportLoadResult.java @@ -0,0 +1,59 @@ +package org.mapfish.print.servlet; + +import java.io.IOException; +import java.net.URI; +import javax.servlet.http.HttpServletResponse; +import org.mapfish.print.servlet.job.PrintJobStatus; +import org.mapfish.print.servlet.job.loader.ReportLoader; +import org.springframework.http.HttpStatus; + +class BooleanHandleReportLoadResult extends HandleReportLoadResult { + private final boolean isInlining; + + public BooleanHandleReportLoadResult(final boolean inline) { + isInlining = inline; + } + + @Override + public Boolean unknownReference( + final HttpServletResponse httpServletResponse, final String referenceId) { + BaseMapServlet.error( + httpServletResponse, "Print with ref=" + referenceId + " unknown", HttpStatus.NOT_FOUND); + return true; + } + + @Override + public Boolean unsupportedLoader( + final HttpServletResponse httpServletResponse, final String referenceId) { + BaseMapServlet.error( + httpServletResponse, + "Print with ref=" + referenceId + " can not be loaded", + HttpStatus.NOT_FOUND); + return true; + } + + @Override + public Boolean successfulPrint( + final PrintJobStatus successfulPrintResult, + final HttpServletResponse httpServletResponse, + final URI reportURI, + final ReportLoader loader) + throws IOException { + sendReportFile(successfulPrintResult, httpServletResponse, loader, reportURI, isInlining); + return true; + } + + @Override + public Boolean failedPrint( + final PrintJobStatus failedPrintJob, final HttpServletResponse httpServletResponse) { + BaseMapServlet.error( + httpServletResponse, failedPrintJob.getError(), HttpStatus.INTERNAL_SERVER_ERROR); + return true; + } + + @Override + public Boolean printJobPending( + final HttpServletResponse httpServletResponse, final String referenceId) { + return false; + } +} diff --git a/core/src/main/java/org/mapfish/print/servlet/HandleReportLoadResult.java b/core/src/main/java/org/mapfish/print/servlet/HandleReportLoadResult.java index ad94397efc..6ccf1ce982 100644 --- a/core/src/main/java/org/mapfish/print/servlet/HandleReportLoadResult.java +++ b/core/src/main/java/org/mapfish/print/servlet/HandleReportLoadResult.java @@ -1,18 +1,28 @@ package org.mapfish.print.servlet; import java.io.IOException; +import java.io.OutputStream; import java.net.URI; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import javax.servlet.ServletException; import javax.servlet.http.HttpServletResponse; import org.mapfish.print.servlet.job.PrintJobStatus; import org.mapfish.print.servlet.job.loader.ReportLoader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Called when a report is loaded to be sent to the user. * * @param The return value */ -public interface HandleReportLoadResult { +abstract class HandleReportLoadResult { + private static final Pattern VARIABLE_PATTERN = Pattern.compile("\\$\\{(\\S+)}"); + private static final Logger LOGGER = LoggerFactory.getLogger(HandleReportLoadResult.class); /** * Called if the report reference is unknown. @@ -20,7 +30,7 @@ public interface HandleReportLoadResult { * @param httpServletResponse response object * @param referenceId report id */ - R unknownReference(HttpServletResponse httpServletResponse, String referenceId); + abstract R unknownReference(HttpServletResponse httpServletResponse, String referenceId); /** * Called if no loader can be found for loading the report. @@ -28,7 +38,7 @@ public interface HandleReportLoadResult { * @param httpServletResponse response object * @param referenceId report id */ - R unsupportedLoader(HttpServletResponse httpServletResponse, String referenceId); + abstract R unsupportedLoader(HttpServletResponse httpServletResponse, String referenceId); /** * Called when a print succeeded. @@ -38,7 +48,7 @@ public interface HandleReportLoadResult { * @param reportURI the uri to the report * @param loader the loader for loading the report. */ - R successfulPrint( + abstract R successfulPrint( PrintJobStatus successfulPrintResult, HttpServletResponse httpServletResponse, URI reportURI, @@ -51,7 +61,7 @@ R successfulPrint( * @param failedPrintJob the failed print job * @param httpServletResponse the object for writing response */ - R failedPrint(PrintJobStatus failedPrintJob, HttpServletResponse httpServletResponse); + abstract R failedPrint(PrintJobStatus failedPrintJob, HttpServletResponse httpServletResponse); /** * Called when the print job has not yet completed. @@ -59,5 +69,74 @@ R successfulPrint( * @param httpServletResponse the object for writing response * @param referenceId report id */ - R printJobPending(HttpServletResponse httpServletResponse, String referenceId); + abstract R printJobPending(HttpServletResponse httpServletResponse, String referenceId); + + /** + * Copy the PDF into the output stream. + * + * @param metadata the client request data + * @param httpServletResponse the response object + * @param reportLoader the object used for loading the report + * @param reportURI the uri of the report + * @param inline whether to inline the content + */ + protected final void sendReportFile( + final PrintJobStatus metadata, + final HttpServletResponse httpServletResponse, + final ReportLoader reportLoader, + final URI reportURI, + final boolean inline) + throws IOException { + + try (OutputStream response = httpServletResponse.getOutputStream()) { + httpServletResponse.setContentType(metadata.getResult().getMimeType()); + if (!inline) { + String fileName = metadata.getResult().getFileName(); + Matcher matcher = VARIABLE_PATTERN.matcher(fileName); + while (matcher.find()) { + final String variable = matcher.group(1); + String replacement = findReplacement(variable, metadata.getCompletionDate()); + fileName = fileName.replace("${" + variable + "}", replacement); + matcher = VARIABLE_PATTERN.matcher(fileName); + } + + fileName += "." + metadata.getResult().getFileExtension(); + httpServletResponse.setHeader( + "Content-disposition", "attachment; filename=" + cleanUpName(fileName)); + } + reportLoader.loadReport(reportURI, response); + } + } + + /** + * Update a variable name with a date if the variable is detected as being a date. + * + * @param variableName the variable name. + * @param date the date to replace the value with if the variable is a date variable. + */ + private String findReplacement(final String variableName, final Date date) { + if (variableName.equalsIgnoreCase("date")) { + return cleanUpName(DateFormat.getDateInstance().format(date)); + } else if (variableName.equalsIgnoreCase("datetime")) { + return cleanUpName(DateFormat.getDateTimeInstance().format(date)); + } else if (variableName.equalsIgnoreCase("time")) { + return cleanUpName(DateFormat.getTimeInstance().format(date)); + } else { + try { + return new SimpleDateFormat(variableName).format(date); + } catch (RuntimeException e) { + LOGGER.error("Unable to format timestamp according to pattern: {}", variableName, e); + return "${" + variableName + "}"; + } + } + } + + /** + * Remove commas and whitespace from a string. + * + * @param original the starting string. + */ + private String cleanUpName(final String original) { + return original.replace(",", "").replaceAll("\\s+", "_"); + } } diff --git a/core/src/main/java/org/mapfish/print/servlet/MapPrinterServlet.java b/core/src/main/java/org/mapfish/print/servlet/MapPrinterServlet.java index 6c92419e76..e2a6d31844 100644 --- a/core/src/main/java/org/mapfish/print/servlet/MapPrinterServlet.java +++ b/core/src/main/java/org/mapfish/print/servlet/MapPrinterServlet.java @@ -6,7 +6,6 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; -import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; @@ -26,8 +25,6 @@ import java.util.Set; import java.util.UUID; import java.util.concurrent.TimeUnit; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import javax.annotation.Nonnull; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; @@ -205,7 +202,6 @@ public class MapPrinterServlet extends BaseMapServlet { public static final String JSON_OUTPUT_FONTCONFIG_WEIGHT = "weight"; private static final Logger LOGGER = LoggerFactory.getLogger(MapPrinterServlet.class); - private static final Pattern VARIABLE_PATTERN = Pattern.compile("\\$\\{(\\S+)}"); private static final int JSON_INDENT_FACTOR = 4; private static final List REQUEST_ID_HEADERS = Arrays.asList( @@ -532,7 +528,7 @@ public final void createReport( * * @param appId the app ID * @param referenceId the path to the file. - * @param inline whether or not to inline the + * @param inline whether to inline the * @param getReportResponse the response object */ @RequestMapping( @@ -551,7 +547,7 @@ public final void getReportSpecificAppId( * To get the PDF created previously. * * @param referenceId the job reference - * @param inline whether or not to inline the + * @param inline whether to inline the * @param getReportResponse the response object */ @RequestMapping(value = REPORT_URL + "/{referenceId:\\S+}", method = RequestMethod.GET) @@ -568,7 +564,7 @@ public final void getReportPath( * * @param applicationId the application ID * @param referenceId the job reference - * @param inline whether or not to inline the + * @param inline whether to inline the * @param getReportResponse the response object */ public final void getReport( @@ -580,59 +576,7 @@ public final void getReport( MDC.put(Processor.MDC_APPLICATION_ID_KEY, applicationId); MDC.put(Processor.MDC_JOB_ID_KEY, referenceId); setNoCache(getReportResponse); - loadReport( - referenceId, - getReportResponse, - new HandleReportLoadResult() { - - @Override - public Void unknownReference( - final HttpServletResponse httpServletResponse, final String referenceId) { - error( - httpServletResponse, - "Error getting print with ref=" + referenceId + ": unknown reference", - HttpStatus.NOT_FOUND); - return null; - } - - @Override - public Void unsupportedLoader( - final HttpServletResponse httpServletResponse, final String referenceId) { - error( - httpServletResponse, - "Error getting print with ref=" + referenceId + " can not be loaded", - HttpStatus.NOT_FOUND); - return null; - } - - @Override - public Void successfulPrint( - final PrintJobStatus successfulPrintResult, - final HttpServletResponse httpServletResponse, - final URI reportURI, - final ReportLoader loader) - throws IOException { - sendReportFile(successfulPrintResult, httpServletResponse, loader, reportURI, inline); - return null; - } - - @Override - public Void failedPrint( - final PrintJobStatus failedPrintJob, final HttpServletResponse httpServletResponse) { - error(httpServletResponse, failedPrintJob.getError(), HttpStatus.INTERNAL_SERVER_ERROR); - return null; - } - - @Override - public Void printJobPending( - final HttpServletResponse httpServletResponse, final String referenceId) { - error( - httpServletResponse, - "Report has not yet completed processing", - HttpStatus.ACCEPTED); - return null; - } - }); + loadReport(referenceId, getReportResponse, new VoidHandleReportLoadResult(inline)); } /** @@ -670,7 +614,7 @@ public final void createReport( * @param format the format of the returned report * @param requestData a json formatted string with the request data required to perform the report * generation. - * @param inline whether or not to inline the content + * @param inline whether to inline the content * @param createReportRequest the request object * @param createReportResponse the response object */ @@ -695,58 +639,11 @@ public final void createReportAndGet( return; } - final HandleReportLoadResult handler = - new HandleReportLoadResult<>() { - - @Override - public Boolean unknownReference( - final HttpServletResponse httpServletResponse, final String referenceId) { - error( - httpServletResponse, - "Print with ref=" + referenceId + " unknown", - HttpStatus.NOT_FOUND); - return true; - } - - @Override - public Boolean unsupportedLoader( - final HttpServletResponse httpServletResponse, final String referenceId) { - error( - httpServletResponse, - "Print with ref=" + referenceId + " can not be loaded", - HttpStatus.NOT_FOUND); - return true; - } - - @Override - public Boolean successfulPrint( - final PrintJobStatus successfulPrintResult, - final HttpServletResponse httpServletResponse, - final URI reportURI, - final ReportLoader loader) - throws IOException { - sendReportFile(successfulPrintResult, httpServletResponse, loader, reportURI, inline); - return true; - } - - @Override - public Boolean failedPrint( - final PrintJobStatus failedPrintJob, final HttpServletResponse httpServletResponse) { - error(httpServletResponse, failedPrintJob.getError(), HttpStatus.INTERNAL_SERVER_ERROR); - return true; - } - - @Override - public Boolean printJobPending( - final HttpServletResponse httpServletResponse, final String referenceId) { - return false; - } - }; - + final BooleanHandleReportLoadResult handler = new BooleanHandleReportLoadResult(inline); boolean isDone = false; - long startWaitTime = System.currentTimeMillis(); final long maxWaitTimeInMillis = TimeUnit.SECONDS.toMillis(this.maxCreateAndGetWaitTimeInSeconds); + long startWaitTime = System.currentTimeMillis(); while (!isDone && System.currentTimeMillis() - startWaitTime < maxWaitTimeInMillis) { Thread.sleep(TimeUnit.SECONDS.toMillis(1)); isDone = loadReport(ref, createReportResponse, handler); @@ -759,7 +656,7 @@ public Boolean printJobPending( * @param format the format of the returned report * @param requestData a json formatted string with the request data required to perform the report * generation. - * @param inline whether or not to inline the content + * @param inline whether to inline the content * @param createReportRequest the request object * @param createReportResponse the response object */ @@ -1081,43 +978,6 @@ public final void setMaxCreateAndGetWaitTimeInSeconds( this.maxCreateAndGetWaitTimeInSeconds = maxCreateAndGetWaitTimeInSeconds; } - /** - * Copy the PDF into the output stream. - * - * @param metadata the client request data - * @param httpServletResponse the response object - * @param reportLoader the object used for loading the report - * @param reportURI the uri of the report - * @param inline whether or not to inline the content - */ - private void sendReportFile( - final PrintJobStatus metadata, - final HttpServletResponse httpServletResponse, - final ReportLoader reportLoader, - final URI reportURI, - final boolean inline) - throws IOException { - - try (OutputStream response = httpServletResponse.getOutputStream()) { - httpServletResponse.setContentType(metadata.getResult().getMimeType()); - if (!inline) { - String fileName = metadata.getResult().getFileName(); - Matcher matcher = VARIABLE_PATTERN.matcher(fileName); - while (matcher.find()) { - final String variable = matcher.group(1); - String replacement = findReplacement(variable, metadata.getCompletionDate()); - fileName = fileName.replace("${" + variable + "}", replacement); - matcher = VARIABLE_PATTERN.matcher(fileName); - } - - fileName += "." + metadata.getResult().getFileExtension(); - httpServletResponse.setHeader( - "Content-disposition", "attachment; filename=" + cleanUpName(fileName)); - } - reportLoader.loadReport(reportURI, response); - } - } - private void addDownloadLinkToJson( final HttpServletRequest httpServletRequest, final String ref, final JSONWriter json) { String downloadURL = getBaseUrl(httpServletRequest) + REPORT_URL + "/" + ref; @@ -1186,7 +1046,8 @@ private String createAndSubmitPrintJob( .put(JSON_REQUEST_HEADERS, requestHeaders); } - // check that we have authorization and configure the job so it can only be access by users with + // check that we have authorization and configure the job, so it can only be accessed by users + // with // sufficient authorization final String templateName = specJson.getString(Constants.JSON_LAYOUT_KEY); final MapPrinter mapPrinter = this.mapPrinterFactory.create(appId); diff --git a/core/src/main/java/org/mapfish/print/servlet/VoidHandleReportLoadResult.java b/core/src/main/java/org/mapfish/print/servlet/VoidHandleReportLoadResult.java new file mode 100644 index 0000000000..15e2778744 --- /dev/null +++ b/core/src/main/java/org/mapfish/print/servlet/VoidHandleReportLoadResult.java @@ -0,0 +1,64 @@ +package org.mapfish.print.servlet; + +import java.io.IOException; +import java.net.URI; +import javax.servlet.http.HttpServletResponse; +import org.mapfish.print.servlet.job.PrintJobStatus; +import org.mapfish.print.servlet.job.loader.ReportLoader; +import org.springframework.http.HttpStatus; + +class VoidHandleReportLoadResult extends HandleReportLoadResult { + + private final boolean isInlining; + + public VoidHandleReportLoadResult(boolean inline) { + this.isInlining = inline; + } + + @Override + public Void unknownReference( + final HttpServletResponse httpServletResponse, final String referenceId) { + BaseMapServlet.error( + httpServletResponse, + "Error getting print with ref=" + referenceId + ": unknown reference", + HttpStatus.NOT_FOUND); + return null; + } + + @Override + public Void unsupportedLoader( + final HttpServletResponse httpServletResponse, final String referenceId) { + BaseMapServlet.error( + httpServletResponse, + "Error getting print with ref=" + referenceId + " can not be loaded", + HttpStatus.NOT_FOUND); + return null; + } + + @Override + public Void successfulPrint( + final PrintJobStatus successfulPrintResult, + final HttpServletResponse httpServletResponse, + final URI reportURI, + final ReportLoader loader) + throws IOException { + sendReportFile(successfulPrintResult, httpServletResponse, loader, reportURI, isInlining); + return null; + } + + @Override + public Void failedPrint( + final PrintJobStatus failedPrintJob, final HttpServletResponse httpServletResponse) { + BaseMapServlet.error( + httpServletResponse, failedPrintJob.getError(), HttpStatus.INTERNAL_SERVER_ERROR); + return null; + } + + @Override + public Void printJobPending( + final HttpServletResponse httpServletResponse, final String referenceId) { + BaseMapServlet.error( + httpServletResponse, "Report has not yet completed processing", HttpStatus.ACCEPTED); + return null; + } +} From 8f74a4b46f4db785854f178131c8904df7194fcb Mon Sep 17 00:00:00 2001 From: sebr72 Date: Fri, 10 May 2024 00:22:30 +0200 Subject: [PATCH 05/17] Log exceptions and stop increasing counter in all cases --- .../print/processor/ProcessorGraphNode.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/mapfish/print/processor/ProcessorGraphNode.java b/core/src/main/java/org/mapfish/print/processor/ProcessorGraphNode.java index 65ef19adb4..2600d77692 100644 --- a/core/src/main/java/org/mapfish/print/processor/ProcessorGraphNode.java +++ b/core/src/main/java/org/mapfish/print/processor/ProcessorGraphNode.java @@ -190,19 +190,25 @@ protected Values compute() { final In inputParameter = ProcessorUtils.populateInputParameter(process, values); Out output; + boolean isThrowingException = false; try { LOGGER.debug("Executing process: {}", process); output = process.execute(inputParameter, this.execContext.getContext()); LOGGER.debug("Succeeded in executing process: {}", process); } catch (RuntimeException e) { + isThrowingException = true; + LOGGER.info("Error while executing process: {}", process, e); throw e; } catch (Exception e) { + isThrowingException = true; + LOGGER.info("Error while executing process: {}", process, e); throw new PrintException("Failed to execute process:" + process, e); } finally { - // the processor is already canceled, so we don't care if something fails - this.execContext.getContext().stopIfCanceled(); - LOGGER.info("Error while executing process: {}", process); - registry.counter(name + ".error").inc(); + if (isThrowingException) { + // the processor is already canceled, so we don't care if something fails + this.execContext.getContext().stopIfCanceled(); + registry.counter(name + ".error").inc(); + } } if (output != null) { From bbb359413d178dacc92e712b78c376edf0a68a36 Mon Sep 17 00:00:00 2001 From: sebr72 Date: Fri, 10 May 2024 13:03:48 +0200 Subject: [PATCH 06/17] Improve logging --- .../org/mapfish/print/processor/map/CreateMapProcessor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/mapfish/print/processor/map/CreateMapProcessor.java b/core/src/main/java/org/mapfish/print/processor/map/CreateMapProcessor.java index 8e2fe35034..3bb4c8d97a 100644 --- a/core/src/main/java/org/mapfish/print/processor/map/CreateMapProcessor.java +++ b/core/src/main/java/org/mapfish/print/processor/map/CreateMapProcessor.java @@ -741,7 +741,7 @@ && getSupportedRenderType(layers.get(i).getRenderType()) == renderType && imageBufferScaling == layers.get(i).getImageBufferScaling()) { // will always go there the first time l = layers.get(i); - LOGGER.debug("Adding layer {} to the group", l.getName()); + LOGGER.debug("Adding layer: {} named: {} to the group", i, l.getName()); group.layers.add(l); group.opaque = group.opaque || (renderType == RenderType.JPEG && l.getOpacity() == 1.0); ++i; From 6b534f3cd22ee391bb4fbb515494172dc5fbb1ee Mon Sep 17 00:00:00 2001 From: sebr72 Date: Fri, 10 May 2024 13:21:56 +0200 Subject: [PATCH 07/17] Fix checkstyle errors --- .../mapfish/print/servlet/BooleanHandleReportLoadResult.java | 2 +- .../org/mapfish/print/servlet/VoidHandleReportLoadResult.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/mapfish/print/servlet/BooleanHandleReportLoadResult.java b/core/src/main/java/org/mapfish/print/servlet/BooleanHandleReportLoadResult.java index 64fd3dbccd..3007ae8666 100644 --- a/core/src/main/java/org/mapfish/print/servlet/BooleanHandleReportLoadResult.java +++ b/core/src/main/java/org/mapfish/print/servlet/BooleanHandleReportLoadResult.java @@ -10,7 +10,7 @@ class BooleanHandleReportLoadResult extends HandleReportLoadResult { private final boolean isInlining; - public BooleanHandleReportLoadResult(final boolean inline) { + BooleanHandleReportLoadResult(final boolean inline) { isInlining = inline; } diff --git a/core/src/main/java/org/mapfish/print/servlet/VoidHandleReportLoadResult.java b/core/src/main/java/org/mapfish/print/servlet/VoidHandleReportLoadResult.java index 15e2778744..bba96e3c99 100644 --- a/core/src/main/java/org/mapfish/print/servlet/VoidHandleReportLoadResult.java +++ b/core/src/main/java/org/mapfish/print/servlet/VoidHandleReportLoadResult.java @@ -11,7 +11,7 @@ class VoidHandleReportLoadResult extends HandleReportLoadResult { private final boolean isInlining; - public VoidHandleReportLoadResult(boolean inline) { + VoidHandleReportLoadResult(final boolean inline) { this.isInlining = inline; } From 29a626451e5871a43e19f891c67acf6a59508170 Mon Sep 17 00:00:00 2001 From: sebr72 Date: Wed, 15 May 2024 16:44:03 +0200 Subject: [PATCH 08/17] Ensure Polynomial regular expression is used on controlled data --- .../print/servlet/HandleReportLoadResult.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/mapfish/print/servlet/HandleReportLoadResult.java b/core/src/main/java/org/mapfish/print/servlet/HandleReportLoadResult.java index 6ccf1ce982..09b539c056 100644 --- a/core/src/main/java/org/mapfish/print/servlet/HandleReportLoadResult.java +++ b/core/src/main/java/org/mapfish/print/servlet/HandleReportLoadResult.java @@ -21,7 +21,9 @@ * @param The return value */ abstract class HandleReportLoadResult { - private static final Pattern VARIABLE_PATTERN = Pattern.compile("\\$\\{(\\S+)}"); + private static final int FILENAME_MAX_LENGTH = 1000; + private static final Pattern VARIABLE_PATTERN = + Pattern.compile("\\$\\{(\\S{1," + FILENAME_MAX_LENGTH + "})}"); private static final Logger LOGGER = LoggerFactory.getLogger(HandleReportLoadResult.class); /** @@ -92,12 +94,12 @@ protected final void sendReportFile( httpServletResponse.setContentType(metadata.getResult().getMimeType()); if (!inline) { String fileName = metadata.getResult().getFileName(); - Matcher matcher = VARIABLE_PATTERN.matcher(fileName); + Matcher matcher = getFileNameMatcher(fileName); while (matcher.find()) { final String variable = matcher.group(1); String replacement = findReplacement(variable, metadata.getCompletionDate()); fileName = fileName.replace("${" + variable + "}", replacement); - matcher = VARIABLE_PATTERN.matcher(fileName); + matcher = getFileNameMatcher(fileName); } fileName += "." + metadata.getResult().getFileExtension(); @@ -108,6 +110,13 @@ protected final void sendReportFile( } } + private static Matcher getFileNameMatcher(final String fileName) { + if (fileName.length() > FILENAME_MAX_LENGTH) { + throw new IllegalArgumentException("File name is too long"); + } + return VARIABLE_PATTERN.matcher(fileName); + } + /** * Update a variable name with a date if the variable is detected as being a date. * From 1109b1c5ad68fbc56b0ece5bfbec64e9d6c3e555 Mon Sep 17 00:00:00 2001 From: sebr72 Date: Wed, 15 May 2024 18:41:02 +0200 Subject: [PATCH 09/17] Remove HTTP request-splitting or response-splitting vulnerability. --- .../java/org/mapfish/print/servlet/HandleReportLoadResult.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/mapfish/print/servlet/HandleReportLoadResult.java b/core/src/main/java/org/mapfish/print/servlet/HandleReportLoadResult.java index 09b539c056..c6d4789701 100644 --- a/core/src/main/java/org/mapfish/print/servlet/HandleReportLoadResult.java +++ b/core/src/main/java/org/mapfish/print/servlet/HandleReportLoadResult.java @@ -146,6 +146,6 @@ private String findReplacement(final String variableName, final Date date) { * @param original the starting string. */ private String cleanUpName(final String original) { - return original.replace(",", "").replaceAll("\\s+", "_"); + return original.replace(",", "").replaceAll("\\s+", "_").replaceAll("[^a-zA-Z0-9-_.:+]", "_"); } } From 3d0f0195081664ceaa12b66a1fa3c6c49820c2bb Mon Sep 17 00:00:00 2001 From: sebr72 Date: Wed, 15 May 2024 19:08:02 +0200 Subject: [PATCH 10/17] Remove Deprecated class usage --- ...sh-spring-application-context-override.xml | 2 +- .../servlet/ServletMapPrinterFactory.java | 37 +++++++------------ 2 files changed, 15 insertions(+), 24 deletions(-) diff --git a/core/jettyRunExtraFiles/mapfish-spring-application-context-override.xml b/core/jettyRunExtraFiles/mapfish-spring-application-context-override.xml index fccc95c6b5..9591459f50 100644 --- a/core/jettyRunExtraFiles/mapfish-spring-application-context-override.xml +++ b/core/jettyRunExtraFiles/mapfish-spring-application-context-override.xml @@ -13,7 +13,7 @@ location="classpath:mapfish-spring.properties"/> - + getAppDirs(final File base) throws IOException { + try (Stream walk = walk(base.toPath())) { + return walk.map(Path::toFile) + .filter(file -> file.isDirectory() && new File(file, CONFIG_YAML).exists()) + .collect(Collectors.toList()); + } + } + private void pickDefaultApp() { final Iterator> iterator = this.configurationFiles.entrySet().iterator(); if (iterator.hasNext()) { @@ -262,22 +271,4 @@ private URI checkForAddedApp(@Nonnull final String app) { } return null; } - - private static class AppWalker extends DirectoryWalker { - public List getAppDirs(final File base) throws IOException { - List results = new ArrayList<>(); - walk(base, results); - return results; - } - - @Override - protected boolean handleDirectory( - final File directory, final int depth, final Collection results) { - final File configFile = new File(directory, CONFIG_YAML); - if (configFile.exists()) { - results.add(directory); - } - return depth < MAX_DEPTH; - } - } } From 9f1dff4768244fdd1ec1916219b645db19e71c72 Mon Sep 17 00:00:00 2001 From: sebr72 Date: Wed, 15 May 2024 19:20:53 +0200 Subject: [PATCH 11/17] Clarify logging and Stop using deprecated class --- .../mapfish/print/http/ConfigFileResolvingRequest.java | 4 +++- .../mapfish/print/processor/map/NorthArrowGraphic.java | 9 ++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/org/mapfish/print/http/ConfigFileResolvingRequest.java b/core/src/main/java/org/mapfish/print/http/ConfigFileResolvingRequest.java index 903d83ab67..59874de66a 100644 --- a/core/src/main/java/org/mapfish/print/http/ConfigFileResolvingRequest.java +++ b/core/src/main/java/org/mapfish/print/http/ConfigFileResolvingRequest.java @@ -173,7 +173,9 @@ private ClientHttpResponse attemptToFetchResponse( ClientHttpResponse response = executeCallbacksAndRequest(requestUsed); if (response.getRawStatusCode() < 500) { LOGGER.debug( - "Fetching success URI resource {}, error code {}", getURI(), response.getRawStatusCode()); + "Fetching success URI resource {}, status code {}", + getURI(), + response.getRawStatusCode()); return response; } LOGGER.debug( diff --git a/core/src/main/java/org/mapfish/print/processor/map/NorthArrowGraphic.java b/core/src/main/java/org/mapfish/print/processor/map/NorthArrowGraphic.java index 57c52fd12c..147e111327 100644 --- a/core/src/main/java/org/mapfish/print/processor/map/NorthArrowGraphic.java +++ b/core/src/main/java/org/mapfish/print/processor/map/NorthArrowGraphic.java @@ -8,21 +8,22 @@ import java.awt.geom.AffineTransform; import java.awt.image.BufferedImage; import java.io.BufferedInputStream; +import java.io.BufferedWriter; import java.io.File; import java.io.FileInputStream; +import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; -import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import javax.imageio.ImageIO; import org.apache.batik.anim.dom.SAXSVGDocumentFactory; import org.apache.batik.anim.dom.SVGDOMImplementation; import org.apache.batik.dom.util.DOMUtilities; import org.apache.batik.util.SVGConstants; import org.apache.batik.util.XMLResourceDescriptor; -import org.apache.commons.io.output.FileWriterWithEncoding; import org.apache.commons.lang3.StringUtils; import org.mapfish.print.FloatingPointUtil; import org.mapfish.print.ImageUtils; @@ -341,10 +342,8 @@ private static SVGElement parseSvg(final InputStream inputStream) throws IOExcep private static File writeSvgToFile(final Document document, final File workingDir) throws IOException { final File path = File.createTempFile("north-arrow-", ".svg", workingDir); - try (FileWriterWithEncoding fw = - new FileWriterWithEncoding(path, Charset.forName("UTF-8").newEncoder())) { + try (BufferedWriter fw = new BufferedWriter(new FileWriter(path, StandardCharsets.UTF_8))) { DOMUtilities.writeDocument(document, fw); - fw.flush(); } return path; } From 704acc4954f6140843b5d85e1cd5e42ad109e1e8 Mon Sep 17 00:00:00 2001 From: sebr72 Date: Thu, 16 May 2024 17:19:47 +0200 Subject: [PATCH 12/17] Remove obsolete docs config --- .../mapfish-spring-application-context-override.xml | 4 +--- docs/build.gradle | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/core/jettyRunExtraFiles/mapfish-spring-application-context-override.xml b/core/jettyRunExtraFiles/mapfish-spring-application-context-override.xml index 9591459f50..bd2a616c3a 100644 --- a/core/jettyRunExtraFiles/mapfish-spring-application-context-override.xml +++ b/core/jettyRunExtraFiles/mapfish-spring-application-context-override.xml @@ -12,9 +12,7 @@ - - - + diff --git a/docs/build.gradle b/docs/build.gradle index 3ccc8adb93..0b8f2ad75d 100644 --- a/docs/build.gradle +++ b/docs/build.gradle @@ -63,7 +63,6 @@ tasks.register('buildDocs', JavaExec) { def appContext2 = project(':core').webAppDir.toURI().toString() + '/WEB-INF/mapfish-print-servlet.xml' def overrideAppContext = 'classpath*:mapfish-spring-application-context-override.xml' args site, javadocs, basicAppContext, appContext, appContext2, overrideAppContext - systemProperty 'path_to_examples', "${project(':examples').projectDir}/src/test/resources/examples" } build { From d5d565b5d969566d71e5fd382a0d15e5c6a85363 Mon Sep 17 00:00:00 2001 From: sebr72 Date: Thu, 16 May 2024 17:25:43 +0200 Subject: [PATCH 13/17] Fix spelling is filename --- core/Dockerfile | 2 +- ...ish-spring-application-context-override-acceptancetests.xml} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename core/jettyRunExtraFiles/{mapfish-spring-application-context-override-acceptencetests.xml => mapfish-spring-application-context-override-acceptancetests.xml} (100%) diff --git a/core/Dockerfile b/core/Dockerfile index a42ceb430b..35ef31f73c 100644 --- a/core/Dockerfile +++ b/core/Dockerfile @@ -50,7 +50,7 @@ CMD ["/usr/local/tomcat/bin/docker-start-print"] FROM runner AS tester -COPY jettyRunExtraFiles/mapfish-spring-application-context-override-acceptencetests.xml \ +COPY jettyRunExtraFiles/mapfish-spring-application-context-override-acceptancetests.xml \ /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/mapfish-spring-application-context-override.xml FROM runner AS watcher diff --git a/core/jettyRunExtraFiles/mapfish-spring-application-context-override-acceptencetests.xml b/core/jettyRunExtraFiles/mapfish-spring-application-context-override-acceptancetests.xml similarity index 100% rename from core/jettyRunExtraFiles/mapfish-spring-application-context-override-acceptencetests.xml rename to core/jettyRunExtraFiles/mapfish-spring-application-context-override-acceptancetests.xml From 1c79b830538e603390cc0c8a2f5c2ddb402c523f Mon Sep 17 00:00:00 2001 From: sebr72 Date: Thu, 16 May 2024 18:19:49 +0200 Subject: [PATCH 14/17] Remove dead code --- ...fish-spring-application-context-override-acceptancetests.xml | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/jettyRunExtraFiles/mapfish-spring-application-context-override-acceptancetests.xml b/core/jettyRunExtraFiles/mapfish-spring-application-context-override-acceptancetests.xml index 4b33a55f86..6d0465805b 100644 --- a/core/jettyRunExtraFiles/mapfish-spring-application-context-override-acceptancetests.xml +++ b/core/jettyRunExtraFiles/mapfish-spring-application-context-override-acceptancetests.xml @@ -1,12 +1,10 @@ Date: Thu, 16 May 2024 18:45:37 +0200 Subject: [PATCH 15/17] Move spring config to meaningful directories --- core/.dockerignore | 2 +- core/Dockerfile | 2 +- ...fish-spring-application-context-override-acceptancetests.xml | 0 .../docs}/mapfish-spring-application-context-override.xml | 0 docs/build.gradle | 2 +- 5 files changed, 3 insertions(+), 3 deletions(-) rename core/{jettyRunExtraFiles => extraConfigFor/acceptanceTests}/mapfish-spring-application-context-override-acceptancetests.xml (100%) rename core/{jettyRunExtraFiles => extraConfigFor/docs}/mapfish-spring-application-context-override.xml (100%) diff --git a/core/.dockerignore b/core/.dockerignore index 8fc7d95cf8..68f3d70ecd 100644 --- a/core/.dockerignore +++ b/core/.dockerignore @@ -1,3 +1,3 @@ * !docker/ -!jettyRunExtraFiles/ +!extraConfigFor/ diff --git a/core/Dockerfile b/core/Dockerfile index 35ef31f73c..8265ae60f9 100644 --- a/core/Dockerfile +++ b/core/Dockerfile @@ -50,7 +50,7 @@ CMD ["/usr/local/tomcat/bin/docker-start-print"] FROM runner AS tester -COPY jettyRunExtraFiles/mapfish-spring-application-context-override-acceptancetests.xml \ +COPY extraConfigFor/acceptanceTests/mapfish-spring-application-context-override-acceptancetests.xml \ /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/mapfish-spring-application-context-override.xml FROM runner AS watcher diff --git a/core/jettyRunExtraFiles/mapfish-spring-application-context-override-acceptancetests.xml b/core/extraConfigFor/acceptanceTests/mapfish-spring-application-context-override-acceptancetests.xml similarity index 100% rename from core/jettyRunExtraFiles/mapfish-spring-application-context-override-acceptancetests.xml rename to core/extraConfigFor/acceptanceTests/mapfish-spring-application-context-override-acceptancetests.xml diff --git a/core/jettyRunExtraFiles/mapfish-spring-application-context-override.xml b/core/extraConfigFor/docs/mapfish-spring-application-context-override.xml similarity index 100% rename from core/jettyRunExtraFiles/mapfish-spring-application-context-override.xml rename to core/extraConfigFor/docs/mapfish-spring-application-context-override.xml diff --git a/docs/build.gradle b/docs/build.gradle index 0b8f2ad75d..0382e17b6b 100644 --- a/docs/build.gradle +++ b/docs/build.gradle @@ -59,7 +59,7 @@ tasks.register('buildDocs', JavaExec) { def javadocs = project(':core').tasks.javadoc.destinationDir def basicAppContext = 'classpath*:mapfish-spring-application-context.xml' - def appContext = project(':core').projectDir.toURI().toString() + '/jettyRunExtraFiles/*.xml' + def appContext = project(':core').projectDir.toURI().toString() + '/extraConfigFor/docs/*.xml' def appContext2 = project(':core').webAppDir.toURI().toString() + '/WEB-INF/mapfish-print-servlet.xml' def overrideAppContext = 'classpath*:mapfish-spring-application-context-override.xml' args site, javadocs, basicAppContext, appContext, appContext2, overrideAppContext From 7afd71c6489b9759084c4bb4880993a170216a34 Mon Sep 17 00:00:00 2001 From: sebr72 Date: Fri, 17 May 2024 11:34:45 +0200 Subject: [PATCH 16/17] Use correct filename. --- core/Dockerfile | 3 +-- ...sts.xml => mapfish-spring-application-context-override.xml} | 0 2 files changed, 1 insertion(+), 2 deletions(-) rename core/extraConfigFor/acceptanceTests/{mapfish-spring-application-context-override-acceptancetests.xml => mapfish-spring-application-context-override.xml} (100%) diff --git a/core/Dockerfile b/core/Dockerfile index 8265ae60f9..a3e35d2388 100644 --- a/core/Dockerfile +++ b/core/Dockerfile @@ -50,8 +50,7 @@ CMD ["/usr/local/tomcat/bin/docker-start-print"] FROM runner AS tester -COPY extraConfigFor/acceptanceTests/mapfish-spring-application-context-override-acceptancetests.xml \ - /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/mapfish-spring-application-context-override.xml +COPY extraConfigFor/acceptanceTests/mapfish-spring-application-context-override.xml /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/ FROM runner AS watcher diff --git a/core/extraConfigFor/acceptanceTests/mapfish-spring-application-context-override-acceptancetests.xml b/core/extraConfigFor/acceptanceTests/mapfish-spring-application-context-override.xml similarity index 100% rename from core/extraConfigFor/acceptanceTests/mapfish-spring-application-context-override-acceptancetests.xml rename to core/extraConfigFor/acceptanceTests/mapfish-spring-application-context-override.xml From 56b8f9a207ba4655890044e28a3e6c367bbaec0d Mon Sep 17 00:00:00 2001 From: sebr72 Date: Fri, 17 May 2024 12:12:59 +0200 Subject: [PATCH 17/17] Remove deprecated code --- core/build.gradle | 2 +- docs/build.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/build.gradle b/core/build.gradle index 8de1dd2260..44876fe706 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -45,7 +45,7 @@ distributions { } -def appDir = new File(project.buildDir, 'install') +def appDir = new File(getLayout().getBuildDirectory().getAsFile().get(), 'install') installDist.doFirst { appDir.deleteDir() } diff --git a/docs/build.gradle b/docs/build.gradle index 0382e17b6b..7d3349a29f 100644 --- a/docs/build.gradle +++ b/docs/build.gradle @@ -29,7 +29,7 @@ dependencies { ) } -def site = new File(buildDir, "site").path +def site = new File(getLayout().getBuildDirectory().getAsFile().get(), "site").path tasks.register('copyJavadocs', Copy) { dependsOn ':core:javadoc'