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

The following examples show how to use reactor.core.publisher.Mono#empty() . 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: DefaultServerResponseBuilderTests.java    From spring-analysis-note with MIT License 7 votes vote down vote up
@Test
public void buildVoidPublisher() {
	Mono<Void> mono = Mono.empty();
	Mono<ServerResponse> result = ServerResponse.ok().build(mono);

	MockServerHttpRequest request = MockServerHttpRequest.get("https://example.com").build();
	MockServerWebExchange exchange = MockServerWebExchange.from(request);

	result.flatMap(res -> res.writeTo(exchange, EMPTY_CONTEXT)).block();

	MockServerHttpResponse response = exchange.getResponse();
	StepVerifier.create(response.getBody()).expectComplete().verify();
}
 
Example 2
Source File: CorsWebFilterTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void sameOriginRequest() {
	WebFilterChain filterChain = filterExchange -> {
		try {
			HttpHeaders headers = filterExchange.getResponse().getHeaders();
			assertNull(headers.getFirst(ACCESS_CONTROL_ALLOW_ORIGIN));
			assertNull(headers.getFirst(ACCESS_CONTROL_EXPOSE_HEADERS));
		}
		catch (AssertionError ex) {
			return Mono.error(ex);
		}
		return Mono.empty();

	};
	MockServerWebExchange exchange = MockServerWebExchange.from(
			MockServerHttpRequest
					.get("https://domain1.com/test.html")
					.header(ORIGIN, "https://domain1.com"));
	this.filter.filter(exchange, filterChain).block();
}
 
Example 3
Source File: StaticHttpHeadersWriter.java    From spring-security-reactive with Apache License 2.0 5 votes vote down vote up
@Override
public Mono<Void> writeHttpHeaders(ServerWebExchange exchange) {
	HttpHeaders headers = exchange.getResponse().getHeaders();
	boolean containsOneHeaderToAdd = Collections.disjoint(headers.keySet(), this.headersToAdd.keySet());
	if(containsOneHeaderToAdd) {
		this.headersToAdd.forEach((name, values) -> {
			headers.put(name, values);
		});
	}
	return Mono.empty();
}
 
Example 4
Source File: InMemoryWebSessionStore.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public Mono<Void> invalidate() {
	this.state.set(State.EXPIRED);
	getAttributes().clear();
	InMemoryWebSessionStore.this.sessions.remove(this.id.get());
	return Mono.empty();
}
 
Example 5
Source File: PathResourceResolver.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Find the resource under the given location.
 * <p>The default implementation checks if there is a readable
 * {@code Resource} for the given path relative to the location.
 * @param resourcePath the path to the resource
 * @param location the location to check
 * @return the resource, or empty {@link Mono} if none found
 */
protected Mono<Resource> getResource(String resourcePath, Resource location) {
	try {
		if (location instanceof ClassPathResource) {
			resourcePath = UriUtils.decode(resourcePath, StandardCharsets.UTF_8);
		}
		Resource resource = location.createRelative(resourcePath);
		if (resource.isReadable()) {
			if (checkResource(resource, location)) {
				return Mono.just(resource);
			}
			else if (logger.isWarnEnabled()) {
				Resource[] allowedLocations = getAllowedLocations();
				logger.warn("Resource path \"" + resourcePath + "\" was successfully resolved " +
						"but resource \"" + resource.getURL() + "\" is neither under the " +
						"current location \"" + location.getURL() + "\" nor under any of the " +
						"allowed locations " + (allowedLocations != null ? Arrays.asList(allowedLocations) : "[]"));
			}
		}
		return Mono.empty();
	}
	catch (IOException ex) {
		if (logger.isDebugEnabled()) {
			String error = "Skip location [" + location + "] due to error";
			if (logger.isTraceEnabled()) {
				logger.trace(error, ex);
			}
			else {
				logger.debug(error + ": " + ex.getMessage());
			}
		}
		return Mono.error(ex);
	}
}
 
Example 6
Source File: ServerHttpsRequestIntegrationTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public Mono<Void> handle(ServerHttpRequest request, ServerHttpResponse response) {
	URI uri = request.getURI();
	assertEquals("https", uri.getScheme());
	assertNotNull(uri.getHost());
	assertNotEquals(-1, uri.getPort());
	assertNotNull(request.getRemoteAddress());
	assertEquals("/foo", uri.getPath());
	assertEquals("param=bar", uri.getQuery());
	return Mono.empty();
}
 
Example 7
Source File: DeviceMessageConnector.java    From jetlinks-community with Apache License 2.0 5 votes vote down vote up
public Mono<Void> onMessage(Message message) {
    if (null == message) {
        return Mono.empty();
    }
    if (!messageProcessor.hasDownstreams() && !messageProcessor.isCancelled()) {
        return Mono.empty();
    }

    return this.getTopic(message)
        .map(topic -> TopicMessage.of(topic, message))
        .doOnNext(sink::next)
        .then();
}
 
