diff --git a/build.gradle b/build.gradle index 4bdde369e2..053f9811ac 100644 --- a/build.gradle +++ b/build.gradle @@ -62,7 +62,7 @@ configure(subprojects.findAll { ['core', 'examples'].contains(it.name) }) { tasks.register('violations', ViolationsTask) { minSeverity = 'INFO' detailLevel = 'VERBOSE' // PER_FILE_COMPACT, COMPACT or VERBOSE - maxViolations = 1064 + maxViolations = 1066 printViolations = true violations = [ ["FINDBUGS", ".", ".*/reports/spotbugsReports/.*\\.xml", "Spotbugs"], diff --git a/core/src/main/java/org/mapfish/print/MapPrinter.java b/core/src/main/java/org/mapfish/print/MapPrinter.java index 4d43e94b97..dc59d8e25d 100644 --- a/core/src/main/java/org/mapfish/print/MapPrinter.java +++ b/core/src/main/java/org/mapfish/print/MapPrinter.java @@ -10,6 +10,7 @@ import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; +import javax.annotation.Nonnull; import org.json.JSONException; import org.json.JSONObject; import org.json.JSONWriter; @@ -116,18 +117,26 @@ public final OutputFormat getOutputFormat(final PJsonObject specJson) { /** * Start a print. * - * @param jobId the job ID + * @param mdcContext the MDC context for the current print job. * @param specJson the client json request. * @param out the stream to write to. */ public final Processor.ExecutionContext print( - final String jobId, final PJsonObject specJson, final OutputStream out) throws Exception { + @Nonnull final Map mdcContext, + final PJsonObject specJson, + final OutputStream out) + throws Exception { final OutputFormat format = getOutputFormat(specJson); final File taskDirectory = this.workingDirectories.getTaskDirectory(); try { return format.print( - jobId, specJson, getConfiguration(), this.configFile.getParentFile(), taskDirectory, out); + mdcContext, + specJson, + getConfiguration(), + this.configFile.getParentFile(), + taskDirectory, + out); } finally { this.workingDirectories.removeDirectory(taskDirectory); } diff --git a/core/src/main/java/org/mapfish/print/cli/Main.java b/core/src/main/java/org/mapfish/print/cli/Main.java index 8c8c1cbb32..c12502eac2 100644 --- a/core/src/main/java/org/mapfish/print/cli/Main.java +++ b/core/src/main/java/org/mapfish/print/cli/Main.java @@ -14,6 +14,7 @@ import java.io.OutputStream; import java.io.OutputStreamWriter; import java.net.URL; +import java.util.HashMap; import java.util.List; import org.apache.commons.io.IOUtils; import org.json.JSONWriter; @@ -196,7 +197,7 @@ private void run(final CliDefinition cli) throws Exception { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Request Data: \n{}", jsonSpec.getInternalObj().toString(2)); } - this.mapPrinter.print("main", jsonSpec, outFile); + this.mapPrinter.print(new HashMap(), jsonSpec, outFile); } } } diff --git a/core/src/main/java/org/mapfish/print/http/ConfigFileResolvingHttpRequestFactory.java b/core/src/main/java/org/mapfish/print/http/ConfigFileResolvingHttpRequestFactory.java index d97ff44caa..773eda91a4 100644 --- a/core/src/main/java/org/mapfish/print/http/ConfigFileResolvingHttpRequestFactory.java +++ b/core/src/main/java/org/mapfish/print/http/ConfigFileResolvingHttpRequestFactory.java @@ -7,6 +7,7 @@ import java.net.URI; import java.net.URL; import java.util.List; +import java.util.Map; import java.util.NoSuchElementException; import java.util.concurrent.CopyOnWriteArrayList; import javax.annotation.Nonnull; @@ -35,7 +36,7 @@ public final class ConfigFileResolvingHttpRequestFactory implements MfClientHttp private static final Logger LOGGER = LoggerFactory.getLogger(ConfigFileResolvingHttpRequestFactory.class); private final Configuration config; - private final String jobId; + @Nonnull private final Map mdcContext; private final MfClientHttpRequestFactoryImpl httpRequestFactory; private final List callbacks = new CopyOnWriteArrayList<>(); @@ -44,15 +45,15 @@ public final class ConfigFileResolvingHttpRequestFactory implements MfClientHttp * * @param httpRequestFactory basic request factory * @param config the template for the current print job. - * @param jobId the job ID + * @param mdcContext the mdc context for the current print job. */ public ConfigFileResolvingHttpRequestFactory( final MfClientHttpRequestFactoryImpl httpRequestFactory, final Configuration config, - final String jobId) { + @Nonnull final Map mdcContext) { this.httpRequestFactory = httpRequestFactory; this.config = config; - this.jobId = jobId; + this.mdcContext = mdcContext; } @Override @@ -91,19 +92,30 @@ private synchronized ClientHttpRequest createRequestFromWrapped(final HttpHeader httpRequest.setConfiguration(ConfigFileResolvingHttpRequestFactory.this.config); httpRequest.getHeaders().putAll(headers); - httpRequest - .getHeaders() - .set("X-Request-ID", ConfigFileResolvingHttpRequestFactory.this.jobId); + if (ConfigFileResolvingHttpRequestFactory.this.mdcContext.containsKey( + Processor.MDC_JOB_ID_KEY)) { + String jobId = + ConfigFileResolvingHttpRequestFactory.this.mdcContext.get(Processor.MDC_JOB_ID_KEY); + httpRequest.getHeaders().set("X-Request-ID", jobId); + httpRequest.getHeaders().set("X-Job-ID", jobId); + } + if (ConfigFileResolvingHttpRequestFactory.this.mdcContext.containsKey( + Processor.MDC_APPLICATION_ID_KEY)) { + String applicationId = + ConfigFileResolvingHttpRequestFactory.this.mdcContext.get( + Processor.MDC_APPLICATION_ID_KEY); + httpRequest.getHeaders().set("X-Application-ID", applicationId); + } return httpRequest; } @Override protected synchronized ClientHttpResponse executeInternal(final HttpHeaders headers) throws IOException { - final String prev = MDC.get(Processor.MDC_JOB_ID_KEY); - boolean mdcChanged = prev == null || jobId.equals(prev); + final Map prev = MDC.getCopyOfContextMap(); + boolean mdcChanged = mdcContext.equals(prev); if (mdcChanged) { - MDC.put(Processor.MDC_JOB_ID_KEY, ConfigFileResolvingHttpRequestFactory.this.jobId); + MDC.setContextMap(ConfigFileResolvingHttpRequestFactory.this.mdcContext); } try { if (this.request != null) { @@ -144,11 +156,7 @@ protected synchronized ClientHttpResponse executeInternal(final HttpHeaders head return executeCallbacksAndRequest(createRequestFromWrapped(headers)); } finally { if (mdcChanged) { - if (prev != null) { - MDC.put(Processor.MDC_JOB_ID_KEY, prev); - } else { - MDC.remove(Processor.MDC_JOB_ID_KEY); - } + MDC.setContextMap(prev); } } } diff --git a/core/src/main/java/org/mapfish/print/output/AbstractJasperReportOutputFormat.java b/core/src/main/java/org/mapfish/print/output/AbstractJasperReportOutputFormat.java index dbd4810ebc..5df670ae7b 100644 --- a/core/src/main/java/org/mapfish/print/output/AbstractJasperReportOutputFormat.java +++ b/core/src/main/java/org/mapfish/print/output/AbstractJasperReportOutputFormat.java @@ -81,14 +81,14 @@ protected abstract void doExport(OutputStream outputStream, Print print) @Override public final Processor.ExecutionContext print( - final String jobId, + @Nonnull final Map mdcContext, final PJsonObject requestData, final Configuration config, final File configDir, final File taskDirectory, final OutputStream outputStream) throws Exception { - final Print print = getJasperPrint(jobId, requestData, config, configDir, taskDirectory); + final Print print = getJasperPrint(mdcContext, requestData, config, configDir, taskDirectory); if (Thread.currentThread().isInterrupted()) { throw new CancellationException(); @@ -108,7 +108,7 @@ private JasperFillManager getJasperFillManager( /** * Renders the jasper report. * - * @param jobId the job ID + * @param mdcContext the MDC context for the current print job. * @param requestData the data from the client, required for writing. * @param config the configuration object representing the server side configuration. * @param configDir the directory that contains the configuration, used for resolving resources @@ -119,7 +119,7 @@ private JasperFillManager getJasperFillManager( */ @VisibleForTesting public final Print getJasperPrint( - final String jobId, + @Nonnull final Map mdcContext, final PJsonObject requestData, final Configuration config, final File configDir, @@ -138,7 +138,7 @@ public final Print getJasperPrint( final Values values = new Values( - jobId, + mdcContext, requestData, template, taskDirectory, diff --git a/core/src/main/java/org/mapfish/print/output/MapExportOutputFormat.java b/core/src/main/java/org/mapfish/print/output/MapExportOutputFormat.java index be0582fad0..13029475b0 100644 --- a/core/src/main/java/org/mapfish/print/output/MapExportOutputFormat.java +++ b/core/src/main/java/org/mapfish/print/output/MapExportOutputFormat.java @@ -5,9 +5,11 @@ import java.io.OutputStream; import java.net.URI; import java.net.URISyntaxException; +import java.util.Map; import java.util.concurrent.CancellationException; import java.util.concurrent.ForkJoinPool; import java.util.concurrent.ForkJoinTask; +import javax.annotation.Nonnull; import org.apache.commons.io.IOUtils; import org.mapfish.print.Constants; import org.mapfish.print.config.Configuration; @@ -73,7 +75,7 @@ private String getMapSubReportVariable(final Template template) { @Override public final Processor.ExecutionContext print( - final String jobId, + @Nonnull final Map mdcContext, final PJsonObject spec, final Configuration config, final File configDir, @@ -86,7 +88,13 @@ public final Processor.ExecutionContext print( final Values values = new Values( - jobId, spec, template, taskDirectory, this.httpRequestFactory, null, this.fileSuffix); + mdcContext, + spec, + template, + taskDirectory, + this.httpRequestFactory, + null, + this.fileSuffix); final ProcessorDependencyGraph.ProcessorGraphForkJoinTask task = template.getProcessorGraph().createTask(values); diff --git a/core/src/main/java/org/mapfish/print/output/OutputFormat.java b/core/src/main/java/org/mapfish/print/output/OutputFormat.java index 0b52890b11..7c10c87ac6 100644 --- a/core/src/main/java/org/mapfish/print/output/OutputFormat.java +++ b/core/src/main/java/org/mapfish/print/output/OutputFormat.java @@ -2,6 +2,8 @@ import java.io.File; import java.io.OutputStream; +import java.util.Map; +import javax.annotation.Nonnull; import org.mapfish.print.config.Configuration; import org.mapfish.print.processor.Processor; import org.mapfish.print.wrapper.json.PJsonObject; @@ -21,7 +23,7 @@ public interface OutputFormat { /** * Performs the print and writes to the report in the correct format to the outputStream. * - * @param jobId the job ID + * @param mdcContext the MDC context for the current print job. * @param spec the data from the client, required for writing. * @param config the configuration object representing the server side configuration. * @param configDir the directory that contains the configuration, used for resolving resources @@ -30,7 +32,7 @@ public interface OutputFormat { * @param outputStream the stream to write the result to */ Processor.ExecutionContext print( - String jobId, + @Nonnull Map mdcContext, PJsonObject spec, Configuration config, File configDir, diff --git a/core/src/main/java/org/mapfish/print/output/Values.java b/core/src/main/java/org/mapfish/print/output/Values.java index 88451c9661..2938300670 100644 --- a/core/src/main/java/org/mapfish/print/output/Values.java +++ b/core/src/main/java/org/mapfish/print/output/Values.java @@ -51,8 +51,8 @@ public final class Values { /** The key for the values object for the subreport directory. */ public static final String SUBREPORT_DIR_KEY = "SUBREPORT_DIR"; - /** The key for the reference ID. */ - public static final String JOB_ID_KEY = "jobId"; + /** The key for the MDC context of the current print job. */ + public static final String MDC_CONTEXT_KEY = "mdcContext"; /** The key for the values object of it self. */ public static final String VALUES_KEY = "values"; @@ -79,7 +79,7 @@ public Values() { /** * Construct from the json request body and the associated template. * - * @param jobId the job ID + * @param mdcContext the MDC context * @param requestData the json request data * @param template the template * @param taskDirectory the temporary directory for this printing task. @@ -87,20 +87,26 @@ public Values() { * @param jasperTemplateBuild the directory where the jasper templates are compiled to */ public Values( - final String jobId, + @Nonnull final Map mdcContext, final PJsonObject requestData, final Template template, final File taskDirectory, final MfClientHttpRequestFactoryImpl httpRequestFactory, final File jasperTemplateBuild) { this( - jobId, requestData, template, taskDirectory, httpRequestFactory, jasperTemplateBuild, null); + mdcContext, + requestData, + template, + taskDirectory, + httpRequestFactory, + jasperTemplateBuild, + null); } /** * Construct from the json request body and the associated template. * - * @param jobId the job ID + * @param mdcContext the MDC context * @param requestData the json request data * @param template the template * @param taskDirectory the temporary directory for this printing task. @@ -110,7 +116,7 @@ public Values( */ // CHECKSTYLE:OFF public Values( - final String jobId, + @Nonnull final Map mdcContext, final PJsonObject requestData, final Template template, final File taskDirectory, @@ -126,7 +132,7 @@ public Values( CLIENT_HTTP_REQUEST_FACTORY_KEY, new MfClientHttpRequestFactoryProvider( new ConfigFileResolvingHttpRequestFactory( - httpRequestFactory, template.getConfiguration(), jobId))); + httpRequestFactory, template.getConfiguration(), mdcContext))); this.values.put(TEMPLATE_KEY, template); this.values.put(PDF_CONFIG_KEY, template.getPdfConfig()); if (jasperTemplateBuild != null) { @@ -141,7 +147,7 @@ public Values( Map attributes = new HashMap<>(template.getAttributes()); populateFromAttributes(template, attributes, jsonAttributes); - this.values.put(JOB_ID_KEY, jobId); + this.values.put(MDC_CONTEXT_KEY, mdcContext); this.values.put(VALUES_KEY, this); @@ -263,7 +269,7 @@ public void addRequiredValues(@Nonnull final Values sourceValues) { this.values.put(PDF_CONFIG_KEY, pdfConfig); this.values.put(SUBREPORT_DIR_KEY, subReportDir); this.values.put(VALUES_KEY, this); - this.values.put(JOB_ID_KEY, sourceValues.getString(JOB_ID_KEY)); + this.values.put(MDC_CONTEXT_KEY, sourceValues.getStringMap(MDC_CONTEXT_KEY)); this.values.put(LOCALE_KEY, sourceValues.getObject(LOCALE_KEY, Locale.class)); } @@ -319,7 +325,7 @@ public Integer getInteger(final String key) { } /** - * Get a value as a string. + * Get a value as a object. * * @param key the key for looking up the value. * @param type the type of the object @@ -330,6 +336,14 @@ public V getObject(final String key, final Class type) { return type.cast(obj); } + /** + * Get a value as a Map from String to String. + * + * @param key the key for looking up the value. + */ + public Map getStringMap(final String key) { + return (Map) this.values.get(key); + } /** * Return true if the identified value is present in this values. * 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 23187c59d7..5a673a058e 100644 --- a/core/src/main/java/org/mapfish/print/processor/AbstractProcessor.java +++ b/core/src/main/java/org/mapfish/print/processor/AbstractProcessor.java @@ -207,15 +207,15 @@ public String toString() { /** Default implementation of {@link org.mapfish.print.processor.Processor.ExecutionContext}. */ public static final class Context implements ExecutionContext { - private final String jobId; + @Nonnull private final Map mdcContext; private volatile boolean canceled = false; private ExecutionStats stats = new ExecutionStats(); /** - * @param jobId The job ID. + * @param mdcContext The MDC context. */ - public Context(final String jobId) { - this.jobId = jobId; + public Context(@Nonnull final Map mdcContext) { + this.mdcContext = mdcContext; } /** Sets the canceled flag. */ @@ -236,27 +236,25 @@ public ExecutionStats getStats() { } @Override - public String getJobId() { - return this.jobId; + public Map getMDCContext() { + return this.mdcContext; } @Override public T mdcContext(final Supplier action) { this.stopIfCanceled(); - final String prev = MDC.get(MDC_JOB_ID_KEY); - boolean changed = prev == null || (jobId != null && jobId.equals(prev)); + final Map prev = MDC.getCopyOfContextMap(); + final String prevJomId = MDC.get(MDC_JOB_ID_KEY); + final String jobId = this.mdcContext == null ? null : this.mdcContext.get(MDC_JOB_ID_KEY); + boolean changed = prevJomId == null || (jobId != null && jobId.equals(prevJomId)); if (changed) { - MDC.put(MDC_JOB_ID_KEY, this.jobId); + MDC.setContextMap(this.mdcContext); } try { return action.get(); } finally { if (changed) { - if (prev != null) { - MDC.put(MDC_JOB_ID_KEY, prev); - } else { - MDC.remove(MDC_JOB_ID_KEY); - } + MDC.setContextMap(prev); } } } @@ -264,20 +262,16 @@ public T mdcContext(final Supplier action) { @Override public T mdcContextEx(final Callable action) throws Exception { this.stopIfCanceled(); - final String prev = MDC.get(MDC_JOB_ID_KEY); - boolean mdcChanged = prev == null || jobId.equals(prev); + final Map prev = MDC.getCopyOfContextMap(); + boolean mdcChanged = !mdcContext.equals(prev); if (mdcChanged) { - MDC.put(MDC_JOB_ID_KEY, this.jobId); + MDC.setContextMap(this.mdcContext); } try { return action.call(); } finally { if (mdcChanged) { - if (prev != null) { - MDC.put(MDC_JOB_ID_KEY, prev); - } else { - MDC.remove(MDC_JOB_ID_KEY); - } + MDC.setContextMap(prev); } } } diff --git a/core/src/main/java/org/mapfish/print/processor/Processor.java b/core/src/main/java/org/mapfish/print/processor/Processor.java index 36aa2298e2..f345b71f3e 100644 --- a/core/src/main/java/org/mapfish/print/processor/Processor.java +++ b/core/src/main/java/org/mapfish/print/processor/Processor.java @@ -1,6 +1,7 @@ package org.mapfish.print.processor; import com.google.common.collect.BiMap; +import java.util.Map; import java.util.concurrent.Callable; import java.util.function.Supplier; import javax.annotation.Nullable; @@ -19,6 +20,8 @@ * the {@link org.mapfish.print.output.Values} object so other processor can access the values. */ public interface Processor extends ConfigurationObject { + /** MDC key for the application ID. */ + String MDC_APPLICATION_ID_KEY = "application_id"; /** MDC key for the job ID. */ String MDC_JOB_ID_KEY = "job_id"; @@ -141,9 +144,9 @@ interface ExecutionContext { ExecutionStats getStats(); /** - * @return The job ID + * @return The MDC context for the current print job. */ - String getJobId(); + Map getMDCContext(); /** * Set the MDC context while running the action. diff --git a/core/src/main/java/org/mapfish/print/processor/ProcessorDependencyGraphFactory.java b/core/src/main/java/org/mapfish/print/processor/ProcessorDependencyGraphFactory.java index bf8fdf1c1e..2b5b8f3a09 100644 --- a/core/src/main/java/org/mapfish/print/processor/ProcessorDependencyGraphFactory.java +++ b/core/src/main/java/org/mapfish/print/processor/ProcessorDependencyGraphFactory.java @@ -191,7 +191,7 @@ public ProcessorDependencyGraph build( outputTypes.put(Values.PDF_CONFIG_KEY, PDFConfig.class); outputTypes.put(Values.SUBREPORT_DIR_KEY, String.class); outputTypes.put(Values.OUTPUT_FORMAT_KEY, String.class); - outputTypes.put(Values.JOB_ID_KEY, String.class); + outputTypes.put(Values.MDC_CONTEXT_KEY, Map.class); outputTypes.put( MapPrinterServlet.JSON_REQUEST_HEADERS, HttpRequestHeadersAttribute.Value.class); outputTypes.put(Values.LOCALE_KEY, Locale.class); diff --git a/core/src/main/java/org/mapfish/print/processor/ProcessorExecutionContext.java b/core/src/main/java/org/mapfish/print/processor/ProcessorExecutionContext.java index 27d102306a..11fa4dd2af 100644 --- a/core/src/main/java/org/mapfish/print/processor/ProcessorExecutionContext.java +++ b/core/src/main/java/org/mapfish/print/processor/ProcessorExecutionContext.java @@ -1,6 +1,7 @@ package org.mapfish.print.processor; import java.util.IdentityHashMap; +import java.util.Map; import java.util.Set; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; @@ -22,7 +23,7 @@ public final class ProcessorExecutionContext { */ public ProcessorExecutionContext(final Values values) { this.values = values; - this.context = new Context(values.getString(Values.JOB_ID_KEY)); + this.context = new Context(values.getStringMap(Values.MDC_CONTEXT_KEY)); } public Values getValues() { @@ -151,7 +152,7 @@ public Context getContext() { return this.context; } - public String getJobId() { - return this.context.getJobId(); + public Map getMDCContext() { + return this.context.getMDCContext(); } } diff --git a/core/src/main/java/org/mapfish/print/processor/ProcessorUtils.java b/core/src/main/java/org/mapfish/print/processor/ProcessorUtils.java index 937f2eaebb..f39cb8acb6 100644 --- a/core/src/main/java/org/mapfish/print/processor/ProcessorUtils.java +++ b/core/src/main/java/org/mapfish/print/processor/ProcessorUtils.java @@ -122,7 +122,7 @@ public static String getInputValueName( Values.PDF_CONFIG_KEY, Values.SUBREPORT_DIR_KEY, Values.OUTPUT_FORMAT_KEY, - Values.JOB_ID_KEY + Values.MDC_CONTEXT_KEY, }; if (inputPrefix == null || Arrays.asList(defaultValues).contains(field)) { name = field; diff --git a/core/src/main/java/org/mapfish/print/processor/jasper/DataSourceProcessor.java b/core/src/main/java/org/mapfish/print/processor/jasper/DataSourceProcessor.java index 27b44d3b19..392734dbb5 100644 --- a/core/src/main/java/org/mapfish/print/processor/jasper/DataSourceProcessor.java +++ b/core/src/main/java/org/mapfish/print/processor/jasper/DataSourceProcessor.java @@ -167,7 +167,7 @@ public Collection getDependencies() { result.add(Values.PDF_CONFIG_KEY); result.add(Values.SUBREPORT_DIR_KEY); result.add(Values.VALUES_KEY); - result.add(Values.JOB_ID_KEY); + result.add(Values.MDC_CONTEXT_KEY); return result; } 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 cebdccc53f..58ec119adb 100644 --- a/core/src/main/java/org/mapfish/print/servlet/MapPrinterServlet.java +++ b/core/src/main/java/org/mapfish/print/servlet/MapPrinterServlet.java @@ -27,6 +27,7 @@ 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; import javax.servlet.http.HttpServletResponse; @@ -107,7 +108,7 @@ public class MapPrinterServlet extends BaseMapServlet { /** * If the job is done (value is true) or not (value is false). * - *

Part of the {@link #getStatus(String, javax.servlet.http.HttpServletRequest, + *

Part of the {@link #getStatus(String, String, javax.servlet.http.HttpServletRequest, * javax.servlet.http.HttpServletResponse)} response. */ public static final String JSON_DONE = "done"; @@ -123,7 +124,7 @@ public class MapPrinterServlet extends BaseMapServlet { *

  • error * * - * Part of the {@link #getStatus(String, javax.servlet.http.HttpServletRequest, + * Part of the {@link #getStatus(String, String, javax.servlet.http.HttpServletRequest, * javax.servlet.http.HttpServletResponse)} response */ public static final String JSON_STATUS = "status"; @@ -132,7 +133,7 @@ public class MapPrinterServlet extends BaseMapServlet { * The elapsed time in ms from the point the job started. If the job is finished, this is the * duration it took to process the job. * - *

    Part of the {@link #getStatus(String, javax.servlet.http.HttpServletRequest, + *

    Part of the {@link #getStatus(String, String, javax.servlet.http.HttpServletRequest, * javax.servlet.http.HttpServletResponse)} response. */ public static final String JSON_ELAPSED_TIME = "elapsedTime"; @@ -141,7 +142,7 @@ public class MapPrinterServlet extends BaseMapServlet { * A rough estimate for the time in ms the job still has to wait in the queue until it starts * processing. * - *

    Part of the {@link #getStatus(String, javax.servlet.http.HttpServletRequest, + *

    Part of the {@link #getStatus(String, String, javax.servlet.http.HttpServletRequest, * javax.servlet.http.HttpServletResponse)} response. */ public static final String JSON_WAITING_TIME = "waitingTime"; @@ -344,11 +345,11 @@ private static String maybeAddRequestId(final String ref, final HttpServletReque value = "/{appId}" + STATUS_URL + "/{referenceId:\\S+}.json", method = RequestMethod.GET) public final void getStatusSpecificAppId( - @SuppressWarnings("unused") @PathVariable final String appId, - @PathVariable final String referenceId, + @Nonnull @PathVariable final String appId, + @Nonnull @PathVariable final String referenceId, final HttpServletRequest statusRequest, final HttpServletResponse statusResponse) { - getStatus(referenceId, statusRequest, statusResponse); + getStatus(appId, referenceId, statusRequest, statusResponse); } /** @@ -363,10 +364,31 @@ public final void getStatusSpecificAppId( * @param statusResponse the response object */ @RequestMapping(value = STATUS_URL + "/{referenceId:\\S+}.json", method = RequestMethod.GET) + public final void getStatusPath( + @Nonnull @PathVariable final String referenceId, + final HttpServletRequest statusRequest, + final HttpServletResponse statusResponse) { + getStatus("default", referenceId, statusRequest, statusResponse); + } + + /** + * Get a status report on a job. Returns the following json: + * + *

    
    +   *  {"time":0,"count":0,"done":false}
    +   * 
    + * + * @param applicationId the application ID + * @param referenceId the job reference + * @param statusRequest the request object + * @param statusResponse the response object + */ public final void getStatus( - @PathVariable final String referenceId, + @Nonnull final String applicationId, + @Nonnull final String referenceId, final HttpServletRequest statusRequest, final HttpServletResponse statusResponse) { + MDC.put(Processor.MDC_APPLICATION_ID_KEY, applicationId); MDC.put(Processor.MDC_JOB_ID_KEY, referenceId); setNoCache(statusResponse); try { @@ -410,10 +432,10 @@ public final void getStatus( value = "/{appId}" + CANCEL_URL + "/{referenceId:\\S+}", method = RequestMethod.DELETE) public final void cancelSpecificAppId( - @SuppressWarnings("unused") @PathVariable final String appId, - @PathVariable final String referenceId, + @Nonnull @PathVariable final String appId, + @Nonnull @PathVariable final String referenceId, final HttpServletResponse statusResponse) { - cancel(referenceId, statusResponse); + cancel(appId, referenceId, statusResponse); } /** @@ -426,8 +448,26 @@ public final void cancelSpecificAppId( * @param statusResponse the response object */ @RequestMapping(value = CANCEL_URL + "/{referenceId:\\S+}", method = RequestMethod.DELETE) + public final void cancelPath( + @Nonnull @PathVariable final String referenceId, final HttpServletResponse statusResponse) { + cancel("default", referenceId, statusResponse); + } + + /** + * Cancel a job. + * + *

    Even if a job was already finished, subsequent status requests will return that the job was + * canceled. + * + * @param applicationId the application ID + * @param referenceId the job reference + * @param statusResponse the response object + */ public final void cancel( - @PathVariable final String referenceId, final HttpServletResponse statusResponse) { + @Nonnull final String applicationId, + @Nonnull final String referenceId, + final HttpServletResponse statusResponse) { + MDC.put(Processor.MDC_APPLICATION_ID_KEY, applicationId); MDC.put(Processor.MDC_JOB_ID_KEY, referenceId); setNoCache(statusResponse); try { @@ -449,7 +489,7 @@ public final void cancel( */ @RequestMapping(value = "/{appId}" + REPORT_URL + ".{format:\\w+}", method = RequestMethod.POST) public final void createReport( - @PathVariable final String appId, + @Nonnull @PathVariable final String appId, @PathVariable final String format, @RequestBody final String requestData, final HttpServletRequest createReportRequest, @@ -492,27 +532,45 @@ public final void createReport( value = "/{appId}" + REPORT_URL + "/{referenceId:\\S+}", method = RequestMethod.GET) public final void getReportSpecificAppId( - @SuppressWarnings("unused") @PathVariable final String appId, - @PathVariable final String referenceId, + @Nonnull @PathVariable final String appId, + @Nonnull @PathVariable final String referenceId, @RequestParam(value = "inline", defaultValue = "false") final boolean inline, final HttpServletResponse getReportResponse) throws IOException, ServletException { - getReport(referenceId, inline, getReportResponse); + getReport(appId, referenceId, inline, getReportResponse); } /** * To get the PDF created previously. * - * @param referenceId the path to the file. + * @param referenceId the job reference * @param inline whether or not to inline the * @param getReportResponse the response object */ @RequestMapping(value = REPORT_URL + "/{referenceId:\\S+}", method = RequestMethod.GET) - public final void getReport( - @PathVariable final String referenceId, + public final void getReportPath( + @Nonnull @PathVariable final String referenceId, @RequestParam(value = "inline", defaultValue = "false") final boolean inline, final HttpServletResponse getReportResponse) throws IOException, ServletException { + getReport("default", referenceId, inline, getReportResponse); + } + + /** + * To get the PDF created previously. + * + * @param applicationId the application ID + * @param referenceId the job reference + * @param inline whether or not to inline the + * @param getReportResponse the response object + */ + public final void getReport( + @Nonnull final String applicationId, + @Nonnull final String referenceId, + final boolean inline, + final HttpServletResponse getReportResponse) + throws IOException, ServletException { + MDC.put(Processor.MDC_APPLICATION_ID_KEY, applicationId); MDC.put(Processor.MDC_JOB_ID_KEY, referenceId); setNoCache(getReportResponse); loadReport( @@ -592,6 +650,9 @@ public final void createReport( return; } final String appId = spec.optString(JSON_APP, DEFAULT_CONFIGURATION_FILE_KEY); + if (appId == null) { + throw new NoSuchAppException("No app specified"); + } createReport(appId, format, requestData, createReportRequest, createReportResponse); } @@ -610,7 +671,7 @@ public final void createReport( value = "/{appId}" + CREATE_AND_GET_URL + ".{format:\\w+}", method = RequestMethod.POST) public final void createReportAndGet( - @PathVariable final String appId, + @Nonnull @PathVariable final String appId, @PathVariable final String format, @RequestBody final String requestData, @RequestParam(value = "inline", defaultValue = "false") final boolean inline, @@ -709,6 +770,9 @@ public final void createReportAndGetNoAppId( return; } String appId = spec.optString(JSON_APP, DEFAULT_CONFIGURATION_FILE_KEY); + if (appId == null) { + throw new NoSuchAppException("No app specified"); + } createReportAndGet( appId, format, requestData, inline, createReportRequest, createReportResponse); } @@ -721,6 +785,7 @@ public final void createReportAndGetNoAppId( @RequestMapping(value = LIST_APPS_URL, method = RequestMethod.GET) public final void listAppIds(final HttpServletResponse listAppsResponse) throws ServletException, IOException { + MDC.remove(Processor.MDC_APPLICATION_ID_KEY); MDC.remove(Processor.MDC_JOB_ID_KEY); setCache(listAppsResponse); Set appIds = this.printerFactory.getAppIds(); @@ -767,11 +832,12 @@ public final void getCapabilities( */ @RequestMapping(value = "/{appId}" + CAPABILITIES_URL, method = RequestMethod.GET) public final void getCapabilities( - @PathVariable final String appId, + @Nonnull @PathVariable final String appId, @RequestParam(value = "pretty", defaultValue = "false") final boolean pretty, final HttpServletRequest request, final HttpServletResponse capabilitiesResponse) throws ServletException, IOException { + MDC.remove(Processor.MDC_APPLICATION_ID_KEY); MDC.remove(Processor.MDC_JOB_ID_KEY); setCache(capabilitiesResponse); MapPrinter printer; @@ -847,10 +913,11 @@ public final void getExampleRequest( */ @RequestMapping(value = "{appId}" + EXAMPLE_REQUEST_URL, method = RequestMethod.GET) public final void getExampleRequest( - @PathVariable final String appId, + @Nonnull @PathVariable final String appId, final HttpServletRequest request, final HttpServletResponse getExampleResponse) throws IOException { + MDC.remove(Processor.MDC_APPLICATION_ID_KEY); MDC.remove(Processor.MDC_JOB_ID_KEY); setCache(getExampleResponse); try { @@ -937,6 +1004,7 @@ public final void getExampleRequest( */ @RequestMapping(value = FONTS_URL) public final void listAvailableFonts(final HttpServletResponse response) { + MDC.remove(Processor.MDC_APPLICATION_ID_KEY); MDC.remove(Processor.MDC_JOB_ID_KEY); setContentType(response); @@ -1082,7 +1150,7 @@ protected final JSONObject getHeaders(final HttpServletRequest httpServletReques * @return the job reference id */ private String createAndSubmitPrintJob( - final String appId, + @Nonnull final String appId, final String format, final String requestDataRaw, final HttpServletRequest httpServletRequest, @@ -1097,6 +1165,7 @@ private String createAndSubmitPrintJob( maybeAddRequestId( UUID.randomUUID().toString() + "@" + this.servletInfo.getServletId(), httpServletRequest); + MDC.put(Processor.MDC_APPLICATION_ID_KEY, appId); MDC.put(Processor.MDC_JOB_ID_KEY, ref); LOGGER.debug("{}", specJson); diff --git a/core/src/main/java/org/mapfish/print/servlet/ServletMapPrinterFactory.java b/core/src/main/java/org/mapfish/print/servlet/ServletMapPrinterFactory.java index 931a144ffc..4970a80eee 100644 --- a/core/src/main/java/org/mapfish/print/servlet/ServletMapPrinterFactory.java +++ b/core/src/main/java/org/mapfish/print/servlet/ServletMapPrinterFactory.java @@ -36,7 +36,7 @@ public class ServletMapPrinterFactory implements MapPrinterFactory { /** * The name of the default app. This is always required to be one of the apps that are registered. */ - public static final String DEFAULT_CONFIGURATION_FILE_KEY = "default"; + @Nonnull public static final String DEFAULT_CONFIGURATION_FILE_KEY = "default"; private static final String CONFIG_YAML = "config.yaml"; private static final Logger LOGGER = LoggerFactory.getLogger(ServletMapPrinterFactory.class); @@ -59,10 +59,8 @@ private void validateConfigurationFiles() { @Override public final synchronized MapPrinter create(@Nullable final String app) throws NoSuchAppException { - String finalApp = app; - if (app == null) { - finalApp = DEFAULT_CONFIGURATION_FILE_KEY; - } + @Nonnull String finalApp = app == null ? DEFAULT_CONFIGURATION_FILE_KEY : app; + URI configFile = this.configurationFiles.get(finalApp); if (configFile == null) { diff --git a/core/src/main/java/org/mapfish/print/servlet/job/PrintJob.java b/core/src/main/java/org/mapfish/print/servlet/job/PrintJob.java index da3e20734a..5a7e6105cc 100644 --- a/core/src/main/java/org/mapfish/print/servlet/job/PrintJob.java +++ b/core/src/main/java/org/mapfish/print/servlet/job/PrintJob.java @@ -9,6 +9,7 @@ import java.io.OutputStream; import java.net.URISyntaxException; import java.net.URL; +import java.util.Map; import java.util.Properties; import java.util.Set; import java.util.concurrent.Callable; @@ -127,8 +128,12 @@ protected abstract PrintJobResult createResult( public final PrintJobResult call() throws Exception { SecurityContextHolder.setContext(this.securityContext); final Timer.Context timer = this.metricRegistry.timer(getClass().getName() + ".call").time(); + MDC.put(Processor.MDC_APPLICATION_ID_KEY, this.entry.getAppId()); MDC.put(Processor.MDC_JOB_ID_KEY, this.entry.getReferenceId()); - LOGGER.info("Starting print job {}", this.entry.getReferenceId()); + LOGGER.info( + "Starting print application {}, job {}", + this.entry.getAppId(), + this.entry.getReferenceId()); final MapPrinter mapPrinter = PrintJob.this.mapPrinterFactory.create(this.entry.getAppId()); final Accounting.JobTracker jobTracker = this.accounting.startJob(this.entry, mapPrinter.getConfiguration()); @@ -137,7 +142,14 @@ public final PrintJobResult call() throws Exception { final PrintResult report = withOpenOutputStream( outputStream -> - mapPrinter.print(entry.getReferenceId(), entry.getRequestData(), outputStream)); + mapPrinter.print( + Map.of( + Processor.MDC_APPLICATION_ID_KEY, + this.entry.getAppId(), + Processor.MDC_JOB_ID_KEY, + this.entry.getReferenceId()), + entry.getRequestData(), + outputStream)); this.metricRegistry.counter(getClass().getName() + ".success").inc(); LOGGER.info("Successfully completed print job {}", this.entry.getReferenceId()); @@ -187,6 +199,7 @@ public final PrintJobResult call() throws Exception { LOGGER.debug( "Print Job {} completed in {}ms", this.entry.getReferenceId(), computationTimeMs); MDC.remove(Processor.MDC_JOB_ID_KEY); + MDC.remove(Processor.MDC_APPLICATION_ID_KEY); } } diff --git a/core/src/test/java/org/mapfish/print/AbstractMapfishSpringTest.java b/core/src/test/java/org/mapfish/print/AbstractMapfishSpringTest.java index 2f220a0216..c71b48eed3 100644 --- a/core/src/test/java/org/mapfish/print/AbstractMapfishSpringTest.java +++ b/core/src/test/java/org/mapfish/print/AbstractMapfishSpringTest.java @@ -6,6 +6,7 @@ import java.net.URI; import java.net.URL; import java.nio.file.Files; +import java.util.HashMap; import java.util.Optional; import java.util.function.Function; import java.util.regex.Matcher; @@ -43,7 +44,8 @@ public abstract class AbstractMapfishSpringTest { public static final String TEST_SPRING_FONT_XML = "classpath:test-mapfish-spring-custom-fonts.xml"; public static final String TMP = System.getProperty("java.io.tmpdir"); - protected static final Processor.ExecutionContext CONTEXT = new AbstractProcessor.Context("test"); + protected static final Processor.ExecutionContext CONTEXT = + new AbstractProcessor.Context(new HashMap()); static final Pattern IMPORT_PATTERN = Pattern.compile("@@importFile\\((\\S+)\\)@@"); @Autowired private WorkingDirectories workingDirectories; diff --git a/core/src/test/java/org/mapfish/print/attribute/BooleanAttributeTest.java b/core/src/test/java/org/mapfish/print/attribute/BooleanAttributeTest.java index 60b4158e98..ac5667e109 100644 --- a/core/src/test/java/org/mapfish/print/attribute/BooleanAttributeTest.java +++ b/core/src/test/java/org/mapfish/print/attribute/BooleanAttributeTest.java @@ -4,6 +4,7 @@ import static org.junit.Assert.assertTrue; import java.io.IOException; +import java.util.HashMap; import org.json.JSONObject; import org.junit.Test; import org.mapfish.print.AbstractMapfishSpringTest; @@ -30,7 +31,7 @@ public void testParsableByValues() throws Exception { Template template = config.getTemplate("main"); Values values = new Values( - "test", + new HashMap(), requestData, template, config.getDirectory(), diff --git a/core/src/test/java/org/mapfish/print/attribute/JsonDatasourceAttributeTest.java b/core/src/test/java/org/mapfish/print/attribute/JsonDatasourceAttributeTest.java index ee38198447..e0d33d8078 100644 --- a/core/src/test/java/org/mapfish/print/attribute/JsonDatasourceAttributeTest.java +++ b/core/src/test/java/org/mapfish/print/attribute/JsonDatasourceAttributeTest.java @@ -4,6 +4,7 @@ import static org.junit.Assert.assertNotNull; import java.io.IOException; +import java.util.HashMap; import net.sf.jasperreports.engine.JRException; import net.sf.jasperreports.engine.data.JsonDataSource; import net.sf.jasperreports.engine.design.JRDesignField; @@ -43,7 +44,7 @@ public void testParsableByValues() throws Exception { Template template = config.getTemplate("main"); Values values = new Values( - "test", + new HashMap(), requestData, template, config.getDirectory(), diff --git a/core/src/test/java/org/mapfish/print/attribute/ScalebarAttributeTest.java b/core/src/test/java/org/mapfish/print/attribute/ScalebarAttributeTest.java index ffde720f32..bf5e4ab85f 100644 --- a/core/src/test/java/org/mapfish/print/attribute/ScalebarAttributeTest.java +++ b/core/src/test/java/org/mapfish/print/attribute/ScalebarAttributeTest.java @@ -6,6 +6,7 @@ import java.awt.Dimension; import java.io.File; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import org.junit.Test; import org.mapfish.print.AbstractMapfishSpringTest; @@ -80,7 +81,7 @@ public void testAttributesFromJson() throws Exception { parseJSONObjectFromFile(ScalebarAttributeTest.class, "scalebar/requestData.json"); final Values values = new Values( - "test", + new HashMap(), pJsonObject, template, getTaskDirectory(), diff --git a/core/src/test/java/org/mapfish/print/attribute/StringArrayAttributeTest.java b/core/src/test/java/org/mapfish/print/attribute/StringArrayAttributeTest.java index 6af001d2cd..e5fd3eb083 100644 --- a/core/src/test/java/org/mapfish/print/attribute/StringArrayAttributeTest.java +++ b/core/src/test/java/org/mapfish/print/attribute/StringArrayAttributeTest.java @@ -3,6 +3,7 @@ import static org.junit.Assert.assertArrayEquals; import java.io.IOException; +import java.util.HashMap; import org.json.simple.JSONArray; import org.junit.Test; import org.mapfish.print.AbstractMapfishSpringTest; @@ -29,7 +30,7 @@ public void testParsableByValues() throws Exception { Template template = config.getTemplate("main"); Values values = new Values( - "test", + new HashMap(), requestData, template, config.getDirectory(), @@ -56,7 +57,7 @@ public void testWrongType() throws Exception { Template template = config.getTemplate("main"); Values values = new Values( - "test", + new HashMap(), requestData, template, config.getDirectory(), diff --git a/core/src/test/java/org/mapfish/print/attribute/StringAttributeTest.java b/core/src/test/java/org/mapfish/print/attribute/StringAttributeTest.java index 35e6bdf936..a4dc65535c 100644 --- a/core/src/test/java/org/mapfish/print/attribute/StringAttributeTest.java +++ b/core/src/test/java/org/mapfish/print/attribute/StringAttributeTest.java @@ -3,6 +3,7 @@ import static org.junit.Assert.assertEquals; import java.io.IOException; +import java.util.HashMap; import org.junit.Test; import org.mapfish.print.AbstractMapfishSpringTest; import org.mapfish.print.TestHttpClientFactory; @@ -28,7 +29,7 @@ public void testParsableByValues() throws Exception { Template template = config.getTemplate("main"); Values values = new Values( - "test", + new HashMap(), requestData, template, config.getDirectory(), @@ -46,7 +47,7 @@ public void testParsableByValuesError() throws Exception { Template template = config.getTemplate("main"); new Values( - "test", + new HashMap(), requestData, template, config.getDirectory(), diff --git a/core/src/test/java/org/mapfish/print/attribute/StyleAttributeTest.java b/core/src/test/java/org/mapfish/print/attribute/StyleAttributeTest.java index 20ee71ca14..1288c38773 100644 --- a/core/src/test/java/org/mapfish/print/attribute/StyleAttributeTest.java +++ b/core/src/test/java/org/mapfish/print/attribute/StyleAttributeTest.java @@ -3,6 +3,7 @@ import static org.junit.Assert.assertNotNull; import java.io.File; +import java.util.HashMap; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; @@ -30,7 +31,7 @@ public void testAttributesFromJson() throws Exception { parseJSONObjectFromFile(StyleAttributeTest.class, "style_attributes/request.json"); final Values values = new Values( - "test", + new HashMap(), pJsonObject, template, this.folder.getRoot(), diff --git a/core/src/test/java/org/mapfish/print/attribute/map/MapAttributeTest.java b/core/src/test/java/org/mapfish/print/attribute/map/MapAttributeTest.java index eb2736f35a..5a0da8fdd8 100644 --- a/core/src/test/java/org/mapfish/print/attribute/map/MapAttributeTest.java +++ b/core/src/test/java/org/mapfish/print/attribute/map/MapAttributeTest.java @@ -11,6 +11,7 @@ import java.io.File; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import org.geotools.referencing.CRS; import org.json.JSONObject; @@ -83,7 +84,7 @@ public void testAttributesFromJson() throws Exception { parseJSONObjectFromFile(MapAttributeTest.class, "map_attributes/requestData-json.json"); final Values values = new Values( - "test", + new HashMap(), pJsonObject, template, getTaskDirectory(), @@ -110,7 +111,7 @@ public void testAttributesFromYaml() throws Exception { parseJSONObjectFromFile(MapAttributeTest.class, "map_attributes/requestData-yaml.json"); final Values values = new Values( - "test", + new HashMap(), pJsonObject, template, getTaskDirectory(), @@ -138,7 +139,7 @@ public void testAttributesFromBoth() throws Exception { parseJSONObjectFromFile(MapAttributeTest.class, "map_attributes/requestData-json.json"); final Values values = new Values( - "test", + new HashMap(), pJsonObject, template, getTaskDirectory(), @@ -166,7 +167,7 @@ public void testZoomToFeatures() throws Exception { parseJSONObjectFromFile(MapAttributeTest.class, "map_attributes/requestData-zoomTo.json"); final Values values = new Values( - "test", + new HashMap(), pJsonObject, template, getTaskDirectory(), @@ -189,7 +190,7 @@ public void testZoomToFeaturesCenter() throws Exception { MapAttributeTest.class, "map_attributes/requestData-zoomToCenter" + ".json"); final Values values = new Values( - "test", + new HashMap(), pJsonObject, template, getTaskDirectory(), diff --git a/core/src/test/java/org/mapfish/print/attribute/map/OverviewMapAttributeTest.java b/core/src/test/java/org/mapfish/print/attribute/map/OverviewMapAttributeTest.java index 5774b41f06..5056796dbc 100644 --- a/core/src/test/java/org/mapfish/print/attribute/map/OverviewMapAttributeTest.java +++ b/core/src/test/java/org/mapfish/print/attribute/map/OverviewMapAttributeTest.java @@ -5,6 +5,7 @@ import static org.junit.Assert.assertTrue; import java.io.File; +import java.util.HashMap; import org.geotools.referencing.CRS; import org.junit.Before; import org.junit.Test; @@ -40,7 +41,7 @@ public void testAttributesFromJson() throws Exception { final Values values = new Values( - "test", + new HashMap(), pJsonObject, template, getTaskDirectory(), @@ -76,7 +77,7 @@ public void testAttributesFromYaml() throws Exception { final Values values = new Values( - "test", + new HashMap(), pJsonObject, template, getTaskDirectory(), @@ -113,7 +114,7 @@ public void testAttributesFromBoth() throws Exception { final Values values = new Values( - "test", + new HashMap(), pJsonObject, template, getTaskDirectory(), diff --git a/core/src/test/java/org/mapfish/print/config/CustomFontLoaderTest.java b/core/src/test/java/org/mapfish/print/config/CustomFontLoaderTest.java index bd824172de..c985f36628 100644 --- a/core/src/test/java/org/mapfish/print/config/CustomFontLoaderTest.java +++ b/core/src/test/java/org/mapfish/print/config/CustomFontLoaderTest.java @@ -4,6 +4,7 @@ import java.awt.GraphicsEnvironment; import java.io.IOException; +import java.util.HashMap; import java.util.Map; import net.sf.jasperreports.engine.JasperPrint; import org.apache.commons.lang3.ArrayUtils; @@ -43,7 +44,7 @@ public void testPrint() throws Exception { (AbstractJasperReportOutputFormat) this.outputFormat.get("pngOutputFormat"); JasperPrint print = format.getJasperPrint( - "test", + new HashMap(), requestData, config, getFile(CustomFontLoaderTest.class, BASE_DIR), diff --git a/core/src/test/java/org/mapfish/print/http/ConfigFileResolvingHttpRequestFactoryTest.java b/core/src/test/java/org/mapfish/print/http/ConfigFileResolvingHttpRequestFactoryTest.java index 94a4d2de96..f2c2a5919c 100644 --- a/core/src/test/java/org/mapfish/print/http/ConfigFileResolvingHttpRequestFactoryTest.java +++ b/core/src/test/java/org/mapfish/print/http/ConfigFileResolvingHttpRequestFactoryTest.java @@ -6,6 +6,7 @@ import java.io.IOException; import java.net.URI; import java.nio.file.Files; +import java.util.HashMap; import org.apache.commons.io.IOUtils; import org.junit.Before; import org.junit.Test; @@ -46,7 +47,8 @@ public void setUp() throws Exception { final Configuration config = configurationFactory.getConfig(getFile(BASE_DIR + "config.yaml")); this.resolvingFactory = - new ConfigFileResolvingHttpRequestFactory(this.requestFactory, config, "test"); + new ConfigFileResolvingHttpRequestFactory( + this.requestFactory, config, new HashMap()); } @Test diff --git a/core/src/test/java/org/mapfish/print/http/HttpProxyTest.java b/core/src/test/java/org/mapfish/print/http/HttpProxyTest.java index 61f1ce9c09..149dc40e83 100644 --- a/core/src/test/java/org/mapfish/print/http/HttpProxyTest.java +++ b/core/src/test/java/org/mapfish/print/http/HttpProxyTest.java @@ -21,6 +21,7 @@ import java.security.cert.CertificateException; import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.List; import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.SSLContext; @@ -107,7 +108,8 @@ static void assertCorrectResponse( } ConfigFileResolvingHttpRequestFactory clientHttpRequestFactory = - new ConfigFileResolvingHttpRequestFactory(requestFactory, config, "test"); + new ConfigFileResolvingHttpRequestFactory( + requestFactory, config, new HashMap()); URI uri = new URI(target + path); final ClientHttpRequest request = clientHttpRequestFactory.createRequest(uri, HttpMethod.GET); diff --git a/core/src/test/java/org/mapfish/print/map/geotools/FeaturesParserTest.java b/core/src/test/java/org/mapfish/print/map/geotools/FeaturesParserTest.java index 6f5c9da727..4768e5a16c 100644 --- a/core/src/test/java/org/mapfish/print/map/geotools/FeaturesParserTest.java +++ b/core/src/test/java/org/mapfish/print/map/geotools/FeaturesParserTest.java @@ -8,6 +8,7 @@ import java.io.File; import java.net.URI; import java.util.Arrays; +import java.util.HashMap; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -185,7 +186,8 @@ public void testParseCRSLinkProj4() { public void testTreatStringAsGeoJson() throws Exception { Configuration configuration = configurationFactory.getConfig(getFile("geojson/config.yaml")); MfClientHttpRequestFactory configRequestFactory = - new ConfigFileResolvingHttpRequestFactory(requestFactory, configuration, "test"); + new ConfigFileResolvingHttpRequestFactory( + requestFactory, configuration, new HashMap()); FeaturesParser featuresParser = new FeaturesParser(configRequestFactory, false); for (File geojsonExample : getGeoJsonExamples()) { try { @@ -215,7 +217,8 @@ public void testTreatStringAsGeoJson() throws Exception { public void testTreatStringAsGeoJsonEmptyCollection() throws Exception { Configuration configuration = configurationFactory.getConfig(getFile("geojson/config.yaml")); MfClientHttpRequestFactory configRequestFactory = - new ConfigFileResolvingHttpRequestFactory(requestFactory, configuration, "test"); + new ConfigFileResolvingHttpRequestFactory( + requestFactory, configuration, new HashMap()); FeaturesParser featuresParser = new FeaturesParser(configRequestFactory, false); final String geojson = "{\"type\": \"FeatureCollection\", \"features\": []}"; diff --git a/core/src/test/java/org/mapfish/print/map/geotools/grid/LineGridStrategyTest.java b/core/src/test/java/org/mapfish/print/map/geotools/grid/LineGridStrategyTest.java index 56de608d24..c5092df110 100644 --- a/core/src/test/java/org/mapfish/print/map/geotools/grid/LineGridStrategyTest.java +++ b/core/src/test/java/org/mapfish/print/map/geotools/grid/LineGridStrategyTest.java @@ -51,7 +51,9 @@ public void testParseSpacingAndOrigin() throws Throwable { MapfishMapContext context = new MapfishMapContext(bounds, mapSize, rotation, dpi, true, true); final List layers = layer.getLayers( - new TestHttpClientFactory(), context, new AbstractProcessor.Context("test")); + new TestHttpClientFactory(), + context, + new AbstractProcessor.Context(new HashMap())); assertEquals(1, layers.size()); FeatureSource fs = layers.get(0).getFeatureSource(); @@ -92,7 +94,9 @@ public void testParseNumLines() throws Throwable { MapfishMapContext context = new MapfishMapContext(bounds, mapSize, rotation, dpi, true, true); final List layers = layer.getLayers( - new TestHttpClientFactory(), context, new AbstractProcessor.Context("test")); + new TestHttpClientFactory(), + context, + new AbstractProcessor.Context(new HashMap())); assertEquals(1, layers.size()); FeatureSource fs = layers.get(0).getFeatureSource(); diff --git a/core/src/test/java/org/mapfish/print/map/style/FileSLDParserPluginTest.java b/core/src/test/java/org/mapfish/print/map/style/FileSLDParserPluginTest.java index b91387843f..7af52f1b8f 100644 --- a/core/src/test/java/org/mapfish/print/map/style/FileSLDParserPluginTest.java +++ b/core/src/test/java/org/mapfish/print/map/style/FileSLDParserPluginTest.java @@ -5,6 +5,7 @@ import static org.junit.Assert.assertTrue; import java.io.File; +import java.util.HashMap; import java.util.Optional; import org.geotools.styling.Style; import org.junit.Test; @@ -115,7 +116,8 @@ public void testFileNotInConfigDir() throws Throwable { config.setFileLoaderManager(this.fileLoaderManager); ConfigFileResolvingHttpRequestFactory requestFactory = - new ConfigFileResolvingHttpRequestFactory(this.clientHttpRequestFactory, config, "test"); + new ConfigFileResolvingHttpRequestFactory( + this.clientHttpRequestFactory, config, new HashMap()); assertFalse(this.parser.parseStyle(config, requestFactory, file.getAbsolutePath()).isPresent()); } @@ -127,7 +129,8 @@ private Optional