org.springframework.core.codec.Decoder Java Examples

The following examples show how to use org.springframework.core.codec.Decoder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BaseDefaultCodecs.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Return Object readers (JSON, XML, SSE).
 */
final List<HttpMessageReader<?>> getObjectReaders() {
	if (!this.registerDefaults) {
		return Collections.emptyList();
	}
	List<HttpMessageReader<?>> readers = new ArrayList<>();
	if (jackson2Present) {
		readers.add(new DecoderHttpMessageReader<>(getJackson2JsonDecoder()));
	}
	if (jackson2SmilePresent) {
		readers.add(new DecoderHttpMessageReader<>(new Jackson2SmileDecoder()));
	}
	if (jaxb2Present) {
		Decoder<?> decoder = this.jaxb2Decoder != null ? this.jaxb2Decoder : new Jaxb2XmlDecoder();
		readers.add(new DecoderHttpMessageReader<>(decoder));
	}
	extendObjectReaders(readers);
	return readers;
}
 
Example #2
Source File: BaseDefaultCodecs.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Return readers that support specific types.
 */
final List<HttpMessageReader<?>> getTypedReaders() {
	if (!this.registerDefaults) {
		return Collections.emptyList();
	}
	List<HttpMessageReader<?>> readers = new ArrayList<>();
	readers.add(new DecoderHttpMessageReader<>(new ByteArrayDecoder()));
	readers.add(new DecoderHttpMessageReader<>(new ByteBufferDecoder()));
	readers.add(new DecoderHttpMessageReader<>(new DataBufferDecoder()));
	readers.add(new DecoderHttpMessageReader<>(new ResourceDecoder()));
	readers.add(new DecoderHttpMessageReader<>(StringDecoder.textPlainOnly()));
	if (protobufPresent) {
		Decoder<?> decoder = this.protobufDecoder != null ? this.protobufDecoder : new ProtobufDecoder();
		readers.add(new DecoderHttpMessageReader<>(decoder));
	}

	FormHttpMessageReader formReader = new FormHttpMessageReader();
	formReader.setEnableLoggingRequestDetails(this.enableLoggingRequestDetails);
	readers.add(formReader);

	extendTypedReaders(readers);

	return readers;
}
 
Example #3
Source File: BaseDefaultCodecs.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Return readers that support specific types.
 */
final List<HttpMessageReader<?>> getTypedReaders() {
	if (!this.registerDefaults) {
		return Collections.emptyList();
	}
	List<HttpMessageReader<?>> readers = new ArrayList<>();
	readers.add(new DecoderHttpMessageReader<>(new ByteArrayDecoder()));
	readers.add(new DecoderHttpMessageReader<>(new ByteBufferDecoder()));
	readers.add(new DecoderHttpMessageReader<>(new DataBufferDecoder()));
	readers.add(new ResourceHttpMessageReader());
	readers.add(new DecoderHttpMessageReader<>(StringDecoder.textPlainOnly()));
	if (protobufPresent) {
		Decoder<?> decoder = this.protobufDecoder != null ? this.protobufDecoder : new ProtobufDecoder();
		readers.add(new DecoderHttpMessageReader<>(decoder));
	}

	FormHttpMessageReader formReader = new FormHttpMessageReader();
	formReader.setEnableLoggingRequestDetails(this.enableLoggingRequestDetails);
	readers.add(formReader);

	extendTypedReaders(readers);

	return readers;
}
 
Example #4
Source File: BaseDefaultCodecs.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Return Object readers (JSON, XML, SSE).
 */
final List<HttpMessageReader<?>> getObjectReaders() {
	if (!this.registerDefaults) {
		return Collections.emptyList();
	}
	List<HttpMessageReader<?>> readers = new ArrayList<>();
	if (jackson2Present) {
		readers.add(new DecoderHttpMessageReader<>(getJackson2JsonDecoder()));
	}
	if (jackson2SmilePresent) {
		readers.add(new DecoderHttpMessageReader<>(new Jackson2SmileDecoder()));
	}
	if (jaxb2Present) {
		Decoder<?> decoder = this.jaxb2Decoder != null ? this.jaxb2Decoder : new Jaxb2XmlDecoder();
		readers.add(new DecoderHttpMessageReader<>(decoder));
	}
	extendObjectReaders(readers);
	return readers;
}
 
