From 3a6b02d1c914851a60f5e3fac7c6a846e51ac176 Mon Sep 17 00:00:00 2001 From: Lukasz Lenart Date: Sat, 12 Sep 2026 12:03:25 +0200 Subject: [PATCH] WW-5732 fix(jasperreports7): match the report format case-insensitively The exporter providers are registered under the lower-case names in JasperReport7Constants and the container lookup is exact, so the upper-case "CSV" from the class Javadoc example (and from any config migrated from the 6.x plugin, whose constants are upper-case) failed with "No exporter found for format: CSV". The result now retries the lookup with the lower-cased name, so a custom provider registered under a mixed-case name keeps working while csv, Csv and CSV all resolve to the bundled one. The example uses the canonical lower-case spelling. Co-Authored-By: Claude Opus 5 (1M context) --- .../views/jasperreports7/JasperReport7Result.java | 12 +++++++++--- .../jasperreports7/JasperReport7ResultTest.java | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/plugins/jasperreports7/src/main/java/org/apache/struts2/views/jasperreports7/JasperReport7Result.java b/plugins/jasperreports7/src/main/java/org/apache/struts2/views/jasperreports7/JasperReport7Result.java index fde8590bcd..7744cefc42 100644 --- a/plugins/jasperreports7/src/main/java/org/apache/struts2/views/jasperreports7/JasperReport7Result.java +++ b/plugins/jasperreports7/src/main/java/org/apache/struts2/views/jasperreports7/JasperReport7Result.java @@ -33,6 +33,7 @@ import org.apache.logging.log4j.Logger; import org.apache.struts2.ActionInvocation; import org.apache.struts2.StrutsException; +import org.apache.struts2.inject.Container; import org.apache.struts2.inject.Inject; import org.apache.struts2.result.StrutsResultSupport; import org.apache.struts2.security.NotExcludedAcceptedPatternsChecker; @@ -71,7 +72,8 @@ *
  • parse - true by default. If set to false, all the parameters will * not be parsed for EL expressions.
  • *
  • format - the format in which the report should be generated. Valid - * values can be found in {@link JasperReport7Constants}. If no format is + * values can be found in {@link JasperReport7Constants} and are matched case-insensitively, + * so csv and CSV select the same exporter. If no format is * specified, PDF will be used.
  • *
  • contentDisposition - disposition (defaults to "inline", values are * typically filename="document.pdf").
  • @@ -103,7 +105,7 @@ * <result name="success" type="jasperReport7"> * <param name="location">foo.jasper</param> * <param name="dataSource">mySource</param> - * <param name="format">CSV</param> + * <param name="format">csv</param> * </result> * * @@ -211,7 +213,11 @@ protected void doExecute(String finalLocation, ActionInvocation invocation) thro try { LOG.debug("Export the print object to the desired output format: {}", format); - JasperReport7ExporterProvider exporterProvider = invocation.getInvocationContext().getContainer().getInstance(JasperReport7ExporterProvider.class, format); + Container container = invocation.getInvocationContext().getContainer(); + JasperReport7ExporterProvider exporterProvider = container.getInstance(JasperReport7ExporterProvider.class, format); + if (exporterProvider == null) { + exporterProvider = container.getInstance(JasperReport7ExporterProvider.class, format.toLowerCase(Locale.ROOT)); + } if (exporterProvider == null) { throw new StrutsException("No exporter found for format: " + format); } diff --git a/plugins/jasperreports7/src/test/java/org/apache/struts2/views/jasperreports7/JasperReport7ResultTest.java b/plugins/jasperreports7/src/test/java/org/apache/struts2/views/jasperreports7/JasperReport7ResultTest.java index 2ef9d2ace3..d7c3aadc3e 100644 --- a/plugins/jasperreports7/src/test/java/org/apache/struts2/views/jasperreports7/JasperReport7ResultTest.java +++ b/plugins/jasperreports7/src/test/java/org/apache/struts2/views/jasperreports7/JasperReport7ResultTest.java @@ -289,6 +289,20 @@ public String getCsvDelimiter(ActionInvocation invocation) { assertThat(csv.lines()).containsExactly("Qux Report", "Hello Foo Bar!", "Hello Baz Qux!"); } + public void testFormatLookupIsCaseInsensitive() throws Exception { + // given + result.setDataSource("{#{'firstName':'ignore', 'lastName':'ignore'}}"); + result.setReportParameters("#{'title':'Qux'}"); + result.setFormat("CSV"); + + // when + result.execute(this.invocation); + + // then + assertThat(response.getContentType()).isEqualTo("text/csv"); + assertThat(response.getContentAsString()).contains("Qux Report"); + } + public void testExportToRtf() throws Exception { // given result.setDataSource("{#{'firstName':'ignore', 'lastName':'ignore'}}");