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

The following examples show how to use org.springframework.http.codec.multipart.MultipartHttpMessageWriter. 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: ClientCodecConfigurerTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void defaultWriters() {
	List<HttpMessageWriter<?>> writers = this.configurer.getWriters();
	assertEquals(11, writers.size());
	assertEquals(ByteArrayEncoder.class, getNextEncoder(writers).getClass());
	assertEquals(ByteBufferEncoder.class, getNextEncoder(writers).getClass());
	assertEquals(DataBufferEncoder.class, getNextEncoder(writers).getClass());
	assertEquals(ResourceHttpMessageWriter.class, writers.get(index.getAndIncrement()).getClass());
	assertStringEncoder(getNextEncoder(writers), true);
	assertEquals(MultipartHttpMessageWriter.class, writers.get(this.index.getAndIncrement()).getClass());
	assertEquals(ProtobufHttpMessageWriter.class, writers.get(index.getAndIncrement()).getClass());
	assertEquals(Jackson2JsonEncoder.class, getNextEncoder(writers).getClass());
	assertEquals(Jackson2SmileEncoder.class, getNextEncoder(writers).getClass());
	assertEquals(Jaxb2XmlEncoder.class, getNextEncoder(writers).getClass());
	assertStringEncoder(getNextEncoder(writers), false);
}
 
Example #2
Source File: ClientCodecConfigurerTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void defaultWriters() {
	List<HttpMessageWriter<?>> writers = this.configurer.getWriters();
	assertEquals(11, writers.size());
	assertEquals(ByteArrayEncoder.class, getNextEncoder(writers).getClass());
	assertEquals(ByteBufferEncoder.class, getNextEncoder(writers).getClass());
	assertEquals(DataBufferEncoder.class, getNextEncoder(writers).getClass());
	assertEquals(ResourceHttpMessageWriter.class, writers.get(index.getAndIncrement()).getClass());
	assertStringEncoder(getNextEncoder(writers), true);
	assertEquals(MultipartHttpMessageWriter.class, writers.get(this.index.getAndIncrement()).getClass());
	assertEquals(ProtobufHttpMessageWriter.class, writers.get(index.getAndIncrement()).getClass());
	assertEquals(Jackson2JsonEncoder.class, getNextEncoder(writers).getClass());
	assertEquals(Jackson2SmileEncoder.class, getNextEncoder(writers).getClass());
	assertEquals(Jaxb2XmlEncoder.class, getNextEncoder(writers).getClass());
	assertStringEncoder(getNextEncoder(writers), false);
}
 
Example #3
Source File: BodyInsertersTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Before
public void createContext() {
	final List<HttpMessageWriter<?>> messageWriters = new ArrayList<>();
	messageWriters.add(new EncoderHttpMessageWriter<>(new ByteBufferEncoder()));
	messageWriters.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.textPlainOnly()));
	messageWriters.add(new ResourceHttpMessageWriter());
	messageWriters.add(new EncoderHttpMessageWriter<>(new Jaxb2XmlEncoder()));
	Jackson2JsonEncoder jsonEncoder = new Jackson2JsonEncoder();
	messageWriters.add(new EncoderHttpMessageWriter<>(jsonEncoder));
	messageWriters.add(new ServerSentEventHttpMessageWriter(jsonEncoder));
	messageWriters.add(new FormHttpMessageWriter());
	messageWriters.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.allMimeTypes()));
	messageWriters.add(new MultipartHttpMessageWriter(messageWriters));

	this.context = new BodyInserter.Context() {
		@Override
		public List<HttpMessageWriter<?>> messageWriters() {
			return messageWriters;
		}
		@Override
		public Optional<ServerHttpRequest> serverRequest() {
			return Optional.empty();
		}
		@Override
		public Map<String, Object> hints() {
			return hints;
		}
	};
	this.hints = new HashMap<>();
}
 
Example #4
Source File: RequestPartMethodArgumentResolverTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Before
public void setup() throws Exception {
	List<HttpMessageReader<?>> readers = ServerCodecConfigurer.create().getReaders();
	ReactiveAdapterRegistry registry = ReactiveAdapterRegistry.getSharedInstance();
	this.resolver = new RequestPartMethodArgumentResolver(readers, registry);

	List<HttpMessageWriter<?>> writers = ClientCodecConfigurer.create().getWriters();
	this.writer = new MultipartHttpMessageWriter(writers);
}
 
Example #5
Source File: ClientDefaultCodecsImpl.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
protected void extendTypedWriters(List<HttpMessageWriter<?>> typedWriters) {

	FormHttpMessageWriter formWriter = new FormHttpMessageWriter();
	formWriter.setEnableLoggingRequestDetails(isEnableLoggingRequestDetails());

	MultipartHttpMessageWriter multipartWriter = new MultipartHttpMessageWriter(getPartWriters(), formWriter);
	multipartWriter.setEnableLoggingRequestDetails(isEnableLoggingRequestDetails());

	typedWriters.add(multipartWriter);
}
 