Example #5
Source File: MessageMappingMessageHandlerTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private MessageMappingMessageHandler initMesssageHandler() {

		List<Decoder<?>> decoders = Collections.singletonList(StringDecoder.allMimeTypes());
		List<Encoder<?>> encoders = Collections.singletonList(CharSequenceEncoder.allMimeTypes());

		ReactiveAdapterRegistry registry = ReactiveAdapterRegistry.getSharedInstance();
		this.returnValueHandler = new TestEncoderMethodReturnValueHandler(encoders, registry);

		PropertySource<?> source = new MapPropertySource("test", Collections.singletonMap("path", "path123"));

		StaticApplicationContext context = new StaticApplicationContext();
		context.getEnvironment().getPropertySources().addFirst(source);
		context.registerSingleton("testController", TestController.class);
		context.refresh();

		MessageMappingMessageHandler messageHandler = new MessageMappingMessageHandler();
		messageHandler.getReturnValueHandlerConfigurer().addCustomHandler(this.returnValueHandler);
		messageHandler.setApplicationContext(context);
		messageHandler.setEmbeddedValueResolver(new EmbeddedValueResolver(context.getBeanFactory()));
		messageHandler.setDecoders(decoders);
		messageHandler.afterPropertiesSet();

		return messageHandler;
	}
 
Example #6
Source File: CodecConfigurerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
private void assertDecoderInstance(Decoder<?> decoder) {
	assertSame(decoder, this.configurer.getReaders().stream()
			.filter(writer -> writer instanceof DecoderHttpMessageReader)
			.map(writer -> ((DecoderHttpMessageReader<?>) writer).getDecoder())
			.filter(e -> decoder.getClass().equals(e.getClass()))
			.findFirst()
			.filter(e -> e == decoder).orElse(null));
}
 
Example #7
Source File: MessageReaderArgumentResolverTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@SuppressWarnings("Convert2MethodRef")
private AbstractMessageReaderArgumentResolver resolver(Decoder<?>... decoders) {
	List<HttpMessageReader<?>> readers = new ArrayList<>();
	Arrays.asList(decoders).forEach(decoder -> readers.add(new DecoderHttpMessageReader<>(decoder)));
	return new AbstractMessageReaderArgumentResolver(readers) {
		@Override
		public boolean supportsParameter(MethodParameter parameter) {
			return false;
		}
		@Override
		public Mono<Object> resolveArgument(MethodParameter p, BindingContext bc, ServerWebExchange e) {
			return null;
		}
	};
}
 
Example #8
Source File: PayloadMethodArgumentResolver.java    From spring-analysis-note with MIT License 5 votes vote down vote up
public PayloadMethodArgumentResolver(List<? extends Decoder<?>> decoders, @Nullable Validator validator,
		@Nullable ReactiveAdapterRegistry registry, boolean useDefaultResolution) {

	Assert.isTrue(!CollectionUtils.isEmpty(decoders), "At least one Decoder is required");
	this.decoders = Collections.unmodifiableList(new ArrayList<>(decoders));
	this.validator = validator;
	this.adapterRegistry = registry != null ? registry : ReactiveAdapterRegistry.getSharedInstance();
	this.useDefaultResolution = useDefaultResolution;
}
 
