@@ -96,7 +96,7 @@ public StandardServletAsyncWebRequest(HttpServletRequest request, HttpServletRes
96
96
}
97
97
98
98
//noinspection DataFlowIssue
99
- ((LifecycleHttpServletResponse ) getResponse ()).setParent (this );
99
+ ((LifecycleHttpServletResponse ) getResponse ()).setAsyncWebRequest (this );
100
100
}
101
101
102
102
@@ -207,23 +207,25 @@ public void onComplete(AsyncEvent event) throws IOException {
207
207
private static final class LifecycleHttpServletResponse extends HttpServletResponseWrapper {
208
208
209
209
@ Nullable
210
- private StandardServletAsyncWebRequest parent ;
210
+ private StandardServletAsyncWebRequest asyncWebRequest ;
211
211
212
+ @ Nullable
212
213
private ServletOutputStream outputStream ;
213
214
214
215
public LifecycleHttpServletResponse (HttpServletResponse response ) {
215
216
super (response );
216
217
}
217
218
218
- public void setParent (StandardServletAsyncWebRequest parent ) {
219
- this .parent = parent ;
219
+ public void setAsyncWebRequest (StandardServletAsyncWebRequest asyncWebRequest ) {
220
+ this .asyncWebRequest = asyncWebRequest ;
220
221
}
221
222
222
223
@ Override
223
224
public ServletOutputStream getOutputStream () {
224
225
if (this .outputStream == null ) {
225
- Assert .notNull (this .parent , "Not initialized" );
226
- this .outputStream = new LifecycleServletOutputStream ((HttpServletResponse ) getResponse (), this .parent );
226
+ Assert .notNull (this .asyncWebRequest , "Not initialized" );
227
+ this .outputStream = new LifecycleServletOutputStream (
228
+ (HttpServletResponse ) getResponse (), this .asyncWebRequest );
227
229
}
228
230
return this .outputStream ;
229
231
}
@@ -236,13 +238,15 @@ public ServletOutputStream getOutputStream() {
236
238
*/
237
239
private static final class LifecycleServletOutputStream extends ServletOutputStream {
238
240
239
- private final HttpServletResponse response ;
241
+ private final HttpServletResponse delegate ;
242
+
243
+ private final StandardServletAsyncWebRequest asyncWebRequest ;
240
244
241
- private final StandardServletAsyncWebRequest parent ;
245
+ private LifecycleServletOutputStream (
246
+ HttpServletResponse delegate , StandardServletAsyncWebRequest asyncWebRequest ) {
242
247
243
- private LifecycleServletOutputStream (HttpServletResponse response , StandardServletAsyncWebRequest parent ) {
244
- this .response = response ;
245
- this .parent = parent ;
248
+ this .delegate = delegate ;
249
+ this .asyncWebRequest = asyncWebRequest ;
246
250
}
247
251
248
252
@ Override
@@ -258,7 +262,7 @@ public void setWriteListener(WriteListener writeListener) {
258
262
public void write (int b ) throws IOException {
259
263
checkState ();
260
264
try {
261
- this .response .getOutputStream ().write (b );
265
+ this .delegate .getOutputStream ().write (b );
262
266
}
263
267
catch (IOException ex ) {
264
268
handleIOException (ex , "ServletOutputStream failed to write" );
@@ -268,7 +272,7 @@ public void write(int b) throws IOException {
268
272
public void write (byte [] buf , int offset , int len ) throws IOException {
269
273
checkState ();
270
274
try {
271
- this .response .getOutputStream ().write (buf , offset , len );
275
+ this .delegate .getOutputStream ().write (buf , offset , len );
272
276
}
273
277
catch (IOException ex ) {
274
278
handleIOException (ex , "ServletOutputStream failed to write" );
@@ -279,7 +283,7 @@ public void write(byte[] buf, int offset, int len) throws IOException {
279
283
public void flush () throws IOException {
280
284
checkState ();
281
285
try {
282
- this .response .getOutputStream ().flush ();
286
+ this .delegate .getOutputStream ().flush ();
283
287
}
284
288
catch (IOException ex ) {
285
289
handleIOException (ex , "ServletOutputStream failed to flush" );
@@ -290,23 +294,23 @@ public void flush() throws IOException {
290
294
public void close () throws IOException {
291
295
checkState ();
292
296
try {
293
- this .response .getOutputStream ().close ();
297
+ this .delegate .getOutputStream ().close ();
294
298
}
295
299
catch (IOException ex ) {
296
300
handleIOException (ex , "ServletOutputStream failed to close" );
297
301
}
298
302
}
299
303
300
304
private void checkState () throws AsyncRequestNotUsableException {
301
- if (this .parent .state .get () != State .ACTIVE ) {
302
- String reason = this . parent . state . get () == State . COMPLETED ?
303
- "async request completion" : "Servlet container onError notification" ;
304
- throw new AsyncRequestNotUsableException ( "Response not usable after " + reason + "." );
305
+ if (this .asyncWebRequest .state .get () != State .ACTIVE ) {
306
+ throw new AsyncRequestNotUsableException ( "Response not usable after " +
307
+ ( this . asyncWebRequest . state . get () == State . COMPLETED ?
308
+ "async request completion" : "onError notification" ) + "." );
305
309
}
306
310
}
307
311
308
312
private void handleIOException (IOException ex , String msg ) throws AsyncRequestNotUsableException {
309
- this .parent .transitionToErrorState ();
313
+ this .asyncWebRequest .transitionToErrorState ();
310
314
throw new AsyncRequestNotUsableException (msg , ex );
311
315
}
312
316
0 commit comments