org.springframework.http.codec.EncoderHttpMessageWriter Java Examples

The following examples show how to use org.springframework.http.codec.EncoderHttpMessageWriter. 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 writers (JSON, XML, SSE).
 * @param forMultipart whether to returns writers for general use ("false"),
 * or for multipart requests only ("true"). Generally the two sets are the
 * same except for the multipart writer itself.
 */
final List<HttpMessageWriter<?>> getObjectWriters(boolean forMultipart) {
	if (!this.registerDefaults) {
		return Collections.emptyList();
	}
	List<HttpMessageWriter<?>> writers = new ArrayList<>();
	if (jackson2Present) {
		writers.add(new EncoderHttpMessageWriter<>(getJackson2JsonEncoder()));
	}
	if (jackson2SmilePresent) {
		writers.add(new EncoderHttpMessageWriter<>(new Jackson2SmileEncoder()));
	}
	if (jaxb2Present) {
		Encoder<?> encoder = this.jaxb2Encoder != null ? this.jaxb2Encoder : new Jaxb2XmlEncoder();
		writers.add(new EncoderHttpMessageWriter<>(encoder));
	}
	// No client or server specific multipart writers currently..
	if (!forMultipart) {
		extendObjectWriters(writers);
	}
	return writers;
}
 
Example #2
Source File: DefaultClientRequestBuilderTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void bodyClass() {
	String body = "foo";
	Publisher<String> publisher = Mono.just(body);
	ClientRequest result = ClientRequest.create(POST, URI.create("https://example.com"))
			.body(publisher, String.class).build();

	List<HttpMessageWriter<?>> messageWriters = new ArrayList<>();
	messageWriters.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.allMimeTypes()));

	ExchangeStrategies strategies = mock(ExchangeStrategies.class);
	given(strategies.messageWriters()).willReturn(messageWriters);

	MockClientHttpRequest request = new MockClientHttpRequest(GET, "/");
	result.writeTo(request, strategies).block();
	assertNotNull(request.getBody());

	StepVerifier.create(request.getBody())
			.expectNextCount(1)
			.verifyComplete();
}
 
Example #3
Source File: DefaultClientRequestBuilderTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void bodyParameterizedTypeReference() {
	String body = "foo";
	Publisher<String> publisher = Mono.just(body);
	ParameterizedTypeReference<String> typeReference = new ParameterizedTypeReference<String>() {};
	ClientRequest result = ClientRequest.create(POST, URI.create("https://example.com"))
			.body(publisher, typeReference).build();

	List<HttpMessageWriter<?>> messageWriters = new ArrayList<>();
	messageWriters.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.allMimeTypes()));

	ExchangeStrategies strategies = mock(ExchangeStrategies.class);
	given(strategies.messageWriters()).willReturn(messageWriters);

	MockClientHttpRequest request = new MockClientHttpRequest(GET, "/");
	result.writeTo(request, strategies).block();
	assertNotNull(request.getBody());

	StepVerifier.create(request.getBody())
			.expectNextCount(1)
			.verifyComplete();
}
 
Example #4
Source File: MessageWriterResultHandlerTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
private AbstractMessageWriterResultHandler initResultHandler(HttpMessageWriter<?>... writers) {
	List<HttpMessageWriter<?>> writerList;
	if (ObjectUtils.isEmpty(writers)) {
		writerList = new ArrayList<>();
		writerList.add(new EncoderHttpMessageWriter<>(new ByteBufferEncoder()));
		writerList.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.allMimeTypes()));
		writerList.add(new ResourceHttpMessageWriter());
		writerList.add(new EncoderHttpMessageWriter<>(new Jaxb2XmlEncoder()));
		writerList.add(new EncoderHttpMessageWriter<>(new Jackson2JsonEncoder()));
	}
	else {
		writerList = Arrays.asList(writers);
	}
	RequestedContentTypeResolver resolver = new RequestedContentTypeResolverBuilder().build();
	return new AbstractMessageWriterResultHandler(writerList, resolver) {};
}
 
Example #5
Source File: BaseDefaultCodecs.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Return writers that support specific types.
 * @param forMultipart whether to returns writers for general use ("false"),
 * or for multipart requests only ("true"). Generally the two sets are the
 * same except for the multipart writer itself.
 */
