org.springframework.core.codec.ResourceDecoder Java Examples

The following examples show how to use org.springframework.core.codec.ResourceDecoder. 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 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 #2
Source File: ServerCodecConfigurerTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void defaultReaders() {
	List<HttpMessageReader<?>> readers = this.configurer.getReaders();
	assertEquals(13, 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());
	assertStringDecoder(getNextDecoder(readers), true);
	assertEquals(ProtobufDecoder.class, getNextDecoder(readers).getClass());
	assertEquals(FormHttpMessageReader.class, readers.get(this.index.getAndIncrement()).getClass());
	assertEquals(SynchronossPartHttpMessageReader.class, readers.get(this.index.getAndIncrement()).getClass());
	assertEquals(MultipartHttpMessageReader.class, readers.get(this.index.getAndIncrement()).getClass());
	assertEquals(Jackson2JsonDecoder.class, getNextDecoder(readers).getClass());
	assertEquals(Jackson2SmileDecoder.class, getNextDecoder(readers).getClass());
	assertEquals(Jaxb2XmlDecoder.class, getNextDecoder(readers).getClass());
	assertStringDecoder(getNextDecoder(readers), false);
}
 
Example #3
Source File: ClientCodecConfigurerTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void defaultReaders() {
	List<HttpMessageReader<?>> readers = this.configurer.getReaders();
	assertEquals(12, 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());
	assertStringDecoder(getNextDecoder(readers), true);
	assertEquals(ProtobufDecoder.class, getNextDecoder(readers).getClass());
	assertEquals(FormHttpMessageReader.class, readers.get(this.index.getAndIncrement()).getClass()); // SPR-16804
	assertEquals(Jackson2JsonDecoder.class, getNextDecoder(readers).getClass());
	assertEquals(Jackson2SmileDecoder.class, getNextDecoder(readers).getClass());
	assertEquals(Jaxb2XmlDecoder.class, getNextDecoder(readers).getClass());
	assertSseReader(readers);
	assertStringDecoder(getNextDecoder(readers), false);
}
 
Example #4
Source File: CodecConfigurerTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void defaultReaders() {
	List<HttpMessageReader<?>> readers = this.configurer.getReaders();
	assertEquals(11, 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());
	assertStringDecoder(getNextDecoder(readers), true);
	assertEquals(ProtobufDecoder.class, getNextDecoder(readers).getClass());
	assertEquals(FormHttpMessageReader.class, readers.get(this.index.getAndIncrement()).getClass());
	assertEquals(Jackson2JsonDecoder.class, getNextDecoder(readers).getClass());
	assertEquals(Jackson2SmileDecoder.class, getNextDecoder(readers).getClass());
	assertEquals(Jaxb2XmlDecoder.class, getNextDecoder(readers).getClass());
	assertStringDecoder(getNextDecoder(readers), false);
}
 
Example #5
Source File: ResourceHttpMessageReader.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
protected Map<String, Object> getReadHints(ResolvableType actualType, ResolvableType elementType,
		ServerHttpRequest request, ServerHttpResponse response) {

	String name = request.getHeaders().getContentDisposition().getFilename();
	return StringUtils.hasText(name) ? Hints.from(ResourceDecoder.FILENAME_HINT, name) : Hints.none();
}
 
Example #6
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 #7
Source File: ResourceHttpMessageReader.java    From spring-analysis-note with MIT License 4 votes vote down vote up
public ResourceHttpMessageReader() {
	super(new ResourceDecoder());
}
 
Example #8
Source File: ResourceHttpMessageReader.java    From spring-analysis-note with MIT License 4 votes vote down vote up
public ResourceHttpMessageReader(ResourceDecoder resourceDecoder) {
	super(resourceDecoder);
}
 
Example #9
Source File: ResourceCodecInitializer.java    From spring-fu with Apache License 2.0 4 votes vote down vote up
@Override
protected void register(GenericApplicationContext context, CodecConfigurer configurer) {
	configurer.customCodecs().writer(new ResourceHttpMessageWriter());
	configurer.customCodecs().decoder(new ResourceDecoder());
}