Example #6
Source File: WebExchangeDataBinderTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private ServerWebExchange exchangeMultipart(MultiValueMap<String, ?> multipartData) {

		MockClientHttpRequest request = new MockClientHttpRequest(HttpMethod.POST, "/");

		new MultipartHttpMessageWriter().write(Mono.just(multipartData), forClass(MultiValueMap.class),
				MediaType.MULTIPART_FORM_DATA, request, Collections.emptyMap()).block();

		return MockServerWebExchange.from(MockServerHttpRequest
				.post("/")
				.contentType(request.getHeaders().getContentType())
				.body(request.getBody()));
	}
 
Example #7
Source File: CancelWithoutDemandCodecTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test // gh-22107
public void cancelWithMultipartContent() {
	MultipartBodyBuilder builder = new MultipartBodyBuilder();
	builder.part("part1", "value1");
	builder.part("part2", "value2");

	List<HttpMessageWriter<?>> writers = ClientCodecConfigurer.create().getWriters();
	MultipartHttpMessageWriter writer = new MultipartHttpMessageWriter(writers);
	CancellingOutputMessage outputMessage = new CancellingOutputMessage(this.bufferFactory);

	writer.write(Mono.just(builder.build()), null, MediaType.MULTIPART_FORM_DATA,
			outputMessage, Collections.emptyMap()).block(Duration.ofSeconds(5));
}
 
Example #8
Source File: BodyInsertersTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Before
public void createContext() {
	final List<HttpMessageWriter<?>> messageWriters = new ArrayList<>();
	messageWriters.add(new EncoderHttpMessageWriter<>(new ByteBufferEncoder()));
	messageWriters.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.textPlainOnly()));
	messageWriters.add(new ResourceHttpMessageWriter());
	messageWriters.add(new EncoderHttpMessageWriter<>(new Jaxb2XmlEncoder()));
	Jackson2JsonEncoder jsonEncoder = new Jackson2JsonEncoder();
	messageWriters.add(new EncoderHttpMessageWriter<>(jsonEncoder));
	messageWriters.add(new ServerSentEventHttpMessageWriter(jsonEncoder));
	messageWriters.add(new FormHttpMessageWriter());
	messageWriters.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.allMimeTypes()));
	messageWriters.add(new MultipartHttpMessageWriter(messageWriters));

	this.context = new BodyInserter.Context() {
		@Override
		public List<HttpMessageWriter<?>> messageWriters() {
			return messageWriters;
		}
		@Override
		public Optional<ServerHttpRequest> serverRequest() {
			return Optional.empty();
		}
		@Override
		public Map<String, Object> hints() {
			return hints;
		}
	};
	this.hints = new HashMap<>();
}
 
Example #9
Source File: RequestPartMethodArgumentResolverTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Before
public void setup() throws Exception {
	List<HttpMessageReader<?>> readers = ServerCodecConfigurer.create().getReaders();
	ReactiveAdapterRegistry registry = ReactiveAdapterRegistry.getSharedInstance();
	this.resolver = new RequestPartMethodArgumentResolver(readers, registry);

	List<HttpMessageWriter<?>> writers = ClientCodecConfigurer.create().getWriters();
	this.writer = new MultipartHttpMessageWriter(writers);
}
 
Example #10
Source File: ClientDefaultCodecsImpl.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
protected void extendTypedWriters(List<HttpMessageWriter<?>> typedWriters) {

	FormHttpMessageWriter formWriter = new FormHttpMessageWriter();
	formWriter.setEnableLoggingRequestDetails(isEnableLoggingRequestDetails());

	MultipartHttpMessageWriter multipartWriter = new MultipartHttpMessageWriter(getPartWriters(), formWriter);
	multipartWriter.setEnableLoggingRequestDetails(isEnableLoggingRequestDetails());

	typedWriters.add(multipartWriter);
}
 
Example #11
Source File: WebExchangeDataBinderTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
private ServerWebExchange exchangeMultipart(MultiValueMap<String, ?> multipartData) {

		MockClientHttpRequest request = new MockClientHttpRequest(HttpMethod.POST, "/");

		new MultipartHttpMessageWriter().write(Mono.just(multipartData), forClass(MultiValueMap.class),
				MediaType.MULTIPART_FORM_DATA, request, Collections.emptyMap()).block();

		return MockServerWebExchange.from(MockServerHttpRequest
				.post("/")
				.contentType(request.getHeaders().getContentType())
				.body(request.getBody()));
	}
 
Example #12
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()));
	}
}