本文整理了Java中reactor.core.publisher.Flux.error()
方法的一些代码示例,展示了Flux.error()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Flux.error()
方法的具体详情如下:
包路径:reactor.core.publisher.Flux
类名称:Flux
方法名:error
[英]Create a Flux that terminates with the specified error immediately after being subscribed to.
[中]创建一个在订阅后立即以指定错误终止的通量。
代码示例来源:origin: spring-projects/spring-framework
public Flux<DataBuffer> getBody() {
return (this.body != null ? this.body :
Flux.error(new IllegalStateException("Body has not been written yet")));
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Configure a custom handler to consume the response body.
* <p>By default, response body content is consumed in full and cached for
* subsequent access in tests. Use this option to take control over how the
* response body is consumed.
* @param writeHandler the write handler to use returning {@code Mono<Void>}
* when the body has been "written" (i.e. consumed).
*/
public void setWriteHandler(Function<Flux<DataBuffer>, Mono<Void>> writeHandler) {
Assert.notNull(writeHandler, "'writeHandler' is required");
this.body = Flux.error(new IllegalStateException("Not available with custom write handler."));
this.writeHandler = writeHandler;
}
代码示例来源:origin: spring-projects/spring-framework
private Flux<TokenBuffer> endOfInput() {
this.inputFeeder.endOfInput();
try {
return parseTokenBufferFlux();
}
catch (JsonProcessingException ex) {
return Flux.error(new DecodingException(
"JSON decoding error: " + ex.getOriginalMessage(), ex));
}
catch (IOException ex) {
return Flux.error(ex);
}
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Configure a custom handler to consume the response body.
* <p>By default, response body content is consumed in full and cached for
* subsequent access in tests. Use this option to take control over how the
* response body is consumed.
* @param writeHandler the write handler to use returning {@code Mono<Void>}
* when the body has been "written" (i.e. consumed).
*/
public void setWriteHandler(Function<Flux<DataBuffer>, Mono<Void>> writeHandler) {
Assert.notNull(writeHandler, "'writeHandler' is required");
this.body = Flux.error(new IllegalStateException("Not available with custom write handler."));
this.writeHandler = writeHandler;
}
代码示例来源:origin: spring-projects/spring-framework
private static <T> Flux<T> unsupportedErrorHandler(
ReactiveHttpInputMessage message, UnsupportedMediaTypeException ex) {
Flux<T> result;
if (message.getHeaders().getContentType() == null) {
// Maybe it's okay there is no content type, if there is no content..
result = message.getBody().map(buffer -> {
DataBufferUtils.release(buffer);
throw ex;
});
}
else {
result = message instanceof ClientHttpResponse ?
consumeAndCancel(message).thenMany(Flux.error(ex)) : Flux.error(ex);
}
return result;
}
代码示例来源:origin: spring-projects/spring-framework
private Flux<TokenBuffer> tokenize(DataBuffer dataBuffer) {
byte[] bytes = new byte[dataBuffer.readableByteCount()];
dataBuffer.read(bytes);
DataBufferUtils.release(dataBuffer);
try {
this.inputFeeder.feedInput(bytes, 0, bytes.length);
return parseTokenBufferFlux();
}
catch (JsonProcessingException ex) {
return Flux.error(new DecodingException(
"JSON decoding error: " + ex.getOriginalMessage(), ex));
}
catch (IOException ex) {
return Flux.error(ex);
}
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public Mono<Void> handle(WebSocketSession session) {
return session.send(Flux
.error(new Throwable())
.onErrorResume(ex -> session.close(CloseStatus.GOING_AWAY)) // SPR-17306 (nested close)
.cast(WebSocketMessage.class));
}
}
代码示例来源:origin: spring-projects/spring-framework
@Override
protected void testEncodeError(Publisher<?> input, ResolvableType outputType,
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
Flux<Resource> i = Flux.error(new InputException());
Flux<DataBuffer> result = ((Encoder<Resource>) this.encoder).encode(i,
this.bufferFactory, outputType,
mimeType, hints);
StepVerifier.create(result)
.expectError(InputException.class)
.verify();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void decodeErrorNonAalto() {
decoder.useAalto = false;
Flux<DataBuffer> source = Flux.concat(
stringBuffer("<pojo>"),
Flux.error(new RuntimeException()));
Flux<XMLEvent> events =
this.decoder.decode(source, null, null, Collections.emptyMap());
StepVerifier.create(events)
.expectError(RuntimeException.class)
.verify();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void encodeError() {
Flux<Pojo> input = Flux.error(RuntimeException::new);
testEncode(input, Pojo.class, step -> step
.expectError(RuntimeException.class)
.verify());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void writeWithError() throws Exception {
TestServerHttpResponse response = new TestServerHttpResponse();
response.getHeaders().setContentLength(12);
IllegalStateException error = new IllegalStateException("boo");
response.writeWith(Flux.error(error)).onErrorResume(ex -> Mono.empty()).block();
assertFalse(response.statusCodeWritten);
assertFalse(response.headersWritten);
assertFalse(response.cookiesWritten);
assertFalse(response.getHeaders().containsKey(HttpHeaders.CONTENT_LENGTH));
assertTrue(response.body.isEmpty());
}
代码示例来源:origin: spring-projects/spring-framework
@Override
protected void testDecodeError(Publisher<DataBuffer> input, ResolvableType outputType,
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
input = Flux.concat(
Flux.from(input).take(1),
Flux.error(new InputException()));
Flux<Resource> result = this.decoder.decode(input, outputType, mimeType, hints);
StepVerifier.create(result)
.expectError(InputException.class)
.verify();
}
代码示例来源:origin: spring-projects/spring-framework
@Override
protected void testDecodeError(Publisher<DataBuffer> input, ResolvableType outputType,
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
input = Flux.concat(
Flux.from(input).take(1),
Flux.error(new InputException()));
Flux<String> result = this.decoder.decode(input, outputType, mimeType, hints);
StepVerifier.create(result)
.expectError(InputException.class)
.verify();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void decodeError() throws Exception {
Flux<DataBuffer> source = Flux.concat(
stringBuffer("<pojo>"),
Flux.error(new RuntimeException()));
Mono<Object> output = this.decoder.decodeToMono(source, ResolvableType.forClass(Pojo.class),
null, Collections.emptyMap());
StepVerifier.create(output)
.expectError(RuntimeException.class)
.verify();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void errorInStream() {
DataBuffer buffer = stringBuffer("{\"id\":1,\"name\":");
Flux<DataBuffer> source = Flux.just(buffer)
.concatWith(Flux.error(new RuntimeException()));
Flux<TokenBuffer> result = Jackson2Tokenizer.tokenize(source, this.jsonFactory, true);
StepVerifier.create(result)
.expectError(RuntimeException.class)
.verify();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void writeWritableByteChannelErrorInFlux() throws Exception {
DataBuffer foo = stringBuffer("foo");
DataBuffer bar = stringBuffer("bar");
Flux<DataBuffer> flux = Flux.just(foo, bar).concatWith(Flux.error(new RuntimeException()));
WritableByteChannel channel = Files.newByteChannel(tempFile, StandardOpenOption.WRITE);
Flux<DataBuffer> writeResult = DataBufferUtils.write(flux, channel);
StepVerifier.create(writeResult)
.consumeNextWith(stringConsumer("foo"))
.consumeNextWith(stringConsumer("bar"))
.expectError()
.verify(Duration.ofSeconds(5));
String result = String.join("", Files.readAllLines(tempFile));
assertEquals("foobar", result);
channel.close();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void readError() {
Flux<DataBuffer> body =
Flux.just(stringBuffer("data:foo\ndata:bar\n\ndata:baz\n\n"))
.concatWith(Flux.error(new RuntimeException()));
MockServerHttpRequest request = MockServerHttpRequest.post("/")
.body(body);
Flux<String> data = messageReader.read(ResolvableType.forClass(String.class),
request, Collections.emptyMap()).cast(String.class);
StepVerifier.create(data)
.expectNextMatches(elem -> elem.equals("foo\nbar"))
.expectNextMatches(elem -> elem.equals("baz"))
.expectError()
.verify();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void readFormError() {
DataBuffer fooBuffer = stringBuffer("name=value");
Flux<DataBuffer> body =
Flux.just(fooBuffer).concatWith(Flux.error(new RuntimeException()));
MockServerHttpRequest request = request(body);
Flux<MultiValueMap<String, String>> result = this.reader.read(null, request, null);
StepVerifier.create(result)
.expectError()
.verify();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void joinErrors() {
DataBuffer foo = stringBuffer("foo");
DataBuffer bar = stringBuffer("bar");
Flux<DataBuffer> flux = Flux.just(foo, bar).concatWith(Flux.error(new RuntimeException()));
Mono<DataBuffer> result = DataBufferUtils.join(flux);
StepVerifier.create(result)
.expectError(RuntimeException.class)
.verify();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void decodeErrorAalto() {
Flux<DataBuffer> source = Flux.concat(
stringBuffer("<pojo>"),
Flux.error(new RuntimeException()));
Flux<XMLEvent> events =
this.decoder.decode(source, null, null, Collections.emptyMap());
StepVerifier.create(events)
.consumeNextWith(e -> assertTrue(e.isStartDocument()))
.consumeNextWith(e -> assertStartElement(e, "pojo"))
.expectError(RuntimeException.class)
.verify();
}
内容来源于网络,如有侵权,请联系作者删除!