@Override public Flux<T> read(ResolvableType elementType, ReactiveHttpInputMessage message, Map<String, Object> hints) { MediaType contentType = getContentType(message); return this.decoder.decode(message.getBody(), elementType, contentType, hints); }
public Flux<T> read(ResolvableType elementType, ReactiveHttpInputMessage message, Map<String, Object> hints) { MediaType contentType = getContentType(message); return this.decoder.decode(message.getBody(), elementType, contentType, hints);
@Override public Flux<T> read(ResolvableType elementType, ReactiveHttpInputMessage message, Map<String, Object> hints) { MediaType contentType = getContentType(message); return this.decoder.decode(message.getBody(), elementType, contentType, hints); }
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) { Flux<T> result = (Flux<T>) this.decoder.decode(input, outputType, mimeType, hints); StepVerifier.FirstStep<T> step = StepVerifier.create(result); stepConsumer.accept(step);
/** * Test a {@link Decoder#decode decode} scenario where the input stream is empty. * The output is expected to be empty as well. * * @param outputType the desired output type * @param mimeType the mime type to use for decoding. May be {@code null}. * @param hints the hints used for decoding. May be {@code null}. */ protected void testDecodeEmpty(ResolvableType outputType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) { Flux<DataBuffer> input = Flux.empty(); Flux<?> result = this.decoder.decode(input, outputType, mimeType, hints); StepVerifier.create(result) .verifyComplete(); }
/** * Test a {@link Decoder#decode decode} scenario where the input stream is canceled. * This test method will feed the first element of the {@code input} stream to the decoder, * followed by a cancel signal. * The result is expected to contain one "normal" element. * * @param input the input to be provided to the decoder * @param outputType the desired output type * @param mimeType the mime type to use for decoding. May be {@code null}. * @param hints the hints used for decoding. May be {@code null}. */ protected void testDecodeCancel(Publisher<DataBuffer> input, ResolvableType outputType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) { Flux<?> result = this.decoder.decode(input, outputType, mimeType, hints); StepVerifier.create(result) .expectNextCount(1) .thenCancel() .verify(); }
@SuppressWarnings("unchecked") private void assertStringDecoder(Decoder<?> decoder, boolean textOnly) { assertEquals(StringDecoder.class, decoder.getClass()); assertTrue(decoder.canDecode(forClass(String.class), MimeTypeUtils.TEXT_PLAIN)); assertEquals(!textOnly, decoder.canDecode(forClass(String.class), MediaType.TEXT_EVENT_STREAM)); Flux<String> decoded = (Flux<String>) decoder.decode( Flux.just(new DefaultDataBufferFactory().wrap("line1\nline2".getBytes(StandardCharsets.UTF_8))), ResolvableType.forClass(String.class), MimeTypeUtils.TEXT_PLAIN, Collections.emptyMap()); assertEquals(Arrays.asList("line1", "line2"), decoded.collectList().block(Duration.ZERO)); }
@SuppressWarnings("unchecked") private void assertStringDecoder(Decoder<?> decoder, boolean textOnly) { assertEquals(StringDecoder.class, decoder.getClass()); assertTrue(decoder.canDecode(forClass(String.class), MimeTypeUtils.TEXT_PLAIN)); assertEquals(!textOnly, decoder.canDecode(forClass(String.class), MediaType.TEXT_EVENT_STREAM)); Flux<String> flux = (Flux<String>) decoder.decode( Flux.just(new DefaultDataBufferFactory().wrap("line1\nline2".getBytes(StandardCharsets.UTF_8))), ResolvableType.forClass(String.class), MimeTypeUtils.TEXT_PLAIN, Collections.emptyMap()); assertEquals(Arrays.asList("line1", "line2"), flux.collectList().block(Duration.ZERO)); }
/** * Test a {@link Decoder#decode decode} scenario where the input stream contains an error. * This test method will feed the first element of the {@code input} stream to the decoder, * followed by an {@link InputException}. * The result is expected to contain one "normal" element, followed by the error. * * @param input the input to be provided to the decoder * @param outputType the desired output type * @param mimeType the mime type to use for decoding. May be {@code null}. * @param hints the hints used for decoding. May be {@code null}. * @see InputException */ protected void testDecodeError(Publisher<DataBuffer> input, ResolvableType outputType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) { input = Flux.concat( Flux.from(input).take(1), Flux.error(new InputException())); Flux<?> result = this.decoder.decode(input, outputType, mimeType, hints); StepVerifier.create(result) .expectNextCount(1) .expectError(InputException.class) .verify(); }
@Override public Flux<T> read(ResolvableType elementType, ReactiveHttpInputMessage message, Map<String, Object> hints) { MediaType contentType = getContentType(message); return this.decoder.decode(message.getBody(), elementType, contentType, hints); }