25
25
import static org .springframework .http .MediaType .APPLICATION_FORM_URLENCODED_VALUE ;
26
26
import static org .springframework .http .MediaType .APPLICATION_JSON_VALUE ;
27
27
import static org .springframework .http .MediaType .MULTIPART_FORM_DATA_VALUE ;
28
- import static org .springframework .web .bind .annotation .RequestMethod .POST ;
29
28
30
29
import java .io .IOException ;
31
30
import java .util .Collection ;
36
35
import org .springframework .http .HttpStatus ;
37
36
import org .springframework .http .ResponseEntity ;
38
37
import org .springframework .stereotype .Controller ;
38
+ import org .springframework .web .bind .annotation .GetMapping ;
39
39
import org .springframework .web .bind .annotation .PathVariable ;
40
40
import org .springframework .web .bind .annotation .PostMapping ;
41
41
import org .springframework .web .bind .annotation .RequestBody ;
42
- import org .springframework .web .bind .annotation .RequestMapping ;
43
42
import org .springframework .web .bind .annotation .RequestParam ;
44
43
import org .springframework .web .bind .annotation .RequestPart ;
45
44
import org .springframework .web .bind .annotation .ResponseStatus ;
51
50
@ SuppressWarnings ("checkstyle:DesignForExtension" )
52
51
public class Server {
53
52
54
- @ RequestMapping (path = "/form" , method = POST )
55
- public ResponseEntity <Void > form (@ RequestParam ("key1" ) String key1 ,
56
- @ RequestParam ("key2" ) String key2
53
+ @ PostMapping ("/form" )
54
+ public ResponseEntity <Void > form (
55
+ @ RequestParam ("key1" ) String key1 ,
56
+ @ RequestParam ("key2" ) String key2
57
57
) {
58
58
val status = !key1 .equals (key2 )
59
59
? BAD_REQUEST
60
60
: OK ;
61
61
return ResponseEntity .status (status ).body (null );
62
62
}
63
63
64
- @ RequestMapping ( path = "/upload/{id}" , method = POST )
64
+ @ PostMapping ( "/upload/{id}" )
65
65
@ ResponseStatus (OK )
66
- public ResponseEntity <Long > upload (@ PathVariable ("id" ) Integer id ,
67
- @ RequestParam ("public" ) Boolean isPublic ,
68
- @ RequestParam ("file" ) MultipartFile file
66
+ public ResponseEntity <Long > upload (
67
+ @ PathVariable ("id" ) Integer id ,
68
+ @ RequestParam ("public" ) Boolean isPublic ,
69
+ @ RequestParam ("file" ) MultipartFile file
69
70
) {
70
71
HttpStatus status ;
71
72
if (id == null || id != 10 ) {
@@ -82,7 +83,7 @@ public ResponseEntity<Long> upload (@PathVariable("id") Integer id,
82
83
return ResponseEntity .status (status ).body (file .getSize ());
83
84
}
84
85
85
- @ RequestMapping ( path = "/upload" , method = POST )
86
+ @ PostMapping ( "/upload" )
86
87
public ResponseEntity <Long > upload (@ RequestParam ("file" ) MultipartFile file ) {
87
88
HttpStatus status ;
88
89
if (file .getSize () == 0 ) {
@@ -95,7 +96,7 @@ public ResponseEntity<Long> upload (@RequestParam("file") MultipartFile file) {
95
96
return ResponseEntity .status (status ).body (file .getSize ());
96
97
}
97
98
98
- @ RequestMapping ( path = "/upload/files" , method = POST )
99
+ @ PostMapping ( "/upload/files" )
99
100
public ResponseEntity <Long > upload (@ RequestParam ("files" ) MultipartFile [] files ) {
100
101
HttpStatus status ;
101
102
if (files [0 ].getSize () == 0 || files [1 ].getSize () == 0 ) {
@@ -109,7 +110,7 @@ public ResponseEntity<Long> upload (@RequestParam("files") MultipartFile[] files
109
110
return ResponseEntity .status (status ).body (files [0 ].getSize () + files [1 ].getSize ());
110
111
}
111
112
112
- @ RequestMapping (path = "/json" , method = POST , consumes = APPLICATION_JSON_VALUE )
113
+ @ PostMapping (path = "/json" , consumes = APPLICATION_JSON_VALUE )
113
114
public ResponseEntity <String > json (@ RequestBody Dto dto ) {
114
115
HttpStatus status ;
115
116
if (!dto .getName ().equals ("Artem" )) {
@@ -122,24 +123,31 @@ public ResponseEntity<String> json (@RequestBody Dto dto) {
122
123
return ResponseEntity .status (status ).body ("ok" );
123
124
}
124
125
125
- @ RequestMapping ("/query_map" )
126
- public ResponseEntity <Integer > queryMap (@ RequestParam ("filter" ) List <String > filters ) {
126
+ @ GetMapping ("/query_map" )
127
+ public ResponseEntity <Integer > queryMap (
128
+ @ RequestParam ("filter" ) List <String > filters
129
+ ) {
127
130
val status = filters != null && !filters .isEmpty ()
128
131
? OK
129
132
: I_AM_A_TEAPOT ;
130
133
return ResponseEntity .status (status ).body (filters .size ());
131
134
}
132
135
133
- @ RequestMapping (path = "/wild-card-map" , method = POST , consumes = APPLICATION_FORM_URLENCODED_VALUE )
134
- public ResponseEntity <Integer > wildCardMap (@ RequestParam ("key1" ) String key1 , @ RequestParam ("key2" ) String key2 ) {
136
+ @ PostMapping (path = "/wild-card-map" , consumes = APPLICATION_FORM_URLENCODED_VALUE )
137
+ public ResponseEntity <Integer > wildCardMap (
138
+ @ RequestParam ("key1" ) String key1 ,
139
+ @ RequestParam ("key2" ) String key2
140
+ ) {
135
141
val status = key1 .equals (key2 )
136
142
? OK
137
143
: I_AM_A_TEAPOT ;
138
144
return ResponseEntity .status (status ).body (null );
139
145
}
140
146
141
147
@ PostMapping (path = "/upload/with_dto" , consumes = MULTIPART_FORM_DATA_VALUE )
142
- public ResponseEntity <Long > uploadWithDto (Dto dto , @ RequestPart ("file" ) MultipartFile file
148
+ public ResponseEntity <Long > uploadWithDto (
149
+ Dto dto ,
150
+ @ RequestPart ("file" ) MultipartFile file
143
151
) throws IOException {
144
152
val status = dto != null && dto .getName ().equals ("Artem" )
145
153
? OK
@@ -148,7 +156,9 @@ public ResponseEntity<Long> uploadWithDto (Dto dto, @RequestPart("file") Multipa
148
156
}
149
157
150
158
@ PostMapping (path = "/upload/byte_array" , consumes = MULTIPART_FORM_DATA_VALUE )
151
- public ResponseEntity <String > uploadByteArray (@ RequestPart ("file" ) MultipartFile file ) {
159
+ public ResponseEntity <String > uploadByteArray (
160
+ @ RequestPart ("file" ) MultipartFile file
161
+ ) {
152
162
val status = file != null
153
163
? OK
154
164
: I_AM_A_TEAPOT ;
@@ -159,31 +169,39 @@ public ResponseEntity<String> uploadByteArray (@RequestPart("file") MultipartFil
159
169
// We just want the request because when there's a filename part of the Content-Disposition header spring
160
170
// will treat it as a file (available through getFile()) and when it doesn't have the filename part it's
161
171
// available in the parameter (getParameter())
162
- public ResponseEntity <String > uploadByteArrayParameter (MultipartHttpServletRequest request ) {
172
+ public ResponseEntity <String > uploadByteArrayParameter (
173
+ MultipartHttpServletRequest request
174
+ ) {
163
175
val status = request .getFile ("file" ) == null && request .getParameter ("file" ) != null
164
176
? OK
165
177
: I_AM_A_TEAPOT ;
166
178
return ResponseEntity .status (status ).build ();
167
179
}
168
180
169
181
@ PostMapping (path = "/upload/unknown_type" , consumes = MULTIPART_FORM_DATA_VALUE )
170
- public ResponseEntity <String > uploadUnknownType (@ RequestPart ("file" ) MultipartFile file ) {
182
+ public ResponseEntity <String > uploadUnknownType (
183
+ @ RequestPart ("file" ) MultipartFile file
184
+ ) {
171
185
val status = file != null
172
186
? OK
173
187
: I_AM_A_TEAPOT ;
174
188
return ResponseEntity .status (status ).body (file .getContentType ());
175
189
}
176
190
177
191
@ PostMapping (path = "/upload/form_data" , consumes = MULTIPART_FORM_DATA_VALUE )
178
- public ResponseEntity <String > uploadFormData (@ RequestPart ("file" ) MultipartFile file ) {
192
+ public ResponseEntity <String > uploadFormData (
193
+ @ RequestPart ("file" ) MultipartFile file
194
+ ) {
179
195
val status = file != null
180
196
? OK
181
197
: I_AM_A_TEAPOT ;
182
198
return ResponseEntity .status (status ).body (file .getOriginalFilename () + ':' + file .getContentType ());
183
199
}
184
200
185
201
@ PostMapping (path = "/submit/url" , consumes = APPLICATION_FORM_URLENCODED_VALUE )
186
- public ResponseEntity <String > submitRepeatableQueryParam (@ RequestParam ("names" ) String [] names ) {
202
+ public ResponseEntity <String > submitRepeatableQueryParam (
203
+ @ RequestParam ("names" ) String [] names
204
+ ) {
187
205
val response = new StringBuilder ();
188
206
if (names != null && names .length == 2 ) {
189
207
response
@@ -199,7 +217,9 @@ public ResponseEntity<String> submitRepeatableQueryParam (@RequestParam("names")
199
217
}
200
218
201
219
@ PostMapping (path = "/submit/form" , consumes = MULTIPART_FORM_DATA_VALUE )
202
- public ResponseEntity <String > submitRepeatableFormParam (@ RequestParam ("names" ) Collection <String > names ) {
220
+ public ResponseEntity <String > submitRepeatableFormParam (
221
+ @ RequestParam ("names" ) Collection <String > names
222
+ ) {
203
223
val response = new StringBuilder ();
204
224
if (names != null && names .size () == 2 ) {
205
225
val iterator = names .iterator ();
@@ -216,8 +236,10 @@ public ResponseEntity<String> submitRepeatableFormParam (@RequestParam("names")
216
236
}
217
237
218
238
@ PostMapping (path = "/form-data" , consumes = APPLICATION_FORM_URLENCODED_VALUE )
219
- public ResponseEntity <String > submitPostData (@ RequestParam ("f_name" ) String firstName ,
220
- @ RequestParam ("age" ) Integer age ) {
239
+ public ResponseEntity <String > submitPostData (
240
+ @ RequestParam ("f_name" ) String firstName ,
241
+ @ RequestParam ("age" ) Integer age
242
+ ) {
221
243
val response = new StringBuilder ();
222
244
if (firstName != null && age != null ) {
223
245
response
0 commit comments