Skip to content

Commit fda5579

Browse files
committed
ControllerUtils.printHtml(): extract method.
No functional changes.
1 parent e7add79 commit fda5579

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

src/main/java/ru/mystamps/web/controller/ControllerUtils.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
*/
1818
package ru.mystamps.web.controller;
1919

20+
import java.io.IOException;
21+
22+
import javax.servlet.http.HttpServletResponse;
23+
2024
import org.springframework.web.util.UriComponentsBuilder;
2125

2226
final class ControllerUtils {
@@ -32,4 +36,10 @@ public static String redirectTo(String url, Object... args) {
3236
return "redirect:" + dstUrl;
3337
}
3438

39+
public static void printHtml(HttpServletResponse response, String html) throws IOException {
40+
response.setContentType("text/html");
41+
response.setCharacterEncoding("UTF-8");
42+
response.getWriter().println(html);
43+
}
44+
3545
}

src/main/java/ru/mystamps/web/controller/TestController.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
import ru.mystamps.web.Url;
2929

30+
import static ru.mystamps.web.controller.ControllerUtils.printHtml;
31+
3032
@Controller
3133
public class TestController {
3234

@@ -60,18 +62,16 @@ public String simpleJson() {
6062

6163
@GetMapping("/test/invalid/simple-html")
6264
public void simpleHtml(HttpServletResponse response) throws IOException {
63-
response.setContentType("text/html");
64-
response.setCharacterEncoding("UTF-8");
65-
response.getWriter().println(
65+
printHtml(
66+
response,
6667
"<html><head><title>test</title></head><body>test</body></html>"
6768
);
6869
}
6970

7071
@GetMapping("/test/valid/series-info/existing-seller")
7172
public void seriesInfoWithExistingSeller(HttpServletResponse response) throws IOException {
72-
response.setContentType("text/html");
73-
response.setCharacterEncoding("UTF-8");
74-
response.getWriter().println(
73+
printHtml(
74+
response,
7575
"<!DOCTYPE html>"
7676
+ "<html>"
7777
+ "<head>"
@@ -92,9 +92,8 @@ public void seriesInfoWithExistingSeller(HttpServletResponse response) throws IO
9292

9393
@GetMapping("/test/valid/series-info/new-seller")
9494
public void seriesInfoWithNewSeller(HttpServletResponse response) throws IOException {
95-
response.setContentType("text/html");
96-
response.setCharacterEncoding("UTF-8");
97-
response.getWriter().println(
95+
printHtml(
96+
response,
9897
"<!DOCTYPE html>"
9998
+ "<html>"
10099
+ "<head>"

0 commit comments

Comments
 (0)