Example #9
Source File: RSocketMessageHandler.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Return the {@code RSocketStrategies} instance provided via
 * {@link #setRSocketStrategies rsocketStrategies}, or
 * otherwise initialize it with the configured {@link #setEncoders(List)
 * encoders}, {@link #setDecoders(List) decoders}, and others.
 */
public RSocketStrategies getRSocketStrategies() {
	if (this.rsocketStrategies == null) {
		this.rsocketStrategies = RSocketStrategies.builder()
				.decoder(getDecoders().toArray(new Decoder<?>[0]))
				.encoder(getEncoders().toArray(new Encoder<?>[0]))
				.reactiveAdapterStrategy(getReactiveAdapterRegistry())
				.build();
	}
	return this.rsocketStrategies;
}
 
Example #10
Source File: DefaultRSocketStrategies.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private DefaultRSocketStrategies(List<Encoder<?>> encoders, List<Decoder<?>> decoders,
		ReactiveAdapterRegistry adapterRegistry, DataBufferFactory bufferFactory) {

	this.encoders = Collections.unmodifiableList(encoders);
	this.decoders = Collections.unmodifiableList(decoders);
	this.adapterRegistry = adapterRegistry;
	this.bufferFactory = bufferFactory;
}
 
Example #11
Source File: DecoderHttpMessageReader.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Create an instance wrapping the given {@link Decoder}.
 */
public DecoderHttpMessageReader(Decoder<T> decoder) {
	Assert.notNull(decoder, "Decoder is required");
	initLogger(decoder);
	this.decoder = decoder;
	this.mediaTypes = MediaType.asMediaTypes(decoder.getDecodableMimeTypes());
}
 
Example #12
Source File: DecoderHttpMessageReader.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private static void initLogger(Decoder<?> decoder) {
	if (decoder instanceof AbstractDecoder &&
			decoder.getClass().getName().startsWith("org.springframework.core.codec")) {
		Log logger = HttpLogging.forLog(((AbstractDecoder) decoder).getLogger());
		((AbstractDecoder) decoder).setLogger(logger);
	}
}
 
Example #13
Source File: DefaultRSocketRequester.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
private <T> Flux<T> retrieveFlux(ResolvableType elementType) {
	Flux<Payload> payloadFlux = this.payloadMono != null ?
			this.payloadMono.flatMapMany(rsocket::requestStream) :
			rsocket.requestChannel(this.payloadFlux);

	if (isVoid(elementType)) {
		return payloadFlux.thenMany(Flux.empty());
	}

	Decoder<?> decoder = strategies.decoder(elementType, dataMimeType);
	return payloadFlux.map(this::retainDataAndReleasePayload).map(dataBuffer ->
			(T) decoder.decode(dataBuffer, elementType, dataMimeType, EMPTY_HINTS));
}
 
Example #14
Source File: ServerCodecConfigurerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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));
}
 
Example #15
Source File: ClientCodecConfigurerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private void assertSseReader(List<HttpMessageReader<?>> readers) {
	HttpMessageReader<?> reader = readers.get(this.index.getAndIncrement());
	assertEquals(ServerSentEventHttpMessageReader.class, reader.getClass());
	Decoder<?> decoder = ((ServerSentEventHttpMessageReader) reader).getDecoder();
	assertNotNull(decoder);
	assertEquals(Jackson2JsonDecoder.class, decoder.getClass());
}
 
Example #16
Source File: CodecConfigurerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void defaultAndCustomReaders() {
	Decoder<?> customDecoder1 = mock(Decoder.class);
	Decoder<?> customDecoder2 = mock(Decoder.class);

	given(customDecoder1.canDecode(ResolvableType.forClass(Object.class), null)).willReturn(false);
	given(customDecoder2.canDecode(ResolvableType.forClass(Object.class), null)).willReturn(true);

	HttpMessageReader<?> customReader1 = mock(HttpMessageReader.class);
	HttpMessageReader<?> customReader2 = mock(HttpMessageReader.class);

	given(customReader1.canRead(ResolvableType.forClass(Object.class), null)).willReturn(false);
	given(customReader2.canRead(ResolvableType.forClass(Object.class), null)).willReturn(true);

	this.configurer.customCodecs().decoder(customDecoder1);
	this.configurer.customCodecs().decoder(customDecoder2);

	this.configurer.customCodecs().reader(customReader1);
	this.configurer.customCodecs().reader(customReader2);

	List<HttpMessageReader<?>> readers = this.configurer.getReaders();

	assertEquals(15, readers.size());
	assertSame(customDecoder1, getNextDecoder(readers));
	assertSame(customReader1, readers.get(this.index.getAndIncrement()));
	assertEquals(ByteArrayDecoder.class, getNextDecoder(readers).getClass());
	assertEquals(ByteBufferDecoder.class, getNextDecoder(readers).getClass());
	assertEquals(DataBufferDecoder.class, getNextDecoder(readers).getClass());
	assertEquals(ResourceHttpMessageReader.class, readers.get(this.index.getAndIncrement()).getClass());
	assertEquals(StringDecoder.class, getNextDecoder(readers).getClass());
	assertEquals(ProtobufDecoder.class, getNextDecoder(readers).getClass());
	assertEquals(FormHttpMessageReader.class, readers.get(this.index.getAndIncrement()).getClass());
	assertSame(customDecoder2, getNextDecoder(readers));
	assertSame(customReader2, readers.get(this.index.getAndIncrement()));
	assertEquals(Jackson2JsonDecoder.class, getNextDecoder(readers).getClass());
	assertEquals(Jackson2SmileDecoder.class, getNextDecoder(readers).getClass());
	assertEquals(Jaxb2XmlDecoder.class, getNextDecoder(readers).getClass());
	assertEquals(StringDecoder.class, getNextDecoder(readers).getClass());
}
 
