org.springframework.http.codec.FormHttpMessageReader Java Examples

The following examples show how to use org.springframework.http.codec.FormHttpMessageReader. 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 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 #2
Source File: ServerCodecConfigurerTests.java    From spring-analysis-note 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(ResourceHttpMessageReader.class, readers.get(this.index.getAndIncrement()).getClass());
	assertStringDecoder(getNextDecoder(readers), true);
	assertEquals(ProtobufDecoder.class, getNextDecoder(readers).getClass());
	assertEquals(FormHttpMessageReader.class, readers.get(this.index.getAndIncrement()).getClass());
	assertEquals(DefaultMultipartMessageReader.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 spring-analysis-note 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(ResourceHttpMessageReader.class, readers.get(this.index.getAndIncrement()).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 spring-analysis-note 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(ResourceHttpMessageReader.class, readers.get(this.index.getAndIncrement()).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: 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 #6
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 #7
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 #8
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 #9
Source File: BodyExtractorsTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Before
public void createContext() {
	final List<HttpMessageReader<?>> messageReaders = new ArrayList<>();
	messageReaders.add(new DecoderHttpMessageReader<>(new ByteBufferDecoder()));
	messageReaders.add(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes()));
	messageReaders.add(new DecoderHttpMessageReader<>(new Jaxb2XmlDecoder()));
	messageReaders.add(new DecoderHttpMessageReader<>(new Jackson2JsonDecoder()));
	messageReaders.add(new FormHttpMessageReader());
	SynchronossPartHttpMessageReader partReader = new SynchronossPartHttpMessageReader();
	messageReaders.add(partReader);
	messageReaders.add(new MultipartHttpMessageReader(partReader));

	messageReaders.add(new FormHttpMessageReader());

	this.context = new BodyExtractor.Context() {
		@Override
		public List<HttpMessageReader<?>> messageReaders() {
			return messageReaders;
		}

		@Override
		public Optional<ServerHttpResponse> serverResponse() {
			return serverResponse;
		}

		@Override
		public Map<String, Object> hints() {
			return hints;
		}
	};
	this.hints = new HashMap<String, Object>();
}
 
Example #10
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 #11
Source File: BodyExtractorsTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Before
public void createContext() {
	final List<HttpMessageReader<?>> messageReaders = new ArrayList<>();
	messageReaders.add(new DecoderHttpMessageReader<>(new ByteBufferDecoder()));
	messageReaders.add(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes()));
	messageReaders.add(new DecoderHttpMessageReader<>(new Jaxb2XmlDecoder()));
	messageReaders.add(new DecoderHttpMessageReader<>(new Jackson2JsonDecoder()));
	messageReaders.add(new FormHttpMessageReader());
	SynchronossPartHttpMessageReader partReader = new SynchronossPartHttpMessageReader();
	messageReaders.add(partReader);
	messageReaders.add(new MultipartHttpMessageReader(partReader));

	messageReaders.add(new FormHttpMessageReader());

	this.context = new BodyExtractor.Context() {
		@Override
		public List<HttpMessageReader<?>> messageReaders() {
			return messageReaders;
		}

		@Override
		public Optional<ServerHttpResponse> serverResponse() {
			return serverResponse;
		}

		@Override
		public Map<String, Object> hints() {
			return hints;
		}
	};
	this.hints = new HashMap<String, Object>();
}
 
Example #12
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 #13
Source File: FormCodecInitializer.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 FormHttpMessageWriter());
	configurer.customCodecs().reader(new FormHttpMessageReader());
}