diff --git a/default/generated/spring-framework/spring-framework-5.x-to-6.0-web-applications.yaml b/default/generated/spring-framework/spring-framework-5.x-to-6.0-web-applications.yaml index e1845182..807954f8 100644 --- a/default/generated/spring-framework/spring-framework-5.x-to-6.0-web-applications.yaml +++ b/default/generated/spring-framework/spring-framework-5.x-to-6.0-web-applications.yaml @@ -49,3 +49,46 @@ url: https://github.com/spring-projects/spring-framework/wiki/Spring-Framework-6.0-Release-Notes#web-applications - title: 'Specific Spring Framwork change' url: https://github.com/spring-projects/spring-framework/issues/28552 + +- ruleID: spring-framework-5.x-to-6.0-web-applications-00030 + category: mandatory + effort: 1 + labels: + - konveyor.io/source=spring5 + - konveyor.io/target=spring6+ + when: + or: + - and: + - or: + - java.referenced: + pattern: org.springframework.stereotype.Controller + location: ANNOTATION + - java.referenced: + pattern: org.springframework.web.bind.annotation.RestController + location: ANNOTATION + as: class + ignore: true + - java.referenced: + pattern: '* javax.xml.transform.Source' + location: METHOD + filepaths: "{{class.Filepaths}}" + from: class + - or: + - java.referenced: + pattern: 'getForObject(URI,Class)' + location: METHOD_CALL + - java.referenced: + pattern: 'getForObject(String,Class,*)' + location: METHOD_CALL + description: "SourceHttpMessageConverter is not configured by default anymore in Spring MVC and RestTemplate" + message: | + `SourceHttpMessageConverter` is not configured by default anymore in Spring MVC and `RestTemplate`. + As a consequence, Spring web applications using `javax.xml.transform.Source` now need to configure + `SourceHttpMessageConverter` explicitly. Note that the order of converter registration is important, + and `SourceHttpMessageConverter` should typically be registered before "catch-all" converters like + `MappingJackson2HttpMessageConverter` for example. + links: + - title: 'Spring 6.0 migration guide' + url: https://github.com/spring-projects/spring-framework/wiki/Spring-Framework-6.0-Release-Notes#web-applications + - title: 'GitHub issue: Make SourceHttpMessageConverter optional' + url: https://github.com/spring-projects/spring-framework/issues/29535 diff --git a/default/generated/spring-framework/tests/data/web-applications/src/main/java/org/konveyor/Main.java b/default/generated/spring-framework/tests/data/web-applications/src/main/java/org/konveyor/Main.java index 5224b76e..fe30da79 100644 --- a/default/generated/spring-framework/tests/data/web-applications/src/main/java/org/konveyor/Main.java +++ b/default/generated/spring-framework/tests/data/web-applications/src/main/java/org/konveyor/Main.java @@ -1,11 +1,20 @@ package org.konveyor; -import java.beans.IntrospectionException; +import org.springframework.web.client.RestTemplate; + +import javax.xml.transform.Source; +import java.net.URI; +import java.net.URISyntaxException; public class Main { - public static void main(String[] args) throws IntrospectionException { + public static void main(String[] args) throws URISyntaxException { + RestTemplate rest = new RestTemplate(); + rest.getForObject(new URI("http://www.example.com/"), Source.class); + rest.getForObject("http://www.example.com/", Source.class); + rest.getForObject("http://www.example.com/", Source.class, "Hey"); + java.lang.System.getenv(); } } diff --git a/default/generated/spring-framework/tests/data/web-applications/src/main/java/org/konveyor/controller/XmlController.java b/default/generated/spring-framework/tests/data/web-applications/src/main/java/org/konveyor/controller/XmlController.java new file mode 100644 index 00000000..87179e55 --- /dev/null +++ b/default/generated/spring-framework/tests/data/web-applications/src/main/java/org/konveyor/controller/XmlController.java @@ -0,0 +1,37 @@ +package org.konveyor.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.ResponseBody; + +import javax.xml.transform.Source; +import javax.xml.transform.stream.StreamSource; +import java.io.StringReader; + +@Controller +public class XmlController { + + @PostMapping("/process-xml") + @ResponseBody + public Source processXml(@RequestBody String xmlInput) { + // For example, log the input or perform some processing here + System.out.println("Received XML: " + xmlInput); + + // Assuming we want to respond with a modified version of the XML + String responseXml = "Success%s"; + + // Return the new XML wrapped in a StreamSource + return new StreamSource(new StringReader(responseXml)); + } + + @GetMapping(value = "/xml/", produces = "application/xml") + public Source getXmlData() { + // Predefined XML string + String xmlContent = "Hello, World!%s"; + + // Return as Source + return new StreamSource(new StringReader(xmlContent)); + } +} diff --git a/default/generated/spring-framework/tests/data/web-applications/src/main/java/org/konveyor/controller/XmlRestController.java b/default/generated/spring-framework/tests/data/web-applications/src/main/java/org/konveyor/controller/XmlRestController.java new file mode 100644 index 00000000..92907494 --- /dev/null +++ b/default/generated/spring-framework/tests/data/web-applications/src/main/java/org/konveyor/controller/XmlRestController.java @@ -0,0 +1,25 @@ +package org.konveyor.controller; + +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +import javax.xml.transform.Source; +import javax.xml.transform.stream.StreamSource; +import java.io.StringReader; + +@RestController +public class XmlRestController { + + public Source method(@RequestBody String xmlInput) { + // For example, log the input or perform some processing here + System.out.println("Received XML: " + xmlInput); + + // Assuming we want to respond with a modified version of the XML + String responseXml = "Success%s"; + + // Return the new XML wrapped in a StreamSource + return new StreamSource(new StringReader(responseXml)); + } + + +} diff --git a/default/generated/spring-framework/tests/spring-framework-5.x-to-6.0-web-applications.test.yaml b/default/generated/spring-framework/tests/spring-framework-5.x-to-6.0-web-applications.test.yaml index 114eb706..4150db86 100644 --- a/default/generated/spring-framework/tests/spring-framework-5.x-to-6.0-web-applications.test.yaml +++ b/default/generated/spring-framework/tests/spring-framework-5.x-to-6.0-web-applications.test.yaml @@ -10,3 +10,11 @@ tests: mode: "source-only" hasIncidents: exactly: 1 + +- ruleID: spring-framework-5.x-to-6.0-web-applications-00030 + testCases: + - name: tc-1 + analysisParams: + mode: "source-only" + hasIncidents: + exactly: 6