Example #17
Source File: CodecConfigurerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void defaultsOffCustomReaders() {
	Decoder<?> customDecoder1 = mock(Decoder.class);
	Decoder<?> customDecoder2 = mock(Decoder.class);

	given(customDecoder1.canDecode(ResolvableType.forClass(Object.class), null)).willReturn(false);
	given(customDecoder2.canDecode(ResolvableType.forClass(Object.class), null)).willReturn(true);

	HttpMessageReader<?> customReader1 = mock(HttpMessageReader.class);
	HttpMessageReader<?> customReader2 = mock(HttpMessageReader.class);

	given(customReader1.canRead(ResolvableType.forClass(Object.class), null)).willReturn(false);
	given(customReader2.canRead(ResolvableType.forClass(Object.class), null)).willReturn(true);

	this.configurer.customCodecs().decoder(customDecoder1);
	this.configurer.customCodecs().decoder(customDecoder2);

	this.configurer.customCodecs().reader(customReader1);
	this.configurer.customCodecs().reader(customReader2);

	this.configurer.registerDefaults(false);

	List<HttpMessageReader<?>> readers = this.configurer.getReaders();

	assertEquals(4, readers.size());
	assertSame(customDecoder1, getNextDecoder(readers));
	assertSame(customReader1, readers.get(this.index.getAndIncrement()));
	assertSame(customDecoder2, getNextDecoder(readers));
	assertSame(customReader2, readers.get(this.index.getAndIncrement()));
}
 
Example #18
Source File: CodecConfigurerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private void assertDecoderInstance(Decoder<?> decoder) {
	assertSame(decoder, this.configurer.getReaders().stream()
			.filter(writer -> writer instanceof DecoderHttpMessageReader)
			.map(writer -> ((DecoderHttpMessageReader<?>) writer).getDecoder())
			.filter(e -> decoder.getClass().equals(e.getClass()))
			.findFirst()
			.filter(e -> e == decoder).orElse(null));
}
 
Example #19
Source File: MessageReaderArgumentResolverTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@SuppressWarnings("Convert2MethodRef")
private AbstractMessageReaderArgumentResolver resolver(Decoder<?>... decoders) {
	List<HttpMessageReader<?>> readers = new ArrayList<>();
	Arrays.asList(decoders).forEach(decoder -> readers.add(new DecoderHttpMessageReader<>(decoder)));
	return new AbstractMessageReaderArgumentResolver(readers) {
		@Override
		public boolean supportsParameter(MethodParameter parameter) {
			return false;
		}
		@Override
		public Mono<Object> resolveArgument(MethodParameter p, BindingContext bc, ServerWebExchange e) {
			return null;
		}
	};
}
 
Example #20
Source File: DecoderHttpMessageReader.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Create an instance wrapping the given {@link Decoder}.
 */
public DecoderHttpMessageReader(Decoder<T> decoder) {
	Assert.notNull(decoder, "Decoder is required");
	initLogger(decoder);
	this.decoder = decoder;
	this.mediaTypes = MediaType.asMediaTypes(decoder.getDecodableMimeTypes());
}
 
Example #21
Source File: DecoderHttpMessageReader.java    From java-technology-stack with MIT License 5 votes vote down vote up
private static void initLogger(Decoder<?> decoder) {
	if (decoder instanceof AbstractDecoder &&
			decoder.getClass().getName().startsWith("org.springframework.core.codec")) {
		Log logger = HttpLogging.forLog(((AbstractDecoder) decoder).getLogger());
		((AbstractDecoder) decoder).setLogger(logger);
	}
}
 
Example #22
Source File: ServerCodecConfigurerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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));
}
 
Example #23
Source File: ClientCodecConfigurerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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));
}
 
Example #24
Source File: ClientCodecConfigurerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
private void assertSseReader(List<HttpMessageReader<?>> readers) {
	HttpMessageReader<?> reader = readers.get(this.index.getAndIncrement());
	assertEquals(ServerSentEventHttpMessageReader.class, reader.getClass());
	Decoder<?> decoder = ((ServerSentEventHttpMessageReader) reader).getDecoder();
	assertNotNull(decoder);
	assertEquals(Jackson2JsonDecoder.class, decoder.getClass());
}
 
