Java Code Examples for reactor.core.publisher.Mono#then()

The following examples show how to use reactor.core.publisher.Mono#then() . 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: RandomHandlerIntegrationTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public Mono<Void> handle(ServerHttpRequest request, ServerHttpResponse response) {
	Mono<Integer> requestSizeMono = request.getBody().
			reduce(0, (integer, dataBuffer) -> integer +
					dataBuffer.readableByteCount()).
			doOnSuccessOrError((size, throwable) -> {
				assertNull(throwable);
				assertEquals(REQUEST_SIZE, (long) size);
			});

	response.getHeaders().setContentLength(RESPONSE_SIZE);

	return requestSizeMono.then(response.writeWith(multipleChunks()));
}
 
Example 2
Source File: RequestStream.java    From Discord4J with GNU Lesser General Public License v3.0 5 votes vote down vote up
public RequestSubscriber(RateLimitStrategy strategy) {
    this.responseFunction = response -> {
        HttpClientResponse httpResponse = response.getHttpResponse();
        if (log.isDebugEnabled()) {
            Instant requestTimestamp =
                    Instant.ofEpochMilli(httpResponse.currentContext().get(DiscordWebClient.KEY_REQUEST_TIMESTAMP));
            Duration responseTime = Duration.between(requestTimestamp, Instant.now());
            LogUtil.traceDebug(log, trace -> format(httpResponse.currentContext(),
                    "Read " + httpResponse.status() + " in " + responseTime + (!trace ? "" :
                            " with headers: " + httpResponse.responseHeaders())));
        }
        Duration nextReset = strategy.apply(httpResponse);
        if (!nextReset.isZero()) {
            if (log.isDebugEnabled()) {
                log.debug(format(httpResponse.currentContext(), "Delaying next request by {}"), nextReset);
            }
            sleepTime = nextReset;
        }
        boolean global = Boolean.parseBoolean(httpResponse.responseHeaders().get("X-RateLimit-Global"));
        Mono<Void> action = Mono.empty();
        if (global) {
            long retryAfter = Long.parseLong(httpResponse.responseHeaders().get("Retry-After"));
            Duration fixedBackoff = Duration.ofMillis(retryAfter);
            action = globalRateLimiter.rateLimitFor(fixedBackoff)
                    .doOnTerminate(() -> log.debug(format(httpResponse.currentContext(),
                            "Globally rate limited for {}"), fixedBackoff));
        }
        if (httpResponse.status().code() >= 400) {
            return action.then(response.createException().flatMap(Mono::error));
        } else {
            return action.thenReturn(response);
        }
    };
}
 
Example 3
Source File: FakeApiDelegate.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * PUT /fake/body-with-query-params
 *
 * @param query  (required)
 * @param body  (required)
 * @return Success (status code 200)
 * @see FakeApi#testBodyWithQueryParams
 */
default Mono<ResponseEntity<Void>> testBodyWithQueryParams(String query,
    Mono<User> body,
    ServerWebExchange exchange) {
    Mono<Void> result = Mono.empty();
    exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED);
    return result.then(Mono.empty());

}
 
Example 4
Source File: UserApiDelegate.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * POST /user/createWithList : Creates list of users with given input array
 *
 * @param body List of user object (required)
 * @return successful operation (status code 200)
 * @see UserApi#createUsersWithListInput
 */
default Mono<ResponseEntity<Void>> createUsersWithListInput(Flux<User> body,
    ServerWebExchange exchange) {
    Mono<Void> result = Mono.empty();
    exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED);
    return result.then(Mono.empty());

}
 
Example 5
Source File: FakeApiDelegate.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * POST /fake/outer/composite
 * Test serialization of object with outer number type
 *
 * @param body Input composite as post body (optional)
 * @return Output composite (status code 200)
 * @see FakeApi#fakeOuterCompositeSerialize
 */
default Mono<ResponseEntity<OuterComposite>> fakeOuterCompositeSerialize(Mono<OuterComposite> body,
    ServerWebExchange exchange) {
    Mono<Void> result = Mono.empty();
    exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED);
    for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) {
        if (mediaType.isCompatibleWith(MediaType.valueOf("*/*"))) {
            String exampleString = "{ \"my_string\" : \"my_string\", \"my_number\" : 0.8008281904610115, \"my_boolean\" : true }";
            result = ApiUtil.getExampleResponse(exchange, exampleString);
            break;
        }
    }
    return result.then(Mono.empty());

}
 
