Skip to content

Commit

Permalink
Improve rule
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Manuel Leflet Estrada <jleflete@redhat.com>
  • Loading branch information
jmle committed Nov 25, 2024
1 parent 52fb1c2 commit 9b91b66
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,25 @@
- konveyor.io/target=spring6+
when:
or:
- java.referenced:
pattern: org.springframework.stereotype.Controller
location: ANNOTATION
as: class
ignore: true
- java.referenced:
pattern: '* javax.xml.transform.Source'
location: METHOD
filepaths: "{{class.Filepaths}}"
from: class
- 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
# TODO: not working atm - fix test cases when working
- java.referenced:
pattern: 'getForObject()'
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`.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package org.konveyor;

import org.springframework.web.client.RestTemplate;

import javax.xml.transform.Source;
import java.beans.IntrospectionException;
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 IntrospectionException, URISyntaxException {
RestTemplate rest = new RestTemplate();
rest.getForObject(new URI("http://www.example.com/"), Source.class);
}

}
Original file line number Diff line number Diff line change
@@ -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 = "<response><status>Success</status><originalMessage>%s</originalMessage></response>";

// Return the new XML wrapped in a StreamSource
return new StreamSource(new StringReader(responseXml));
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ tests:
analysisParams:
mode: "source-only"
hasIncidents:
exactly: 2
exactly: 3

0 comments on commit 9b91b66

Please sign in to comment.