Java Code Examples for reactor.core.publisher.Mono#just()
The following examples show how to use
reactor.core.publisher.Mono#just() .
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: VaultNamespaceTests.java From spring-cloud-vault with Apache License 2.0 | 7 votes |
@Test public void shouldReportReactiveHealth() { ReactiveVaultTemplate reactiveMarketing = new ReactiveVaultTemplate( this.marketingWebClientBuilder, () -> Mono.just(VaultToken.of(this.marketingToken))); Health.Builder builder = Health.unknown(); new VaultReactiveHealthIndicator(reactiveMarketing).doHealthCheck(builder) .as(StepVerifier::create) .assertNext(actual -> assertThat(actual.getStatus()).isEqualTo(Status.UP)) .verifyComplete(); }
Example 2
Source File: SessionController.java From tutorials with MIT License | 5 votes |
@GetMapping("/websession/test") public Mono<CustomResponse> testWebSessionByParam( @RequestParam(value = "id") int id, @RequestParam(value = "note") String note, WebSession session) { session.getAttributes().put("id", id); session.getAttributes().put("note", note); CustomResponse r = new CustomResponse(); r.setId((int) session.getAttributes().get("id")); r.setNote((String) session.getAttributes().get("note")); return Mono.just(r); }
Example 3
Source File: MonosTest.java From cyclops with Apache License 2.0 | 5 votes |
@Before public void setup(){ just = Mono.just(10); none = Mono.empty(); none.toFuture().completeExceptionally(new Exception("boo")); active = Mono.fromFuture(CompletableFuture::new); just2 = Mono.just(20); }
Example 4
Source File: ApplicationInfomationController.java From wecube-platform with Apache License 2.0 | 5 votes |
@PostMapping("/appinfo/loggers/update") public Mono<CommonResponseDto> changeLogLevel(@RequestBody LoggerInfoDto dto) { LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory(); if (!StringUtils.isEmpty(dto.getLevel())) { ch.qos.logback.classic.Logger logger = loggerContext.getLogger(dto.getPath()); logger.setLevel(Level.toLevel(dto.getLevel())); } return Mono.just(CommonResponseDto.okay()); }
Example 5
Source File: RouterFunctionMappingTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void normal() { HandlerFunction<ServerResponse> handlerFunction = request -> ServerResponse.ok().build(); RouterFunction<ServerResponse> routerFunction = request -> Mono.just(handlerFunction); RouterFunctionMapping mapping = new RouterFunctionMapping(routerFunction); mapping.setMessageReaders(this.codecConfigurer.getReaders()); Mono<Object> result = mapping.getHandler(this.exchange); StepVerifier.create(result) .expectNext(handlerFunction) .expectComplete() .verify(); }
Example 6
Source File: ReactorGrpcPublisherOneToOneVerificationTest.java From reactive-grpc with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public Publisher<Message> createFailedPublisher() { ReactorTckGrpc.ReactorTckStub stub = ReactorTckGrpc.newReactorStub(channel); Mono<Message> request = Mono.just(toMessage(TckService.KABOOM)); Mono<Message> publisher = stub.oneToOne(request); return publisher.flux(); }
Example 7
Source File: ClientResponseWrapperTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void bodyToMonoClass() { Mono<String> result = Mono.just("foo"); given(mockResponse.bodyToMono(String.class)).willReturn(result); assertSame(result, wrapper.bodyToMono(String.class)); }
Example 8
Source File: LocalMemoryLimiter.java From WeEvent with Apache License 2.0 | 5 votes |
@Override public Mono<Response> isAllowed(String routeId, String id) { Config routeConfig = getConfig().get(routeId); if (routeConfig == null) { throw new IllegalArgumentException("No Configuration found for route " + routeId); } // How many requests per second do you want a user to be allowed to do? int replenishRate = routeConfig.getReplenishRate(); // How much bursting do you want to allow? int burstCapacity = routeConfig.getBurstCapacity(); Bucket bucket = this.buckets.computeIfAbsent(id, k -> { Refill refill = Refill.greedy(replenishRate, Duration.ofSeconds(1)); Bandwidth limit = Bandwidth.classic(burstCapacity, refill); return Bucket4j.builder().addLimit(limit).build(); }); // tryConsume returns false immediately if no tokens available with the bucket ConsumptionProbe probe = bucket.tryConsumeAndReturnRemaining(10); if (probe.isConsumed()) { // the limit is not exceeded return Mono.just(new Response(true, Collections.emptyMap())); } else { log.warn("request rate limited"); // limit is exceeded return Mono.just(new Response(false, getHeaders(routeConfig, 0))); } }
Example 9
Source File: BlockingLoadBalancerClientTests.java From spring-cloud-commons with Apache License 2.0 | 5 votes |
@Override public Mono<Response<ServiceInstance>> choose() { List<ServiceInstance> instances = discoveryClient.getInstances(serviceId); if (instances.size() == 0) { return Mono.just(new EmptyResponse()); } int instanceIdx = this.random.nextInt(instances.size()); return Mono.just(new DefaultResponse(instances.get(instanceIdx))); }
Example 10
Source File: RequestMappingMessageConversionIntegrationTests.java From java-technology-stack with MIT License | 4 votes |
@GetMapping("/mono-response-entity") public ResponseEntity<Mono<Person>> getMonoResponseEntity() { Mono<Person> body = Mono.just(new Person("Robert")); return ResponseEntity.ok(body); }
Example 11
Source File: PersonController.java From halo-docs with Apache License 2.0 | 4 votes |
@PostMapping("/person") Mono<String> create(@RequestBody Publisher<Person> personStream) { return Mono.just("Welcome to reactive world ~"); }
Example 12
Source File: MultipartHttpMessageWriter.java From java-technology-stack with MIT License | 4 votes |
@SuppressWarnings("unchecked") private <T> Flux<DataBuffer> encodePart(byte[] boundary, String name, T value) { MultipartHttpOutputMessage outputMessage = new MultipartHttpOutputMessage(this.bufferFactory, getCharset()); HttpHeaders outputHeaders = outputMessage.getHeaders(); T body; ResolvableType resolvableType = null; if (value instanceof HttpEntity) { HttpEntity<T> httpEntity = (HttpEntity<T>) value; outputHeaders.putAll(httpEntity.getHeaders()); body = httpEntity.getBody(); Assert.state(body != null, "MultipartHttpMessageWriter only supports HttpEntity with body"); if (httpEntity instanceof MultipartBodyBuilder.PublisherEntity<?, ?>) { MultipartBodyBuilder.PublisherEntity<?, ?> publisherEntity = (MultipartBodyBuilder.PublisherEntity<?, ?>) httpEntity; resolvableType = publisherEntity.getResolvableType(); } } else { body = value; } if (resolvableType == null) { resolvableType = ResolvableType.forClass(body.getClass()); } if (!outputHeaders.containsKey(HttpHeaders.CONTENT_DISPOSITION)) { if (body instanceof Resource) { outputHeaders.setContentDispositionFormData(name, ((Resource) body).getFilename()); } else if (resolvableType.resolve() == Resource.class) { body = (T) Mono.from((Publisher<?>) body).doOnNext(o -> outputHeaders .setContentDispositionFormData(name, ((Resource) o).getFilename())); } else { outputHeaders.setContentDispositionFormData(name, null); } } MediaType contentType = outputHeaders.getContentType(); final ResolvableType finalBodyType = resolvableType; Optional<HttpMessageWriter<?>> writer = this.partWriters.stream() .filter(partWriter -> partWriter.canWrite(finalBodyType, contentType)) .findFirst(); if (!writer.isPresent()) { return Flux.error(new CodecException("No suitable writer found for part: " + name)); } Publisher<T> bodyPublisher = body instanceof Publisher ? (Publisher<T>) body : Mono.just(body); // The writer will call MultipartHttpOutputMessage#write which doesn't actually write // but only stores the body Flux and returns Mono.empty(). Mono<Void> partContentReady = ((HttpMessageWriter<T>) writer.get()) .write(bodyPublisher, resolvableType, contentType, outputMessage, DEFAULT_HINTS); // After partContentReady, we can access the part content from MultipartHttpOutputMessage // and use it for writing to the actual request body Flux<DataBuffer> partContent = partContentReady.thenMany(Flux.defer(outputMessage::getBody)); return Flux.concat(Mono.just(generateBoundaryLine(boundary)), partContent, Mono.just(generateNewLine())); }
Example 13
Source File: SwaggerController.java From open-cloud with MIT License | 4 votes |
@GetMapping("/configuration/ui") public Mono<ResponseEntity<UiConfiguration>> uiConfiguration() { return Mono.just(new ResponseEntity<>( Optional.ofNullable(uiConfiguration).orElse(new UiConfiguration("/")), HttpStatus.OK)); }
Example 14
Source File: DefaultEntityResponseBuilder.java From java-technology-stack with MIT License | 4 votes |
@Override public Mono<EntityResponse<T>> build() { return Mono.just(new DefaultEntityResponse<T>( this.status, this.headers, this.cookies, this.entity, this.inserter, this.hints)); }
Example 15
Source File: HygienePolicyExecutorTask.java From cf-butler with Apache License 2.0 | 4 votes |
private static Mono<Tuple2<UserSpaces, Workloads>> filterWorkloads(UserSpaces userSpaces, Workloads input){ Workloads workloads = input.matchBySpace(userSpaces.getSpaces()); log.trace(userSpaces.toString() + ", " + workloads.toString()); return Mono.just(Tuples.of(userSpaces, workloads)); }
Example 16
Source File: SleuthBenchmarkingSpringWebFluxApp.java From spring-cloud-sleuth with Apache License 2.0 | 4 votes |
@RequestMapping("/foo") public Mono<String> foo() { return Mono.just("foo"); }
Example 17
Source File: CfRouteUtil.java From ya-cf-app-gradle-plugin with Apache License 2.0 | 4 votes |
/** * Copy of org.cloudfoundry.operations.applications.RouteUtil.decomposeRoute */ private static Mono<DecomposedRoute> decomposeRoute(List<DomainSummary> availableDomains, String route, String routePath) { String domain = null; String host = null; String path = null; Integer port = null; String routeWithoutSuffix = route; if (availableDomains.size() == 0) { throw new IllegalArgumentException(String.format("The route %s did not match any existing domains", route)); } List<DomainSummary> sortedDomains = availableDomains.stream() .sorted(Comparator.<DomainSummary>comparingInt(domainSummary -> domainSummary.getName().length()).reversed()) .collect(Collectors.toList()); if (route.contains("/")) { int index = route.indexOf("/"); path = routePath != null ? routePath : route.substring(index); routeWithoutSuffix = route.substring(0, index); } else if (hasPort(route)) { port = getPort(route); routeWithoutSuffix = route.substring(0, route.indexOf(":")); } for (DomainSummary item : sortedDomains) { if (isDomainMatch(routeWithoutSuffix, item.getName())) { domain = item.getName(); if (domain.length() < routeWithoutSuffix.length()) { host = routeWithoutSuffix.substring(0, routeWithoutSuffix.lastIndexOf(domain) - 1); } break; } } if (domain == null) { throw new IllegalArgumentException(String.format("The route %s did not match any existing domains", route)); } if ((host != null || path != null) && port != null) { throw new IllegalArgumentException(String.format("The route %s is invalid: Host/path cannot be set with port", route)); } return Mono.just(DecomposedRoute.builder() .domain(domain) .host(host) .path(path) .port(port) .build()); }
Example 18
Source File: AppHandle.java From reactor-guice with Apache License 2.0 | 4 votes |
@GET @Path("/test/redirect") @Produces(MediaType.TEXT_HTML) public Mono<String> testRedirect() { return Mono.just("redirect:/kreactor/test/json"); }
Example 19
Source File: TaxiService.java From Spring-Boot-2.0-Projects with MIT License | 4 votes |
public Mono<Taxi> register(TaxiRegisterEventDTO taxiRegisterEventDTO) { Taxi taxi = new Taxi(taxiRegisterEventDTO.getTaxiId(), taxiRegisterEventDTO.getTaxiType(), TaxiStatus.AVAILABLE); return Mono.just(taxiRepository.save(taxi)); }
Example 20
Source File: DefaultRenderingResponseBuilder.java From java-technology-stack with MIT License | 4 votes |
@Override public Mono<RenderingResponse> build() { return Mono.just( new DefaultRenderingResponse(this.status, this.headers, this.cookies, this.name, this.model)); }