@SuppressWarnings("unchecked")
final List<HttpMessageWriter<?>> getTypedWriters(boolean forMultipart) {
	if (!this.registerDefaults) {
		return Collections.emptyList();
	}
	List<HttpMessageWriter<?>> writers = new ArrayList<>();
	writers.add(new EncoderHttpMessageWriter<>(new ByteArrayEncoder()));
	writers.add(new EncoderHttpMessageWriter<>(new ByteBufferEncoder()));
	writers.add(new EncoderHttpMessageWriter<>(new DataBufferEncoder()));
	writers.add(new ResourceHttpMessageWriter());
	writers.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.textPlainOnly()));
	// No client or server specific multipart writers currently..
	if (!forMultipart) {
		extendTypedWriters(writers);
	}
	if (protobufPresent) {
		Encoder<?> encoder = this.protobufEncoder != null ? this.protobufEncoder : new ProtobufEncoder();
		writers.add(new ProtobufHttpMessageWriter((Encoder) encoder));
	}
	return writers;
}
 
Example #6
Source File: ResponseEntityResultHandlerTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private ResponseEntityResultHandler createHandler(HttpMessageWriter<?>... writers) {
	List<HttpMessageWriter<?>> writerList;
	if (ObjectUtils.isEmpty(writers)) {
		writerList = new ArrayList<>();
		writerList.add(new EncoderHttpMessageWriter<>(new ByteBufferEncoder()));
		writerList.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.textPlainOnly()));
		writerList.add(new ResourceHttpMessageWriter());
		writerList.add(new EncoderHttpMessageWriter<>(new Jaxb2XmlEncoder()));
		writerList.add(new EncoderHttpMessageWriter<>(new Jackson2JsonEncoder()));
		writerList.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.allMimeTypes()));
	}
	else {
		writerList = Arrays.asList(writers);
	}
	RequestedContentTypeResolver resolver = new RequestedContentTypeResolverBuilder().build();
	return new ResponseEntityResultHandler(writerList, resolver);
}
 
Example #7
Source File: ResponseEntityResultHandlerTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
private ResponseEntityResultHandler createHandler(HttpMessageWriter<?>... writers) {
	List<HttpMessageWriter<?>> writerList;
	if (ObjectUtils.isEmpty(writers)) {
		writerList = new ArrayList<>();
		writerList.add(new EncoderHttpMessageWriter<>(new ByteBufferEncoder()));
		writerList.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.textPlainOnly()));
		writerList.add(new ResourceHttpMessageWriter());
		writerList.add(new EncoderHttpMessageWriter<>(new Jaxb2XmlEncoder()));
		writerList.add(new EncoderHttpMessageWriter<>(new Jackson2JsonEncoder()));
		writerList.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.allMimeTypes()));
	}
	else {
		writerList = Arrays.asList(writers);
	}
	RequestedContentTypeResolver resolver = new RequestedContentTypeResolverBuilder().build();
	return new ResponseEntityResultHandler(writerList, resolver);
}
 
Example #8
Source File: MessageWriterResultHandlerTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private AbstractMessageWriterResultHandler initResultHandler(HttpMessageWriter<?>... writers) {
	List<HttpMessageWriter<?>> writerList;
	if (ObjectUtils.isEmpty(writers)) {
		writerList = new ArrayList<>();
		writerList.add(new EncoderHttpMessageWriter<>(new ByteBufferEncoder()));
		writerList.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.allMimeTypes()));
		writerList.add(new ResourceHttpMessageWriter());
		writerList.add(new EncoderHttpMessageWriter<>(new Jaxb2XmlEncoder()));
		writerList.add(new EncoderHttpMessageWriter<>(new Jackson2JsonEncoder()));
	}
	else {
		writerList = Arrays.asList(writers);
	}
	RequestedContentTypeResolver resolver = new RequestedContentTypeResolverBuilder().build();
	return new AbstractMessageWriterResultHandler(writerList, resolver) {};
}
 
