org.springframework.http.codec.multipart.MultipartHttpMessageReader Java Examples

The following examples show how to use org.springframework.http.codec.multipart.MultipartHttpMessageReader. 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: 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 #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: 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 #4
Source File: MultipartIntegrationTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private MultiValueMap<String, HttpEntity<?>> generateBody() {
	MultipartBodyBuilder builder = new MultipartBodyBuilder();
	builder.part("fieldPart", "fieldValue");
	builder.part("fileParts", new ClassPathResource("foo.txt", MultipartHttpMessageReader.class));
	builder.part("fileParts", new ClassPathResource("logo.png", getClass()));
	builder.part("jsonPart", new Person("Jason"));
	return builder.build();
}
 
Example #5
Source File: ServerDefaultCodecsImpl.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
protected void extendTypedReaders(List<HttpMessageReader<?>> typedReaders) {

	HttpMessageReader<Part> partReader = getMultipartReader();

	boolean logRequestDetails = isEnableLoggingRequestDetails();
	if (partReader instanceof LoggingCodecSupport) {
		((LoggingCodecSupport) partReader).setEnableLoggingRequestDetails(logRequestDetails);
	}
	typedReaders.add(partReader);

	MultipartHttpMessageReader reader = new MultipartHttpMessageReader(partReader);
	reader.setEnableLoggingRequestDetails(logRequestDetails);
	typedReaders.add(reader);
}
 
Example #6
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 #7
Source File: MultipartIntegrationTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
private MultiValueMap<String, HttpEntity<?>> generateBody() {
	MultipartBodyBuilder builder = new MultipartBodyBuilder();
	builder.part("fieldPart", "fieldValue");
	builder.part("fileParts", new ClassPathResource("foo.txt", MultipartHttpMessageReader.class));
	builder.part("fileParts", new ClassPathResource("logo.png", getClass()));
	builder.part("jsonPart", new Person("Jason"));
	return builder.build();
}
 
Example #8
Source File: ServerDefaultCodecsImpl.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
protected void extendTypedReaders(List<HttpMessageReader<?>> typedReaders) {
	if (synchronossMultipartPresent) {
		boolean enable = isEnableLoggingRequestDetails();

		SynchronossPartHttpMessageReader partReader = new SynchronossPartHttpMessageReader();
		partReader.setEnableLoggingRequestDetails(enable);
		typedReaders.add(partReader);

		MultipartHttpMessageReader reader = new MultipartHttpMessageReader(partReader);
		reader.setEnableLoggingRequestDetails(enable);
		typedReaders.add(reader);
	}
}
 
Example #9
Source File: MultipartCodecInitializer.java    From spring-fu with Apache License 2.0 5 votes vote down vote up
@Override
protected void register(GenericApplicationContext context, CodecConfigurer configurer) {
	configurer.customCodecs().writer(new MultipartHttpMessageWriter());
	if (!isClientCodec) {
		configurer.customCodecs().reader(new MultipartHttpMessageReader(new SynchronossPartHttpMessageReader()));
	}
}