Example 6
Source File: FakeClassnameTestApiDelegate.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * PATCH /fake_classname_test : To test class name in snake case
 * To test class name in snake case
 *
 * @param body client model (required)
 * @return successful operation (status code 200)
 * @see FakeClassnameTestApi#testClassname
 */
default Mono<ResponseEntity<Client>> testClassname(Mono<Client> body,
    ServerWebExchange exchange) {
    Mono<Void> result = Mono.empty();
    exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED);
    for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) {
        if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
            String exampleString = "{ \"client\" : \"client\" }";
            result = ApiUtil.getExampleResponse(exchange, exampleString);
            break;
        }
    }
    return result.then(Mono.empty());

}
 
Example 7
Source File: AnotherFakeApiDelegate.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * PATCH /another-fake/dummy : To test special tags
 * To test special tags and operation ID starting with number
 *
 * @param body client model (required)
 * @return successful operation (status code 200)
 * @see AnotherFakeApi#call123testSpecialTags
 */
default Mono<ResponseEntity<Client>> call123testSpecialTags(Mono<Client> body,
    ServerWebExchange exchange) {
    Mono<Void> result = Mono.empty();
    exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED);
    for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) {
        if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
            String exampleString = "{ \"client\" : \"client\" }";
            result = ApiUtil.getExampleResponse(exchange, exampleString);
            break;
        }
    }
    return result.then(Mono.empty());

}
 
Example 8
Source File: UserApiDelegate.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * POST /user/createWithArray : Creates list of users with given input array
 *
 * @param body List of user object (required)
 * @return successful operation (status code 200)
 * @see UserApi#createUsersWithArrayInput
 */
default Mono<ResponseEntity<Void>> createUsersWithArrayInput(Flux<User> body,
    ServerWebExchange exchange) {
    Mono<Void> result = Mono.empty();
    exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED);
    return result.then(Mono.empty());

}
 
Example 9
Source File: BenchmarkReactorServerServiceImpl.java    From reactive-grpc with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public Mono<Messages.SimpleResponse> unaryCall(Mono<Messages.SimpleRequest> request) {
    return request.then(responseMono);
}
 
Example 10
Source File: WebSocketIT.java    From vertx-spring-boot with Apache License 2.0 4 votes vote down vote up
private Mono<Void> doubleProducerHandler(WebSocketSession session) {
    Mono<Void> firstSend = session.send(Mono.just(session.textMessage("ping")));
    Mono<Void> secondSend = session.send(Mono.just(session.textMessage("pong")));

    return firstSend.then(secondSend);
}
 
Example 11
Source File: SimpleHandlerAdapter.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public Mono<HandlerResult> handle(ServerWebExchange exchange, Object handler) {
	WebHandler webHandler = (WebHandler) handler;
	Mono<Void> mono = webHandler.handle(exchange);
	return mono.then(Mono.empty());
}
 
Example 12
Source File: ReactorDebugAgentTest.java    From reactor-core with Apache License 2.0 4 votes vote down vote up
Mono<Void> doSomething() {
	Mono<Void> myMono = new MyMono();
	// Make it think that there were operator calls inside
	myMono.then();
	return myMono;
}
 
Example 13
Source File: FakeApiDelegate.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
/**
 * POST /fake : Fake endpoint for testing various parameters  假端點  偽のエンドポイント  가짜 엔드 포인트
 * Fake endpoint for testing various parameters  假端點  偽のエンドポイント  가짜 엔드 포인트
 *
 * @param number None (required)
 * @param _double None (required)
 * @param patternWithoutDelimiter None (required)
 * @param _byte None (required)
 * @param integer None (optional)
 * @param int32 None (optional)
 * @param int64 None (optional)
 * @param _float None (optional)
 * @param string None (optional)
 * @param binary None (optional)
 * @param date None (optional)
 * @param dateTime None (optional)
 * @param password None (optional)
 * @param paramCallback None (optional)
 * @return Invalid username supplied (status code 400)
 *         or User not found (status code 404)
 * @see FakeApi#testEndpointParameters
 */
default Mono<ResponseEntity<Void>> testEndpointParameters(BigDecimal number,
    Double _double,
    String patternWithoutDelimiter,
    byte[] _byte,
    Integer integer,
    Integer int32,
    Long int64,
    Float _float,
    String string,
    MultipartFile binary,
    LocalDate date,
    OffsetDateTime dateTime,
    String password,
    String paramCallback,
    ServerWebExchange exchange) {
    Mono<Void> result = Mono.empty();
    exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED);
    return result.then(Mono.empty());

}
 