Example #9
Source File: DefaultClientRequestBuilderTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void bodyClass() {
	String body = "foo";
	Publisher<String> publisher = Mono.just(body);
	ClientRequest result = ClientRequest.create(POST, URI.create("http://example.com"))
			.body(publisher, String.class).build();

	List<HttpMessageWriter<?>> messageWriters = new ArrayList<>();
	messageWriters.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.allMimeTypes()));

	ExchangeStrategies strategies = mock(ExchangeStrategies.class);
	when(strategies.messageWriters()).thenReturn(messageWriters);

	MockClientHttpRequest request = new MockClientHttpRequest(GET, "/");
	result.writeTo(request, strategies).block();
	assertNotNull(request.getBody());

	StepVerifier.create(request.getBody())
			.expectNextCount(1)
			.verifyComplete();
}
 
Example #10
Source File: BaseDefaultCodecs.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Return writers that support specific types.
 * @param forMultipart whether to returns writers for general use ("false"),
 * or for multipart requests only ("true"). Generally the two sets are the
 * same except for the multipart writer itself.
 */
@SuppressWarnings("unchecked")
final List<HttpMessageWriter<?>> getTypedWriters(boolean forMultipart) {
	if (!this.registerDefaults) {
		return Collections.emptyList();
	}
	List<HttpMessageWriter<?>> writers = new ArrayList<>();
	writers.add(new EncoderHttpMessageWriter<>(new ByteArrayEncoder()));
	writers.add(new EncoderHttpMessageWriter<>(new ByteBufferEncoder()));
	writers.add(new EncoderHttpMessageWriter<>(new DataBufferEncoder()));
	writers.add(new ResourceHttpMessageWriter());
	writers.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.textPlainOnly()));
	// No client or server specific multipart writers currently..
	if (!forMultipart) {
		extendTypedWriters(writers);
	}
	if (protobufPresent) {
		Encoder<?> encoder = this.protobufEncoder != null ? this.protobufEncoder : new ProtobufEncoder();
		writers.add(new ProtobufHttpMessageWriter((Encoder) encoder));
	}
	return writers;
}
 
Example #11
Source File: BaseDefaultCodecs.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Return Object writers (JSON, XML, SSE).
 * @param forMultipart whether to returns writers for general use ("false"),
 * or for multipart requests only ("true"). Generally the two sets are the
 * same except for the multipart writer itself.
 */
final List<HttpMessageWriter<?>> getObjectWriters(boolean forMultipart) {
	if (!this.registerDefaults) {
		return Collections.emptyList();
	}
	List<HttpMessageWriter<?>> writers = new ArrayList<>();
	if (jackson2Present) {
		writers.add(new EncoderHttpMessageWriter<>(getJackson2JsonEncoder()));
	}
	if (jackson2SmilePresent) {
		writers.add(new EncoderHttpMessageWriter<>(new Jackson2SmileEncoder()));
	}
	if (jaxb2Present) {
		Encoder<?> encoder = this.jaxb2Encoder != null ? this.jaxb2Encoder : new Jaxb2XmlEncoder();
		writers.add(new EncoderHttpMessageWriter<>(encoder));
	}
	// No client or server specific multipart writers currently..
	if (!forMultipart) {
		extendObjectWriters(writers);
	}
	return writers;
}
 
Example #12
Source File: DefaultClientRequestBuilderTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void bodyParameterizedTypeReference() {
	String body = "foo";
	Publisher<String> publisher = Mono.just(body);
	ParameterizedTypeReference<String> typeReference = new ParameterizedTypeReference<String>() {};
	ClientRequest result = ClientRequest.create(POST, URI.create("http://example.com"))
			.body(publisher, typeReference).build();

	List<HttpMessageWriter<?>> messageWriters = new ArrayList<>();
	messageWriters.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.allMimeTypes()));

	ExchangeStrategies strategies = mock(ExchangeStrategies.class);
	when(strategies.messageWriters()).thenReturn(messageWriters);

	MockClientHttpRequest request = new MockClientHttpRequest(GET, "/");
	result.writeTo(request, strategies).block();
	assertNotNull(request.getBody());

	StepVerifier.create(request.getBody())
			.expectNextCount(1)
			.verifyComplete();
}
 
Example #13
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 #14
Source File: MultipartHttpMessageWriter.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Constructor with a default list of part writers (String and Resource).
 */
public MultipartHttpMessageWriter() {
	this(Arrays.asList(
			new EncoderHttpMessageWriter<>(CharSequenceEncoder.textPlainOnly()),
			new ResourceHttpMessageWriter()
	));
}
 
