@@ -98,25 +98,27 @@ public Mono<Part> readMono(ResolvableType elementType, ReactiveHttpInputMessage
98
98
Map <String , Object > hints ) {
99
99
100
100
return Mono .error (new UnsupportedOperationException (
101
- "This reader does not support reading a single element ." ));
101
+ "Can't read a multipart request body into a single Part ." ));
102
102
}
103
103
104
104
105
105
/**
106
- * Consume and feed input to the Synchronoss parser, then adapt parser
107
- * output events to {@code Flux<Sink<Part>>}.
106
+ * Consume and feed input to the Synchronoss parser, then listen for parser
107
+ * output events and adapt to {@code Flux<Sink<Part>>}.
108
108
*/
109
109
private static class SynchronossPartGenerator implements Consumer <FluxSink <Part >> {
110
110
111
111
private final ReactiveHttpInputMessage inputMessage ;
112
112
113
113
private final DataBufferFactory bufferFactory ;
114
114
115
+
115
116
SynchronossPartGenerator (ReactiveHttpInputMessage inputMessage , DataBufferFactory factory ) {
116
117
this .inputMessage = inputMessage ;
117
118
this .bufferFactory = factory ;
118
119
}
119
120
121
+
120
122
@ Override
121
123
public void accept (FluxSink <Part > emitter ) {
122
124
HttpHeaders headers = this .inputMessage .getHeaders ();
@@ -176,12 +178,14 @@ private static class FluxSinkAdapterListener implements NioMultipartParserListen
176
178
177
179
private final AtomicInteger terminated = new AtomicInteger (0 );
178
180
179
- FluxSinkAdapterListener (FluxSink <Part > sink , DataBufferFactory bufferFactory , MultipartContext context ) {
181
+
182
+ FluxSinkAdapterListener (FluxSink <Part > sink , DataBufferFactory factory , MultipartContext context ) {
180
183
this .sink = sink ;
181
- this .bufferFactory = bufferFactory ;
184
+ this .bufferFactory = factory ;
182
185
this .context = context ;
183
186
}
184
187
188
+
185
189
@ Override
186
190
public void onPartFinished (StreamStorage storage , Map <String , List <String >> headers ) {
187
191
HttpHeaders httpHeaders = new HttpHeaders ();
@@ -192,14 +196,14 @@ public void onPartFinished(StreamStorage storage, Map<String, List<String>> head
192
196
private Part createPart (StreamStorage storage , HttpHeaders httpHeaders ) {
193
197
String filename = MultipartUtils .getFileName (httpHeaders );
194
198
if (filename != null ) {
195
- return new SynchronossFilePart (httpHeaders , storage , this .bufferFactory , filename );
199
+ return new SynchronossFilePart (httpHeaders , filename , storage , this .bufferFactory );
196
200
}
197
201
else if (MultipartUtils .isFormField (httpHeaders , this .context )) {
198
202
String value = MultipartUtils .readFormParameterValue (storage , httpHeaders );
199
203
return new SynchronossFormFieldPart (httpHeaders , this .bufferFactory , value );
200
204
}
201
205
else {
202
- return new DefaultSynchronossPart (httpHeaders , storage , this .bufferFactory );
206
+ return new SynchronossPart (httpHeaders , storage , this .bufferFactory );
203
207
}
204
208
}
205
209
@@ -229,47 +233,53 @@ public void onNestedPartFinished() {
229
233
230
234
private abstract static class AbstractSynchronossPart implements Part {
231
235
236
+ private final String name ;
237
+
232
238
private final HttpHeaders headers ;
233
239
234
240
private final DataBufferFactory bufferFactory ;
235
241
242
+
236
243
AbstractSynchronossPart (HttpHeaders headers , DataBufferFactory bufferFactory ) {
237
244
Assert .notNull (headers , "HttpHeaders is required" );
238
245
Assert .notNull (bufferFactory , "'bufferFactory' is required" );
246
+ this .name = MultipartUtils .getFieldName (headers );
239
247
this .headers = headers ;
240
248
this .bufferFactory = bufferFactory ;
241
249
}
242
250
251
+
243
252
@ Override
244
253
public String name () {
245
- return MultipartUtils . getFieldName ( this .headers ) ;
254
+ return this .name ;
246
255
}
247
256
248
257
@ Override
249
258
public HttpHeaders headers () {
250
259
return this .headers ;
251
260
}
252
261
253
- protected DataBufferFactory getBufferFactory () {
262
+ DataBufferFactory getBufferFactory () {
254
263
return this .bufferFactory ;
255
264
}
256
265
}
257
266
258
267
259
- private static class DefaultSynchronossPart extends AbstractSynchronossPart {
268
+ private static class SynchronossPart extends AbstractSynchronossPart {
260
269
261
270
private final StreamStorage storage ;
262
271
263
- DefaultSynchronossPart (HttpHeaders headers , StreamStorage storage , DataBufferFactory factory ) {
272
+
273
+ SynchronossPart (HttpHeaders headers , StreamStorage storage , DataBufferFactory factory ) {
264
274
super (headers , factory );
265
275
Assert .notNull (storage , "'storage' is required" );
266
276
this .storage = storage ;
267
277
}
268
278
279
+
269
280
@ Override
270
281
public Flux <DataBuffer > content () {
271
- return DataBufferUtils .readInputStream (this .storage ::getInputStream , getBufferFactory (),
272
- 4096 );
282
+ return DataBufferUtils .readInputStream (getStorage ()::getInputStream , getBufferFactory (), 4096 );
273
283
}
274
284
275
285
protected StreamStorage getStorage () {
@@ -278,20 +288,23 @@ protected StreamStorage getStorage() {
278
288
}
279
289
280
290
281
- private static class SynchronossFilePart extends DefaultSynchronossPart implements FilePart {
291
+ private static class SynchronossFilePart extends SynchronossPart implements FilePart {
282
292
283
293
private static final OpenOption [] FILE_CHANNEL_OPTIONS = {
284
294
StandardOpenOption .CREATE , StandardOpenOption .TRUNCATE_EXISTING , StandardOpenOption .WRITE };
285
295
296
+
286
297
private final String filename ;
287
298
288
- public SynchronossFilePart (
289
- HttpHeaders headers , StreamStorage storage , DataBufferFactory factory , String filename ) {
299
+
300
+ SynchronossFilePart (HttpHeaders headers , String filename , StreamStorage storage ,
301
+ DataBufferFactory factory ) {
290
302
291
303
super (headers , storage , factory );
292
304
this .filename = filename ;
293
305
}
294
306
307
+
295
308
@ Override
296
309
public String filename () {
297
310
return this .filename ;
@@ -342,11 +355,13 @@ private static class SynchronossFormFieldPart extends AbstractSynchronossPart im
342
355
343
356
private final String content ;
344
357
358
+
345
359
SynchronossFormFieldPart (HttpHeaders headers , DataBufferFactory bufferFactory , String content ) {
346
360
super (headers , bufferFactory );
347
361
this .content = content ;
348
362
}
349
363
364
+
350
365
@ Override
351
366
public String value () {
352
367
return this .content ;
@@ -361,8 +376,8 @@ public Flux<DataBuffer> content() {
361
376
}
362
377
363
378
private Charset getCharset () {
364
- return Optional . ofNullable ( MultipartUtils .getCharEncoding (headers ()))
365
- . map ( Charset :: forName ). orElse ( StandardCharsets .UTF_8 );
379
+ String name = MultipartUtils .getCharEncoding (headers ());
380
+ return ( name != null ? Charset . forName ( name ) : StandardCharsets .UTF_8 );
366
381
}
367
382
}
368
383
0 commit comments