Example 8
Source File: ChainingStrategyTest.java    From spring-boot-admin with Apache License 2.0 5 votes vote down vote up
@Test
public void should_return_empty_endpoints_when_all_empty() {
	// given
	Instance instance = Instance.create(InstanceId.of("id"));
	ChainingStrategy strategy = new ChainingStrategy((a) -> Mono.empty());
	// when/then
	StepVerifier.create(strategy.detectEndpoints(instance)).expectNext(Endpoints.empty()).verifyComplete();
}
 
Example 9
Source File: GuildMusic.java    From Shadbot with GNU General Public License v3.0 5 votes vote down vote up
public Mono<Void> removeAudioLoadResultListener(AudioLoadResultListener listener) {
    LOGGER.debug("{Guild ID: {}} Removing audio load result listener: {}", this.guildId, listener.hashCode());
    this.listeners.remove(listener);
    // If there is no music playing and nothing is loading, leave the voice channel
    if (this.trackScheduler.isStopped() && this.listeners.values().stream().allMatch(Future::isDone)) {
        return this.gateway.getVoiceConnectionRegistry()
                .getVoiceConnection(Snowflake.of(this.guildId))
                .flatMap(VoiceConnection::disconnect);
    }
    return Mono.empty();
}
 
Example 10
Source File: FakeApiDelegate.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * GET /fake/jsonFormData : test json serialization of form data
 *
 * @param param field1 (required)
 * @param param2 field2 (required)
 * @return successful operation (status code 200)
 * @see FakeApi#testJsonFormData
 */
default Mono<ResponseEntity<Void>> testJsonFormData(String param,
    String param2,
    ServerWebExchange exchange) {
    Mono<Void> result = Mono.empty();
    exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED);
    return result.then(Mono.empty());

}
 
Example 11
Source File: AbstractWebSocketServerHandle.java    From reactor-guice with Apache License 2.0 5 votes vote down vote up
@Override
public Mono<Void> onClose(CloseWebSocketFrame frame, Channel channel) {
    System.out.println("onClose" + channel);
    if (channel.isOpen() && channel.isActive()) {
        channel.close();
    }
    return Mono.empty();
}
 
Example 12
Source File: StepVerifierTests.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
public void verifyTimeoutSmokeTest() {
	Mono<String> neverMono = Mono.never();
	Mono<String> completingMono = Mono.empty();

	StepVerifier.create(neverMono, StepVerifierOptions.create().scenarioName("neverMono should pass"))
			.verifyTimeout(Duration.ofSeconds(1));

	assertThatExceptionOfType(AssertionError.class)
			.isThrownBy(() -> StepVerifier.create(completingMono).verifyTimeout(Duration.ofSeconds(1)))
			.withMessage("expectation \"expectTimeout\" failed (expected: timeout(1s); actual: onComplete())");
}
 
Example 13
Source File: NoOpServiceInstanceService.java    From spring-cloud-open-service-broker with Apache License 2.0 4 votes vote down vote up
@Override
public Mono<UpdateServiceInstanceResponse> updateServiceInstance(UpdateServiceInstanceRequest request) {
	return Mono.empty();
}
 
Example 14
Source File: WebTestClientInitializer.java    From spring-auto-restdocs with Apache License 2.0 4 votes vote down vote up
@Override
public Mono<HandlerResult> handle(ServerWebExchange exchange, Object handler) {
    // nothing to do - handler already registered in #supports(Object)
    return Mono.empty();
}
 
Example 15
Source File: TestRSocket.java    From rsocket-java with Apache License 2.0 4 votes vote down vote up
@Override
public Mono<Void> metadataPush(Payload payload) {
  return Mono.empty();
}
 
Example 16
Source File: HybridBlobStore.java    From james-project with Apache License 2.0 4 votes vote down vote up
private <T> Mono<T> logAndReturnEmpty(Throwable throwable) {
    LOGGER.error("error happens from current blob store, fall back to lowCost blob store", throwable);
    return Mono.empty();
}
 
Example 17
Source File: ServiceInstanceControllerRequestTest.java    From spring-cloud-open-service-broker with Apache License 2.0 4 votes vote down vote up
@Override
public Mono<UpdateServiceInstanceResponse> updateServiceInstance(UpdateServiceInstanceRequest request) {
	assertThat(request).isEqualTo(expectedRequest);
	return Mono.empty();
}
 
Example 18
Source File: BlobCodecTest.java    From r2dbc-mysql with Apache License 2.0 4 votes vote down vote up
@Override
public Mono<Void> discard() {
    return Mono.empty();
}
 
Example 19
Source File: CreateServiceInstanceErrorFlow.java    From spring-cloud-open-service-broker with Apache License 2.0 2 votes vote down vote up
/**
 * Performs the operation on the error flow
 *
 * @param request the service broker request
 * @param t the error
 * @return an empty Mono
 */
default Mono<Void> error(CreateServiceInstanceRequest request, Throwable t) {
	return Mono.empty();
}
 
Example 20
Source File: NettyOutbound.java    From reactor-netty with Apache License 2.0 2 votes vote down vote up
/**
 * Obtains a {@link Mono} of pending outbound(s) write completion.
 *
 * @return a {@link Mono} of pending outbound(s) write completion
 */
default Mono<Void> then() {
	return Mono.empty();
}