Example #15
Source File: DefaultEntityResponseBuilderTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void bodyInserter() {
	String body = "foo";
	Publisher<String> publisher = Mono.just(body);

	Mono<EntityResponse<Publisher<String>>> result = EntityResponse.fromPublisher(publisher, String.class).build();

	MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("http://localhost"));

	ServerResponse.Context context = new ServerResponse.Context() {
		@Override
		public List<HttpMessageWriter<?>> messageWriters() {
			return Collections.singletonList(new EncoderHttpMessageWriter<>(CharSequenceEncoder.allMimeTypes()));
		}

		@Override
		public List<ViewResolver> viewResolvers() {
			return Collections.emptyList();
		}
	};
	StepVerifier.create(result)
			.consumeNextWith(response -> {
				StepVerifier.create(response.entity())
						.expectNext(body)
						.expectComplete()
						.verify();
				response.writeTo(exchange, context);
			})
			.expectComplete()
			.verify();

	assertNotNull(exchange.getResponse().getBody());
}
 
Example #16
Source File: CodecConfigurerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
private void assertEncoderInstance(Encoder<?> encoder) {
	assertSame(encoder, this.configurer.getWriters().stream()
			.filter(writer -> writer instanceof EncoderHttpMessageWriter)
			.map(writer -> ((EncoderHttpMessageWriter<?>) writer).getEncoder())
			.filter(e -> encoder.getClass().equals(e.getClass()))
			.findFirst()
			.filter(e -> e == encoder).orElse(null));
}
 
Example #17
Source File: ResponseBodyResultHandlerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Before
public void setup() throws Exception {
	List<HttpMessageWriter<?>> writerList = new ArrayList<>(5);
	writerList.add(new EncoderHttpMessageWriter<>(new ByteBufferEncoder()));
	writerList.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.allMimeTypes()));
	writerList.add(new ResourceHttpMessageWriter());
	writerList.add(new EncoderHttpMessageWriter<>(new Jaxb2XmlEncoder()));
	writerList.add(new EncoderHttpMessageWriter<>(new Jackson2JsonEncoder()));
	RequestedContentTypeResolver resolver = new RequestedContentTypeResolverBuilder().build();
	this.resultHandler = new ResponseBodyResultHandler(writerList, resolver);
}
 
Example #18
Source File: MessageWriterResultHandlerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test  // SPR-13135
public void unsupportedReturnType() throws Exception {
	ByteArrayOutputStream body = new ByteArrayOutputStream();
	MethodParameter type = on(TestController.class).resolveReturnType(OutputStream.class);

	HttpMessageWriter<?> writer = new EncoderHttpMessageWriter<>(new ByteBufferEncoder());
	Mono<Void> mono = initResultHandler(writer).writeBody(body, type, this.exchange);

	StepVerifier.create(mono).expectError(IllegalStateException.class).verify();
}
 
Example #19
Source File: BaseDefaultCodecs.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Return writers that need to be at the end, after all others.
 */
List<HttpMessageWriter<?>> getCatchAllWriters() {
	if (!this.registerDefaults) {
		return Collections.emptyList();
	}
	List<HttpMessageWriter<?>> result = new ArrayList<>();
	result.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.allMimeTypes()));
	return result;
}
 
Example #20
Source File: CodecConfigurerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private void assertEncoderInstance(Encoder<?> encoder) {
	assertSame(encoder, this.configurer.getWriters().stream()
			.filter(writer -> writer instanceof EncoderHttpMessageWriter)
			.map(writer -> ((EncoderHttpMessageWriter<?>) writer).getEncoder())
			.filter(e -> encoder.getClass().equals(e.getClass()))
			.findFirst()
			.filter(e -> e == encoder).orElse(null));
}
 
Example #21
Source File: BaseDefaultCodecs.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Return writers that need to be at the end, after all others.
 */
List<HttpMessageWriter<?>> getCatchAllWriters() {
	if (!this.registerDefaults) {
		return Collections.emptyList();
	}
	List<HttpMessageWriter<?>> result = new ArrayList<>();
	result.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.allMimeTypes()));
	return result;
}
 
Example #22
Source File: MultipartHttpMessageWriter.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Constructor with a default list of part writers (String and Resource).
 */