Example #25
Source File: CodecConfigurerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void defaultAndCustomReaders() {
	Decoder<?> customDecoder1 = mock(Decoder.class);
	Decoder<?> customDecoder2 = mock(Decoder.class);

	when(customDecoder1.canDecode(ResolvableType.forClass(Object.class), null)).thenReturn(false);
	when(customDecoder2.canDecode(ResolvableType.forClass(Object.class), null)).thenReturn(true);

	HttpMessageReader<?> customReader1 = mock(HttpMessageReader.class);
	HttpMessageReader<?> customReader2 = mock(HttpMessageReader.class);

	when(customReader1.canRead(ResolvableType.forClass(Object.class), null)).thenReturn(false);
	when(customReader2.canRead(ResolvableType.forClass(Object.class), null)).thenReturn(true);

	this.configurer.customCodecs().decoder(customDecoder1);
	this.configurer.customCodecs().decoder(customDecoder2);

	this.configurer.customCodecs().reader(customReader1);
	this.configurer.customCodecs().reader(customReader2);

	List<HttpMessageReader<?>> readers = this.configurer.getReaders();

	assertEquals(15, readers.size());
	assertEquals(ByteArrayDecoder.class, getNextDecoder(readers).getClass());
	assertEquals(ByteBufferDecoder.class, getNextDecoder(readers).getClass());
	assertEquals(DataBufferDecoder.class, getNextDecoder(readers).getClass());
	assertEquals(ResourceDecoder.class, getNextDecoder(readers).getClass());
	assertEquals(StringDecoder.class, getNextDecoder(readers).getClass());
	assertEquals(ProtobufDecoder.class, getNextDecoder(readers).getClass());
	assertEquals(FormHttpMessageReader.class, readers.get(this.index.getAndIncrement()).getClass());
	assertSame(customDecoder1, getNextDecoder(readers));
	assertSame(customReader1, readers.get(this.index.getAndIncrement()));
	assertEquals(Jackson2JsonDecoder.class, getNextDecoder(readers).getClass());
	assertEquals(Jackson2SmileDecoder.class, getNextDecoder(readers).getClass());
	assertEquals(Jaxb2XmlDecoder.class, getNextDecoder(readers).getClass());
	assertSame(customDecoder2, getNextDecoder(readers));
	assertSame(customReader2, readers.get(this.index.getAndIncrement()));
	assertEquals(StringDecoder.class, getNextDecoder(readers).getClass());
}
 
Example #26
Source File: CodecConfigurerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void defaultsOffCustomReaders() {
	Decoder<?> customDecoder1 = mock(Decoder.class);
	Decoder<?> customDecoder2 = mock(Decoder.class);

	when(customDecoder1.canDecode(ResolvableType.forClass(Object.class), null)).thenReturn(false);
	when(customDecoder2.canDecode(ResolvableType.forClass(Object.class), null)).thenReturn(true);

	HttpMessageReader<?> customReader1 = mock(HttpMessageReader.class);
	HttpMessageReader<?> customReader2 = mock(HttpMessageReader.class);

	when(customReader1.canRead(ResolvableType.forClass(Object.class), null)).thenReturn(false);
	when(customReader2.canRead(ResolvableType.forClass(Object.class), null)).thenReturn(true);

	this.configurer.customCodecs().decoder(customDecoder1);
	this.configurer.customCodecs().decoder(customDecoder2);

	this.configurer.customCodecs().reader(customReader1);
	this.configurer.customCodecs().reader(customReader2);

	this.configurer.registerDefaults(false);

	List<HttpMessageReader<?>> readers = this.configurer.getReaders();

	assertEquals(4, readers.size());
	assertSame(customDecoder1, getNextDecoder(readers));
	assertSame(customReader1, readers.get(this.index.getAndIncrement()));
	assertSame(customDecoder2, getNextDecoder(readers));
	assertSame(customReader2, readers.get(this.index.getAndIncrement()));
}
 
Example #27
Source File: ClientCodecConfigurerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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));
}
 
Example #28
Source File: BaseDefaultCodecs.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public void protobufDecoder(Decoder<?> decoder) {
	this.protobufDecoder = decoder;
}
 
Example #29
Source File: DefaultRSocketStrategies.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public List<Decoder<?>> decoders() {
	return this.decoders;
}
 
Example #30
Source File: ClientDefaultCodecsImpl.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public void serverSentEventDecoder(Decoder<?> decoder) {
	this.sseDecoder = decoder;
}