Example 14
Source File: PetApiDelegate.java    From openapi-generator with Apache License 2.0 3 votes vote down vote up
/**
 * DELETE /pet/{petId} : Deletes a pet
 *
 * @param petId Pet id to delete (required)
 * @param apiKey  (optional)
 * @return successful operation (status code 200)
 *         or Invalid pet value (status code 400)
 * @see PetApi#deletePet
 */
default Mono<ResponseEntity<Void>> deletePet(Long petId,
    String apiKey,
    ServerWebExchange exchange) {
    Mono<Void> result = Mono.empty();
    exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED);
    return result.then(Mono.empty());

}
 
Example 15
Source File: StoreApiDelegate.java    From openapi-generator with Apache License 2.0 3 votes vote down vote up
/**
 * DELETE /store/order/{order_id} : Delete purchase order by ID
 * For valid response try integer IDs with value &lt; 1000. Anything above 1000 or nonintegers will generate API errors
 *
 * @param orderId ID of the order that needs to be deleted (required)
 * @return Invalid ID supplied (status code 400)
 *         or Order not found (status code 404)
 * @see StoreApi#deleteOrder
 */
default Mono<ResponseEntity<Void>> deleteOrder(String orderId,
    ServerWebExchange exchange) {
    Mono<Void> result = Mono.empty();
    exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED);
    return result.then(Mono.empty());

}
 
Example 16
Source File: FakeApiDelegate.java    From openapi-generator with Apache License 2.0 3 votes vote down vote up
/**
 * POST /fake/create_xml_item : creates an XmlItem
 * this route creates an XmlItem
 *
 * @param xmlItem XmlItem Body (required)
 * @return successful operation (status code 200)
 * @see FakeApi#createXmlItem
 */
default Mono<ResponseEntity<Void>> createXmlItem(Mono<XmlItem> xmlItem,
    ServerWebExchange exchange) {
    Mono<Void> result = Mono.empty();
    exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED);
    return result.then(Mono.empty());

}
 
Example 17
Source File: UserApiDelegate.java    From openapi-generator with Apache License 2.0 3 votes vote down vote up
/**
 * DELETE /user/{username} : Delete user
 * This can only be done by the logged in user.
 *
 * @param username The name that needs to be deleted (required)
 * @return Invalid username supplied (status code 400)
 *         or User not found (status code 404)
 * @see UserApi#deleteUser
 */
default Mono<ResponseEntity<Void>> deleteUser(String username,
    ServerWebExchange exchange) {
    Mono<Void> result = Mono.empty();
    exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED);
    return result.then(Mono.empty());

}
 
Example 18
Source File: StoreApiDelegate.java    From openapi-generator with Apache License 2.0 3 votes vote down vote up
/**
 * GET /store/inventory : Returns pet inventories by status
 * Returns a map of status codes to quantities
 *
 * @return successful operation (status code 200)
 * @see StoreApi#getInventory
 */
default Mono<ResponseEntity<Map<String, Integer>>> getInventory(ServerWebExchange exchange) {
    Mono<Void> result = Mono.empty();
    exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED);
    return result.then(Mono.empty());

}
 
Example 19
Source File: FakeApiDelegate.java    From openapi-generator with Apache License 2.0 3 votes vote down vote up
/**
 * POST /fake/outer/string
 * Test serialization of outer string types
 *
 * @param body Input string as post body (optional)
 * @return Output string (status code 200)
 * @see FakeApi#fakeOuterStringSerialize
 */
default Mono<ResponseEntity<String>> fakeOuterStringSerialize(Mono<String> body,
    ServerWebExchange exchange) {
    Mono<Void> result = Mono.empty();
    exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED);
    return result.then(Mono.empty());

}
 
Example 20
Source File: FakeApiDelegate.java    From openapi-generator with Apache License 2.0 3 votes vote down vote up
/**
 * PUT /fake/test-query-paramters
 * To test the collection format in query parameters
 *
 * @param pipe  (required)
 * @param ioutil  (required)
 * @param http  (required)
 * @param url  (required)
 * @param context  (required)
 * @return Success (status code 200)
 * @see FakeApi#testQueryParameterCollectionFormat
 */
default Mono<ResponseEntity<Void>> testQueryParameterCollectionFormat(List<String> pipe,
    List<String> ioutil,
    List<String> http,
    List<String> url,
    List<String> context,
    ServerWebExchange exchange) {
    Mono<Void> result = Mono.empty();
    exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED);
    return result.then(Mono.empty());

}