public MultipartHttpMessageWriter() {
	this(Arrays.asList(
			new EncoderHttpMessageWriter<>(CharSequenceEncoder.textPlainOnly()),
			new ResourceHttpMessageWriter()
	));
}
 
Example #23
Source File: MessageWriterResultHandlerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test  // SPR-13135
public void unsupportedReturnType() throws Exception {
	ByteArrayOutputStream body = new ByteArrayOutputStream();
	MethodParameter type = on(TestController.class).resolveReturnType(OutputStream.class);

	HttpMessageWriter<?> writer = new EncoderHttpMessageWriter<>(new ByteBufferEncoder());
	Mono<Void> mono = initResultHandler(writer).writeBody(body, type, this.exchange);

	StepVerifier.create(mono).expectError(IllegalStateException.class).verify();
}
 
Example #24
Source File: ResponseBodyResultHandlerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Before
public void setup() throws Exception {
	List<HttpMessageWriter<?>> writerList = new ArrayList<>(5);
	writerList.add(new EncoderHttpMessageWriter<>(new ByteBufferEncoder()));
	writerList.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.allMimeTypes()));
	writerList.add(new ResourceHttpMessageWriter());
	writerList.add(new EncoderHttpMessageWriter<>(new Jaxb2XmlEncoder()));
	writerList.add(new EncoderHttpMessageWriter<>(new Jackson2JsonEncoder()));
	RequestedContentTypeResolver resolver = new RequestedContentTypeResolverBuilder().build();
	this.resultHandler = new ResponseBodyResultHandler(writerList, resolver);
}
 
Example #25
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 #26
Source File: DefaultEntityResponseBuilderTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void bodyInserter() {
	String body = "foo";
	Publisher<String> publisher = Mono.just(body);

	Mono<EntityResponse<Publisher<String>>> result = EntityResponse.fromPublisher(publisher, String.class).build();

	MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("http://localhost"));

	ServerResponse.Context context = new ServerResponse.Context() {
		@Override
		public List<HttpMessageWriter<?>> messageWriters() {
			return Collections.singletonList(new EncoderHttpMessageWriter<>(CharSequenceEncoder.allMimeTypes()));
		}

		@Override
		public List<ViewResolver> viewResolvers() {
			return Collections.emptyList();
		}
	};
	StepVerifier.create(result)
			.consumeNextWith(response -> {
				StepVerifier.create(response.entity())
						.expectNext(body)
						.expectComplete()
						.verify();
				response.writeTo(exchange, context);
			})
			.expectComplete()
			.verify();

	assertNotNull(exchange.getResponse().getBody());
}
 
Example #27
Source File: ServerCodecConfigurerTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
private Encoder<?> getNextEncoder(List<HttpMessageWriter<?>> writers) {
	HttpMessageWriter<?> writer = writers.get(this.index.getAndIncrement());
	assertEquals(EncoderHttpMessageWriter.class, writer.getClass());
	return ((EncoderHttpMessageWriter<?>) writer).getEncoder();
}
 
Example #28
Source File: ClientCodecConfigurerTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
private Encoder<?> getNextEncoder(List<HttpMessageWriter<?>> writers) {
	HttpMessageWriter<?> writer = writers.get(this.index.getAndIncrement());
	assertEquals(EncoderHttpMessageWriter.class, writer.getClass());
	return ((EncoderHttpMessageWriter<?>) writer).getEncoder();
}
 
Example #29
Source File: CodecConfigurerTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
private Encoder<?> getNextEncoder(List<HttpMessageWriter<?>> writers) {
	HttpMessageWriter<?> writer = writers.get(this.index.getAndIncrement());
	assertEquals(EncoderHttpMessageWriter.class, writer.getClass());
	return ((EncoderHttpMessageWriter<?>) writer).getEncoder();
}
 
Example #30
Source File: RestApiWebFluxConfiguration.java    From alibaba-rsocket-broker with Apache License 2.0 4 votes vote down vote up
@Override
public void configureHttpMessageCodecs(ServerCodecConfigurer configurer) {
    configurer.customCodecs().register(new EncoderHttpMessageWriter<>(new ByteBufEncoder()));
    configurer.customCodecs().register(new DecoderHttpMessageReader<>(new ByteBufDecoder()));
}