0

I have a method in a @Controller which generates a ModelAndView and rendered a JSP page. The resulting HTML is a report which is refreshed on-screen every few minutes.

I've now been asked to provide a snapshot of the report on the last day of each month. I feel the best way to do this without too much refactoring of the application is on the last day of each month, simulate a call to the method that generates the report, and capture the generated HTML so it can be rendered at any point in future.

I know how to setup a scheduled task within Spring Boot, but I'm struggling to figure out how to simulate a call to a controller and grab the response as a String that contains the HTML response from the report.

2
  • 1
    Wouldn't it be better if you save the data for that specific time (last day of each month) and render HTML for it when the user requests it? Commented Feb 7, 2018 at 13:32
  • Ideally that's what I would prefer to do, but it's much more time consuming as the visual report contains 4 different tables each with different types of data, so storing all of this data takes longer and currently not necessary for its use case. Commented Feb 7, 2018 at 13:44

1 Answer 1

2

If you insist on the method you described, you can use the RestTemplate class

RestTemplate restTemplate = new RestTemplate();
String url = "http://<path-to-your-report-view>";

ResponseEntity<String> response = restTemplate.getForEntity(url, String.class);
if (response.getStatusCode() == HttpStatus.OK) {
    String result = response.getBody();
    // ... Save the result
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.