1
1
/*
2
- * Copyright 2002-2020 the original author or authors.
2
+ * Copyright 2002-2021 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
32
32
import org .springframework .util .concurrent .ListenableFuture ;
33
33
import org .springframework .util .concurrent .ListenableFutureTask ;
34
34
import org .springframework .web .bind .annotation .ExceptionHandler ;
35
+ import org .springframework .web .bind .annotation .GetMapping ;
35
36
import org .springframework .web .bind .annotation .RequestMapping ;
36
37
import org .springframework .web .bind .annotation .ResponseStatus ;
37
38
import org .springframework .web .bind .annotation .RestController ;
@@ -99,7 +100,7 @@ public void deferredResult() {
99
100
}
100
101
101
102
@ Test
102
- public void deferredResultWithImmediateValue () throws Exception {
103
+ public void deferredResultWithImmediateValue () {
103
104
this .testClient .get ()
104
105
.uri ("/1?deferredResultWithImmediateValue=true" )
105
106
.exchange ()
@@ -109,7 +110,7 @@ public void deferredResultWithImmediateValue() throws Exception {
109
110
}
110
111
111
112
@ Test
112
- public void deferredResultWithDelayedError () throws Exception {
113
+ public void deferredResultWithDelayedError () {
113
114
this .testClient .get ()
114
115
.uri ("/1?deferredResultWithDelayedError=true" )
115
116
.exchange ()
@@ -118,7 +119,7 @@ public void deferredResultWithDelayedError() throws Exception {
118
119
}
119
120
120
121
@ Test
121
- public void listenableFuture () throws Exception {
122
+ public void listenableFuture () {
122
123
this .testClient .get ()
123
124
.uri ("/1?listenableFuture=true" )
124
125
.exchange ()
@@ -142,17 +143,17 @@ public void completableFutureWithImmediateValue() throws Exception {
142
143
@ RequestMapping (path = "/{id}" , produces = "application/json" )
143
144
private static class AsyncController {
144
145
145
- @ RequestMapping (params = "callable" )
146
+ @ GetMapping (params = "callable" )
146
147
public Callable <Person > getCallable () {
147
148
return () -> new Person ("Joe" );
148
149
}
149
150
150
- @ RequestMapping (params = "streaming" )
151
+ @ GetMapping (params = "streaming" )
151
152
public StreamingResponseBody getStreaming () {
152
153
return os -> os .write ("name=Joe" .getBytes (StandardCharsets .UTF_8 ));
153
154
}
154
155
155
- @ RequestMapping (params = "streamingSlow" )
156
+ @ GetMapping (params = "streamingSlow" )
156
157
public StreamingResponseBody getStreamingSlow () {
157
158
return os -> {
158
159
os .write ("name=Joe" .getBytes ());
@@ -166,41 +167,41 @@ public StreamingResponseBody getStreamingSlow() {
166
167
};
167
168
}
168
169
169
- @ RequestMapping (params = "streamingJson" )
170
+ @ GetMapping (params = "streamingJson" )
170
171
public ResponseEntity <StreamingResponseBody > getStreamingJson () {
171
172
return ResponseEntity .ok ().contentType (MediaType .APPLICATION_JSON )
172
173
.body (os -> os .write ("{\" name\" :\" Joe\" ,\" someDouble\" :0.5}" .getBytes (StandardCharsets .UTF_8 )));
173
174
}
174
175
175
- @ RequestMapping (params = "deferredResult" )
176
+ @ GetMapping (params = "deferredResult" )
176
177
public DeferredResult <Person > getDeferredResult () {
177
178
DeferredResult <Person > result = new DeferredResult <>();
178
179
delay (100 , () -> result .setResult (new Person ("Joe" )));
179
180
return result ;
180
181
}
181
182
182
- @ RequestMapping (params = "deferredResultWithImmediateValue" )
183
+ @ GetMapping (params = "deferredResultWithImmediateValue" )
183
184
public DeferredResult <Person > getDeferredResultWithImmediateValue () {
184
185
DeferredResult <Person > result = new DeferredResult <>();
185
186
result .setResult (new Person ("Joe" ));
186
187
return result ;
187
188
}
188
189
189
- @ RequestMapping (params = "deferredResultWithDelayedError" )
190
+ @ GetMapping (params = "deferredResultWithDelayedError" )
190
191
public DeferredResult <Person > getDeferredResultWithDelayedError () {
191
192
DeferredResult <Person > result = new DeferredResult <>();
192
193
delay (100 , () -> result .setErrorResult (new RuntimeException ("Delayed Error" )));
193
194
return result ;
194
195
}
195
196
196
- @ RequestMapping (params = "listenableFuture" )
197
+ @ GetMapping (params = "listenableFuture" )
197
198
public ListenableFuture <Person > getListenableFuture () {
198
199
ListenableFutureTask <Person > futureTask = new ListenableFutureTask <>(() -> new Person ("Joe" ));
199
200
delay (100 , futureTask );
200
201
return futureTask ;
201
202
}
202
203
203
- @ RequestMapping (params = "completableFutureWithImmediateValue" )
204
+ @ GetMapping (params = "completableFutureWithImmediateValue" )
204
205
public CompletableFuture <Person > getCompletableFutureWithImmediateValue () {
205
206
CompletableFuture <Person > future = new CompletableFuture <>();
206
207
future .complete (new Person ("Joe" ));
0 commit comments