Java Code Examples for reactor.core.publisher.Mono#justOrEmpty()
The following examples show how to use
reactor.core.publisher.Mono#justOrEmpty() .
These examples are extracted from open source projects.
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 Project: java-technology-stack File: ModelAttributeMethodArgumentResolver.java License: MIT License | 6 votes |
private Mono<?> prepareAttributeMono(String attributeName, ResolvableType attributeType, BindingContext context, ServerWebExchange exchange) { Object attribute = context.getModel().asMap().get(attributeName); if (attribute == null) { attribute = findAndRemoveReactiveAttribute(context.getModel(), attributeName); } if (attribute == null) { return createAttribute(attributeName, attributeType.toClass(), context, exchange); } ReactiveAdapter adapterFrom = getAdapterRegistry().getAdapter(null, attribute); if (adapterFrom != null) { Assert.isTrue(!adapterFrom.isMultiValue(), "Data binding only supports single-value async types"); return Mono.from(adapterFrom.toPublisher(attribute)); } else { return Mono.justOrEmpty(attribute); } }
Example 2
Source Project: james-project File: JWTAuthenticationStrategy.java License: Apache License 2.0 | 6 votes |
@Override public Mono<MailboxSession> createMailboxSession(HttpServerRequest httpRequest) throws MailboxSessionCreationException { Stream<Username> userLoginStream = extractTokensFromAuthHeaders(authHeaders(httpRequest)) .filter(tokenManager::verify) .map(tokenManager::extractLogin) .map(Username::of) .peek(username -> { try { usersRepository.assertValid(username); } catch (UsersRepositoryException e) { throw new MailboxSessionCreationException(e); } }); Stream<MailboxSession> mailboxSessionStream = userLoginStream .map(mailboxManager::createSystemSession); return Mono.justOrEmpty(mailboxSessionStream.findFirst()); }
Example 3
Source Project: alibaba-rsocket-broker File: ReactiveAdapterDefault.java License: Apache License 2.0 | 5 votes |
@Override public <T> Mono<T> toMono(@Nullable Object source) { if (source instanceof Mono) { return (Mono) source; } else if (source instanceof Publisher) { return Mono.from((Publisher) source); } else { return (Mono<T>) Mono.justOrEmpty(source); } }
Example 4
Source Project: Spring-5.0-Cookbook File: LoginHandler.java License: MIT License | 5 votes |
public Mono<ServerResponse> countLogins(ServerRequest req) { Mono<Long> count = Flux.fromIterable(logindetailsServiceImpl.findAllLogindetails()) .count(); TotalUsers countEmp = new TotalUsers(); countEmp.setCount(count.block()); Mono<TotalUsers> monoCntLogins = Mono.justOrEmpty(countEmp); return ok().contentType(MediaType.APPLICATION_STREAM_JSON).body(monoCntLogins, TotalUsers.class) .switchIfEmpty(ServerResponse.notFound().build()); }
Example 5
Source Project: Spring-5.0-Cookbook File: DeptDataHandler.java License: MIT License | 5 votes |
public Mono<ServerResponse> countDepts(ServerRequest req) { Mono<Long> count = Flux.fromIterable(departmentServiceImpl.findAllDepts()) .count(); CountDept countDept = new CountDept(); countDept.setCount(count.block()); Mono<CountDept> monoCntDept = Mono.justOrEmpty(countDept); return ok().contentType(MediaType.APPLICATION_STREAM_JSON).body(monoCntDept, CountDept.class) .switchIfEmpty(ServerResponse.notFound().build()); }
Example 6
Source Project: tutorials File: CustomWebSecurityConfig.java License: MIT License | 5 votes |
public Mono<String> customer(Authentication authentication) { return Mono.justOrEmpty(authentication .getPrincipal() .toString() .startsWith("customer") ? authentication .getPrincipal() .toString() : null); }
Example 7
Source Project: spring-cloud-deployer-cloudfoundry File: CloudFoundryAppSchedulerTests.java License: Apache License 2.0 | 5 votes |
@Override public Mono<Void> delete(DeleteJobRequest request) { for (int i = 0; i < this.jobResources.size(); i++) { if (this.jobResources.get(i).getId().equals(request.getJobId())) { jobResources.remove(i); break; } } return Mono.justOrEmpty(null); }
Example 8
Source Project: crnk-framework File: ReactiveProjectToTasksRepository.java License: Apache License 2.0 | 5 votes |
@Override public Mono<Void> removeRelations(ReactiveProject source, Collection<Long> targetIds, ResourceField field) { ArrayList<Long> ids = new ArrayList<>(); if (relationMap.containsKey(source.getId())) { ids.addAll(relationMap.getList(source.getId())); } ids.removeAll(targetIds); relationMap.set(source.getId(), ids); return Mono.justOrEmpty(null); }
Example 9
Source Project: Spring-5.0-Cookbook File: DataHandler.java License: MIT License | 5 votes |
public Mono<ServerResponse> countEmps(ServerRequest req) { Mono<Long> count = Flux.fromIterable(employeeServiceImpl.findAllEmps()) .count(); CountEmp countEmp = new CountEmp(); countEmp.setCount(count.block()); Mono<CountEmp> monoCntEmp = Mono.justOrEmpty(countEmp); return ok().contentType(MediaType.APPLICATION_STREAM_JSON).body(monoCntEmp, CountEmp.class) .switchIfEmpty(ServerResponse.notFound().build()); }
Example 10
Source Project: spring-cloud-open-service-broker File: BeanCatalogService.java License: Apache License 2.0 | 4 votes |
@Override public Mono<ServiceDefinition> getServiceDefinition(final String serviceId) { return Mono.justOrEmpty(serviceDefs.get(serviceId)); }
Example 11
Source Project: crnk-framework File: ReactiveTaskToProjectRepository.java License: Apache License 2.0 | 4 votes |
@Override public Mono<Void> setRelation(ReactiveTask source, Long targetId, ResourceField field) { relationMap.put(source.getId(), targetId); return Mono.justOrEmpty(null); }
Example 12
Source Project: spring-analysis-note File: AbstractNamedValueSyncArgumentResolver.java License: MIT License | 4 votes |
@Override protected final Mono<Object> resolveName(String name, MethodParameter param, ServerWebExchange exchange) { return Mono.justOrEmpty(resolveNamedValue(name, param, exchange)); }
Example 13
Source Project: Building-RESTful-Web-Services-with-Spring-5-Second-Edition File: UserRepositorySample.java License: MIT License | 4 votes |
@Override public Mono<User> getUser(Integer id){ return Mono.justOrEmpty(this.users.get(id)); }
Example 14
Source Project: java-technology-stack File: AbstractNamedValueSyncArgumentResolver.java License: MIT License | 4 votes |
@Override protected final Mono<Object> resolveName(String name, MethodParameter param, ServerWebExchange exchange) { return Mono.justOrEmpty(resolveNamedValue(name, param, exchange)); }
Example 15
Source Project: spring-5-examples File: MovieService.java License: MIT License | 4 votes |
public Mono<Movie> getById(final String id) { return Mono.justOrEmpty(repository.findById(id)); // return repository.findById(id); }
Example 16
Source Project: spring-analysis-note File: AbstractReactiveTransactionAspectTests.java License: MIT License | 4 votes |
@Override public Mono<String> getName() { return Mono.justOrEmpty(name); }
Example 17
Source Project: spring-analysis-note File: MockServerRequest.java License: MIT License | 4 votes |
@Override public Mono<WebSession> session() { return Mono.justOrEmpty(this.session); }
Example 18
Source Project: jetlinks-community File: TopicPart.java License: Apache License 2.0 | 4 votes |
public Mono<TopicPart> get(String topic) { return Mono.justOrEmpty(getOrDefault(topic, ((topicPart, s) -> null))); }
Example 19
Source Project: Spring-Boot-Book File: UserController.java License: Apache License 2.0 | 2 votes |
/** * 获取单个用户 * * @param id * @return */ @GetMapping("/{id}") public Mono<User> getUser(@PathVariable Long id) { return Mono.justOrEmpty(users.get(id)); }
Example 20
Source Project: spring-analysis-note File: SyncHandlerMethodArgumentResolver.java License: MIT License | 2 votes |
/** * {@inheritDoc} * <p>By default this simply delegates to {@link #resolveArgumentValue} for * synchronous resolution. */ @Override default Mono<Object> resolveArgument(MethodParameter parameter, Message<?> message) { return Mono.justOrEmpty(resolveArgumentValue(parameter, message)); }