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 fbddfbb8..12182505 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 @@ -79,3 +79,45 @@ url: https://github.com/spring-projects/spring-framework/wiki/Spring-Framework-6.0-Release-Notes#web-applications +- 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 1014d26d..b0b3f1aa 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 @@ -2,13 +2,19 @@ import javax.xml.transform.Source; import javax.xml.transform.stream.StreamSource; -import java.beans.IntrospectionException; import java.io.StringReader; +import java.net.URI; +import java.net.URISyntaxException; -public class Main { +import org.springframework.web.client.RestTemplate; - public static void main(String[] args) throws IntrospectionException { +public class Main { + 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"); } public Source getXmlData() { 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 index e9f7f189..87179e55 100644 --- 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 @@ -2,7 +2,10 @@ 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; @@ -10,14 +13,25 @@ @Controller public class XmlController { - @GetMapping("/xml") + @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() { - String xmlData = - "\n" + - "Hello, world!\n" + - "\n"; + // Predefined XML string + String xmlContent = "Hello, World!%s"; - return new StreamSource(new StringReader(xmlData)); + // Return as Source + return new StreamSource(new StringReader(xmlContent)); } } 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 f81b42ea..41ab16c5 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 @@ -17,4 +17,10 @@ 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