private Mono<?> decodeData(String data, ResolvableType dataType, Map<String, Object> hints) { if (String.class == dataType.resolve()) { return Mono.just(data.substring(0, data.length() - 1)); } if (this.decoder == null) { return Mono.error(new CodecException("No SSE decoder configured and the data is not String.")); } byte[] bytes = data.getBytes(StandardCharsets.UTF_8); Mono<DataBuffer> input = Mono.just(bufferFactory.wrap(bytes)); return this.decoder.decodeToMono(input, dataType, MediaType.TEXT_EVENT_STREAM, hints); }
@Override public Mono<T> readMono(ResolvableType elementType, ReactiveHttpInputMessage message, Map<String, Object> hints) { MediaType contentType = getContentType(message); return this.decoder.decodeToMono(message.getBody(), elementType, contentType, hints); }
private Mono<?> decodeData(String data, ResolvableType dataType, Map<String, Object> hints) { if (String.class == dataType.resolve()) { return Mono.just(data.substring(0, data.length() - 1)); } if (this.decoder == null) { return Mono.error(new CodecException("No SSE decoder configured and the data is not String.")); } byte[] bytes = data.getBytes(StandardCharsets.UTF_8); Mono<DataBuffer> input = Mono.just(bufferFactory.wrap(bytes)); return this.decoder.decodeToMono(input, dataType, MediaType.TEXT_EVENT_STREAM, hints); }
@Override public Mono<T> readMono(ResolvableType elementType, ReactiveHttpInputMessage message, Map<String, Object> hints) { MediaType contentType = getContentType(message); return this.decoder.decodeToMono(message.getBody(), elementType, contentType, hints); }
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) { Mono<T> result = (Mono<T>) this.decoder.decodeToMono(input, outputType, mimeType, hints); StepVerifier.FirstStep<T> step = StepVerifier.create(result); stepConsumer.accept(step);
/** * Test a {@link Decoder#decodeToMono decode} scenario where the input stream is canceled. * This test method will immediately cancel the output stream. * * @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 testDecodeToMonoCancel(Publisher<DataBuffer> input, ResolvableType outputType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) { Mono<?> result = this.decoder.decodeToMono(input, outputType, mimeType, hints); StepVerifier.create(result) .thenCancel() .verify(); }
/** * Test a {@link Decoder#decodeToMono 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 testDecodeToMonoEmpty(ResolvableType outputType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) { Flux<DataBuffer> input = Flux.empty(); Mono<?> result = this.decoder.decodeToMono(input, outputType, mimeType, hints); StepVerifier.create(result) .verifyComplete(); }
/** * Test a {@link Decoder#decodeToMono 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 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 testDecodeToMonoError(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())); Mono<?> result = this.decoder.decodeToMono(input, outputType, mimeType, hints); StepVerifier.create(result) .expectError(InputException.class) .verify(); }
private Mono<?> decodeData(String data, ResolvableType dataType, Map<String, Object> hints) { if (String.class == dataType.resolve()) { return Mono.just(data.substring(0, data.length() - 1)); } if (this.decoder == null) { return Mono.error(new CodecException("No SSE decoder configured and the data is not String.")); } byte[] bytes = data.getBytes(StandardCharsets.UTF_8); Mono<DataBuffer> input = Mono.just(bufferFactory.wrap(bytes)); return this.decoder.decodeToMono(input, dataType, MediaType.TEXT_EVENT_STREAM, hints); }
private Mono<?> decodeData(String data, ResolvableType dataType, Map<String, Object> hints) { if (String.class == dataType.resolve()) { return Mono.just(data.substring(0, data.length() - 1)); } if (this.decoder == null) { return Mono.error(new CodecException("No SSE decoder configured and the data is not String.")); } byte[] bytes = data.getBytes(StandardCharsets.UTF_8); Mono<DataBuffer> input = Mono.just(bufferFactory.wrap(bytes)); return this.decoder.decodeToMono(input, dataType, MediaType.TEXT_EVENT_STREAM, hints); }
@Override public Mono<T> readMono(ResolvableType elementType, ReactiveHttpInputMessage message, Map<String, Object> hints) { MediaType contentType = getContentType(message); return this.decoder.decodeToMono(message.getBody(), elementType, contentType, hints); }
public Mono<T> readMono(ResolvableType elementType, ReactiveHttpInputMessage message, Map<String, Object> hints) { MediaType contentType = getContentType(message); return this.decoder.decodeToMono(message.getBody(), elementType, contentType, hints);