Wrong URL generated for reports
Context
- MapFish print version: 3.22.0
- Java version: 11
- OS: Ubuntu
Describe the bug
The response to a request for generating a report provide wrong URL
Example of reponse :
{
"ref": "07280f75-f10a-4184-b61e-6938e823976a@ad3ca04a-6642-495a-a1a2-6cceae7660b5",
"statusURL": "/servitudes/print/report.pdf/status/07280f75-f10a-4184-b61e-6938e823976a@ad3ca04a-6642-495a-a1a2-6cceae7660b5.json",
"downloadURL": "/servitudes/print/report.pdf/report/07280f75-f10a-4184-b61e-6938e823976a@ad3ca04a-6642-495a-a1a2-6cceae7660b5"
}
The report.pdf should not be a part of the statusURL and downloadURL, because of this, it leads to 404 If I remove the "report.pdf" from URLs, it work well.
How to reproduce
I included print-lib into a SpringBoot 2.3 project
MapfishPrintConfiguration.java :
package fr.lepuyenvelay.servitudes;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.context.annotation.PropertySource;
@Configuration
@PropertySource("classpath:mapfish-print.properties")
@PropertySource(value = "file:${georchestra.datadir}/servitudes/mapfish-print.properties", ignoreResourceNotFound = true)
@ImportResource(locations = {
"classpath:mapfish-print-init.xml"
})
public class MapfishPrintConfiguration {
}
mapfish-print-init.xml :
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<import resource="mapfish-spring-config-objects.xml" />
<import resource="mapfish-spring-attributes.xml" />
<import resource="mapfish-spring-processors.xml" />
<import resource="mapfish-spring-layer-parser.xml" />
<import resource="mapfish-spring-style-parsers.xml" />
<import resource="mapfish-spring-config-file-loaders.xml" />
<import resource="mapfish-spring-config-output-formats.xml" />
<import resource="mapfish-spring-access-assertions.xml" />
<import resource="mapfish-spring-named-styles.xml" />
<bean id="servletInfo" class="org.mapfish.print.servlet.ConfigBasedServletInfo">
<!-- If servlet id is not set then a random uuid will be used -->
<!--<property name="servletId" value="print-server-1" />-->
</bean>
<bean id="workingDirectories" class="org.mapfish.print.config.WorkingDirectories">
<property name="working" value="${workingDir}" />
<property name="maxAgeReport" value="${fileCleanUpMaxAgeReport}" />
<property name="maxAgeTaskDir" value="${fileCleanUpMaxAgeTaskDir}" />
</bean>
<bean id="configurationFactory" class="org.mapfish.print.config.ConfigurationFactory"/>
<bean id="processorDependencyGraphFactory" class="org.mapfish.print.processor.ProcessorDependencyGraphFactory" />
<bean id="registry" class="org.mapfish.print.servlet.registry.BasicRegistry">
<property name="timeToKeepAfterAccessInMinutes" value="30" />
</bean>
<bean id="jobQueue" class="org.mapfish.print.servlet.job.impl.RegistryJobQueue"></bean>
<bean id="jobManager" class="org.mapfish.print.servlet.job.impl.ThreadPoolJobManager">
<property name="maxNumberOfRunningPrintJobs" value="${maxNumberOfRunningPrintJobs}" />
<property name="maxNumberOfWaitingJobs" value="5000" />
<!-- Timeout for print jobs in seconds -->
<property name="timeout" value="${printTimeout}" />
<!-- Timeout after which a print job is canceled, if the status has not been checked (in seconds). -->
<property name="abandonedTimeout" value="120" />
<property name="oldFileCleanUp" value="${fileCleanUp}" />
<property name="oldFileCleanupInterval" value="${fileCleanUpInterval}" />
</bean>
<bean id="printJobPrototype" class="org.mapfish.print.servlet.job.impl.FilePrintJob" scope="prototype"/>
<bean id="fileReportLoader" class="org.mapfish.print.servlet.job.loader.FileReportLoader"/>
<bean id="metricRegistry" class="com.codahale.metrics.MetricRegistry"/>
<bean id="healthCheckRegistry" class="com.codahale.metrics.health.HealthCheckRegistry"/>
<bean id="httpClientFactory" class="org.mapfish.print.http.MfClientHttpRequestFactoryImpl">
<constructor-arg index="0" value="${maxConnectionsTotal}" />
<constructor-arg index="1" value="${maxConnectionsPerRoute}" />
</bean>
<bean id="metricNameStrategy" class="org.mapfish.print.metrics.MetricsNameStrategyFactory" factory-method="hostAndMethod" />
<bean id="loggingMetricsConfigurator" class="org.mapfish.print.metrics.LoggingMetricsConfigurator" lazy-init="false"/>
<bean id="jvmMetricsConfigurator" class="org.mapfish.print.metrics.JvmMetricsConfigurator" lazy-init="false"/>
<bean id="jmxMetricsReporter" class="org.mapfish.print.metrics.JmxMetricsReporter" lazy-init="false"/>
<bean id="statsDReporterInit" class="org.mapfish.print.metrics.StatsDReporterInit" lazy-init="false"/>
<bean id="accounting" class="org.mapfish.print.servlet.job.Accounting" lazy-init="false"/>
<bean id="forkJoinPool" class="java.util.concurrent.ForkJoinPool" destroy-method="shutdownNow">
<!--
Thread pool used to run processors.
-->
<constructor-arg index="0" value="${threadsParallelProcessors}" />
</bean>
<bean id="requestForkJoinPool" class="java.util.concurrent.ForkJoinPool" destroy-method="shutdownNow" autowire-candidate="false">
<!--
Thread pool used for making requests for tile/image layers.
-->
<constructor-arg index="0" value="${threadsParallelRequests}" />
</bean>
<bean id="mapPrinter" class="org.mapfish.print.MapPrinter" scope="prototype"/>
<bean id="configuration" class="org.mapfish.print.config.Configuration" scope="prototype"/>
<bean id="styleParser" class="org.mapfish.print.map.style.StyleParser" />
<bean id="imageIOPluginScanner" class="org.mapfish.print.ImageIOPluginScanner" />
<bean class="org.mapfish.print.ApplicationContextProvider" />
<bean name="CurrentAPI" class="org.mapfish.print.servlet.MapPrinterServlet">
<property name="maxCreateAndGetWaitTimeInSeconds" value="30" />
</bean>
<bean id="mapPrinterFactory" class="org.mapfish.print.servlet.ServletMapPrinterFactory">
<property name="appsRootDirectory" value="${printapps.location}" />
</bean>
</beans>
POST to "/servitudes/print/report.pdf" parameters :
{
"layout":"A4 portrait",
"outputFilename":"NRU_350238000BP0240",
"attributes":{
"map":{
"scale":1066.3647919248917,
"center":[
-185552.085178,
6124901.561718
],
"dpi":91,
"layers":[
{
"type":"geojson",
"style":{
"1":{
"fillColor":"#ee9900",
"fillOpacity":0,
"hoverFillColor":"white",
"hoverFillOpacity":0.8,
"strokeColor":"#ee9900",
"strokeOpacity":1,
"strokeWidth":3,
"strokeLinecap":"round",
"strokeDashstyle":"solid",
"hoverStrokeColor":"red",
"hoverStrokeOpacity":1,
"hoverStrokeWidth":0.2,
"pointRadius":6,
"hoverPointRadius":1,
"hoverPointUnit":"%",
"pointerEvents":"visiblePainted",
"cursor":"pointer",
"fontColor":"#000000",
"labelAlign":"cm",
"labelOutlineColor":"white",
"labelOutlineWidth":3
},
"version":"1",
"styleProperty":"_gx_style"
},
"geoJson":{
"type":"FeatureCollection",
"features":[
{
"type":"Feature",
"properties":{
"_gx_style":1,
"ogc_fid":"131446",
"lot":"2020-06",
"inspireid":"FR350238000BP0240",
"id_parc":"350238000BP0240",
"commune":"350238",
"section":"350238000BP",
"section_txt":"BP",
"parcelle_txt":"240",
"section_parcelle_txt":"BP 240",
"supf":"11850",
"ssurf":"11839.40",
"ssurfb":"3858.39",
"scos":"32.6"
},
"geometry":{
"type":"Polygon",
"coordinates":[
[
[
-185637.618825,
6124902.523521
],
[
-185640.221737,
6124911.889311
],
[
-185646.028255,
6124945.51647
],
[
-185652.288181,
6124963.102459
],
[
-185657.961547,
6124973.708742
],
[
-185661.825712,
6124985.852155
],
[
-185661.061106,
6124990.300176
],
[
-185660.446584,
6124991.283944
],
[
-185658.159405,
6124993.586218
],
[
-185655.341336,
6124995.034454
],
[
-185653.320021,
6124995.292552
],
[
-185644.359742,
6124994.485327
],
[
-185538.753392,
6124978.101628
],
[
-185476.123523,
6124966.285328
],
[
-185442.344644,
6124960.496719
],
[
-185451.147834,
6124815.163708
],
[
-185451.800366,
6124812.825688
],
[
-185453.809462,
6124810.134826
],
[
-185457.054373,
6124808.315238
],
[
-185460.08041,
6124807.830884
],
[
-185463.314893,
6124808.565661
],
[
-185641.744477,
6124889.008146
],
[
-185637.618825,
6124902.523521
]
]
]
},
"id":"urbanisme_parcelle.fid-3c2ba12c_1752cd8b5e1_6bc5"
}
]
}
}
],
"projection":"EPSG:3857"
},
"parcelle":"350238000BP0240",
"commune":"Rennes",
"codeSection":"BP",
"numero":"240",
"adresseCadastrale":" BD RENE LAENNEC",
"contenanceDGFiP":11850,
"surfaceSIG":11839,
"codeProprio":"350238+13368",
"nomProprio":"COMMUNE DE RENNES",
"adresseProprio":"PL DE LA MAIRIE 35000 RENNES",
"dateRU":"24/09/2020",
"datePCI":"06/2020",
"libelles":"Tests"
}
}
Actual results
{
"ref": "07280f75-f10a-4184-b61e-6938e823976a@ad3ca04a-6642-495a-a1a2-6cceae7660b5",
"statusURL": "/servitudes/print/report.pdf/status/07280f75-f10a-4184-b61e-6938e823976a@ad3ca04a-6642-495a-a1a2-6cceae7660b5.json",
"downloadURL": "/servitudes/print/report.pdf/report/07280f75-f10a-4184-b61e-6938e823976a@ad3ca04a-6642-495a-a1a2-6cceae7660b5"
}
Expected results
{
"ref": "07280f75-f10a-4184-b61e-6938e823976a@ad3ca04a-6642-495a-a1a2-6cceae7660b5",
"statusURL": "/servitudes/print/status/07280f75-f10a-4184-b61e-6938e823976a@ad3ca04a-6642-495a-a1a2-6cceae7660b5.json",
"downloadURL": "/servitudes/print/report/07280f75-f10a-4184-b61e-6938e823976a@ad3ca04a-6642-495a-a1a2-6cceae7660b5"
}
Maybe it's related to https://github.com/mapfish/mapfish-print/blob/3.22/core/src/main/java/org/mapfish/print/servlet/BaseMapServlet.java#L110 which doesn't have right ServletPath ?
I notice the same problem when calling :
/servitudes/report.pdf/status/92868781-5905-4ca9-bc12-d7c651af53a2@f13229e5-a60d-4761-b908-e4908a07df70.json
Result :
{
"done": true,
"status": "finished",
"elapsedTime": 722,
"waitingTime": 0,
"downloadURL": "/servitudes/report.pdf/status/92868781-5905-4ca9-bc12-d7c651af53a2@f13229e5-a60d-4761-b908-e4908a07df70.json/report/92868781-5905-4ca9-bc12-d7c651af53a2@f13229e5-a60d-4761-b908-e4908a07df70"
}
Expected :
{
"done": true,
"status": "finished",
"elapsedTime": 722,
"waitingTime": 0,
"downloadURL": "/servitudes/report/92868781-5905-4ca9-bc12-d7c651af53a2@f13229e5-a60d-4761-b908-e4908a07df70"
}
The "/report.pdf/status/92868781-5905-4ca9-bc12-d7c651af53a2@f13229e5-a60d-4761-b908-e4908a07df70.json" part of the URL is generated here : https://github.com/mapfish/mapfish-print/blob/master/core/src/main/java/org/mapfish/print/servlet/BaseMapServlet.java#L116
I think only the context is needed to generate the status and download URL as we already have the job ID. Remove the ServletPath form those URLs can solve the problem.
Is there some utility to keep this servletPath ?