Java Code Examples for org.springframework.web.reactive.function.server.ServerRequest#pathVariable()

The following examples show how to use org.springframework.web.reactive.function.server.ServerRequest#pathVariable() . 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: GraphAlgorithmHandler.java    From kafka-graphs with Apache License 2.0 6 votes vote down vote up
public Mono<ServerResponse> result(ServerRequest request) {
    List<String> appIdHeaders = request.headers().header(X_KGRAPH_APPID);
    String appId = request.pathVariable("id");
    PregelGraphAlgorithm<?, ?, ?, ?> algorithm = algorithms.get(appId);
    if (algorithm == null) {
        return ServerResponse.notFound().build();
    }
    Flux<KeyValue> body = Flux.fromIterable(algorithm.result()).map(kv -> {
        log.trace("result: ({}, {})", kv.key, kv.value);
        return new KeyValue(kv.key.toString(), kv.value.toString());
    });
    body = proxyResult(appIdHeaders.isEmpty() ? group.getCurrentMembers().keySet() : Collections.emptySet(), appId, body);
    return ServerResponse.ok()
        .contentType(MediaType.TEXT_EVENT_STREAM)
        .body(BodyInserters.fromPublisher(body, KeyValue.class));
}
 
Example 2
Source File: GraphAlgorithmHandler.java    From kafka-graphs with Apache License 2.0 6 votes vote down vote up
public Mono<ServerResponse> run(ServerRequest request) {
    List<String> appIdHeaders = request.headers().header(X_KGRAPH_APPID);
    String appId = request.pathVariable("id");
    return request.bodyToMono(GraphAlgorithmRunRequest.class)
        .flatMapMany(input -> {
            log.debug("num iterations: {}", input.getNumIterations());
            PregelGraphAlgorithm<?, ?, ?, ?> algorithm = algorithms.get(appId);
            GraphAlgorithmState state = algorithm.run(input.getNumIterations());
            GraphAlgorithmStatus status = new GraphAlgorithmStatus(state);
            Flux<GraphAlgorithmStatus> states =
                proxyRun(appIdHeaders.isEmpty() ? group.getCurrentMembers().keySet() : Collections.emptySet(), appId, input);
            return Mono.just(status).mergeWith(states);
        })
        .onErrorMap(RuntimeException.class, e -> new ResponseStatusException(NOT_FOUND))
        .reduce((state1, state2) -> state1)
        .flatMap(state ->
            ServerResponse.ok()
                .contentType(MediaType.APPLICATION_JSON)
                .body(Mono.just(state), GraphAlgorithmStatus.class)
        );

}
 
Example 3
Source File: GraphAlgorithmHandler.java    From kafka-graphs with Apache License 2.0 5 votes vote down vote up
public Mono<ServerResponse> configs(ServerRequest request) {
    String appId = request.pathVariable("id");
    PregelGraphAlgorithm<?, ?, ?, ?> algorithm = algorithms.get(appId);
    if (algorithm == null) {
        return ServerResponse.notFound().build();
    }
    return ServerResponse.ok()
        .contentType(MediaType.APPLICATION_JSON)
        .body(Mono.just(algorithm.configs()), Map.class);
}
 
Example 4
Source File: MovieHandler.java    From spring-5-examples with MIT License 5 votes vote down vote up
public Mono<ServerResponse> eventStream(final ServerRequest request) {

    val id = request.pathVariable("id");
    val body = movieService.streamEvents(id);

    return ServerResponse.ok()
                         .contentType(TEXT_EVENT_STREAM)
                         .body(body, MovieEvent.class);
  }
 
Example 5
Source File: MovieHandler.java    From spring-5-examples with MIT License 5 votes vote down vote up
public Mono<ServerResponse> eventStream(final ServerRequest request) {

    val id = request.pathVariable("id");
    val body = movieService.streamEvents(id);

    return ServerResponse.ok()
                         .contentType(TEXT_EVENT_STREAM)
                         .body(body, MovieEvent.class);
  }
 
Example 6
Source File: GraphAlgorithmHandler.java    From kafka-graphs with Apache License 2.0 5 votes vote down vote up
public Mono<ServerResponse> delete(ServerRequest request) {
    List<String> appIdHeaders = request.headers().header(X_KGRAPH_APPID);
    String appId = request.pathVariable("id");
    PregelGraphAlgorithm<?, ?, ?, ?> algorithm = algorithms.remove(appId);
    algorithm.close();
    return proxyDelete(appIdHeaders.isEmpty() ? group.getCurrentMembers().keySet() : Collections.emptySet(), appId)
        .then(ServerResponse.noContent().build());
}
 
Example 7
Source File: GraphAlgorithmHandler.java    From kafka-graphs with Apache License 2.0 5 votes vote down vote up
public Mono<ServerResponse> state(ServerRequest request) {
    String appId = request.pathVariable("id");
    PregelGraphAlgorithm<?, ?, ?, ?> algorithm = algorithms.get(appId);
    if (algorithm == null) {
        return ServerResponse.notFound().build();
    }
    return ServerResponse.ok()
        .contentType(MediaType.APPLICATION_JSON)
        .body(Mono.just(new GraphAlgorithmStatus(algorithm.state())), GraphAlgorithmStatus.class);
}
 
Example 8
Source File: EmployeeHandler.java    From webflux-rxjava2-jdbc-example with Apache License 2.0 5 votes vote down vote up
public Mono<ServerResponse> getEmployee(ServerRequest request) {
  String firstName = request.pathVariable("fn");
  String lastName = request.pathVariable("ln");

  Mono<Employee> employee = repository.getEmployee(firstName, lastName);

  return ServerResponse.ok()
      .contentType(MediaType.APPLICATION_JSON)
      .body(employee, Employee.class);
}
 
Example 9
Source File: FnApplication.java    From spring-5-examples with MIT License 5 votes vote down vote up
public Mono<ServerResponse> getPerson(ServerRequest request) {
  String personId = request.pathVariable("id");
  return repository.getPerson(personId)
                   .flatMap(person -> ok().contentType(APPLICATION_JSON)
                                          .body(fromObject(person)))
                   .switchIfEmpty(ServerResponse.notFound().build());
}
 
Example 10
Source File: VpcWebHandlers.java    From alcor with Apache License 2.0 5 votes vote down vote up
public Mono<ServerResponse> getVpc(ServerRequest request) {
    String projectId = request.pathVariable("projectId");
    String vpcId = request.pathVariable("vpcId");

    Mono<VpcWebJson> vpcInfo = serviceProxy.findVpcById(projectId, vpcId);

    return vpcInfo.flatMap(od -> ServerResponse.ok()
            .contentType(APPLICATION_JSON)
            .body(fromObject(od)))
            .onErrorResume(VpcNotFoundException.class, e -> ServerResponse.notFound().build());
}
 
Example 11
Source File: ProxyConfig.java    From spring-security-samples with MIT License 5 votes vote down vote up
private String toBackendUri(final ServerRequest request) {
	final String service = request.pathVariable("service");
	final String backend = config.backend(service);
	return UriComponentsBuilder.fromUriString(backend)
		.path(request.path().substring(API_PREFIX.length() + service.length()))
		.queryParams(request.queryParams())
		.build().toString();
}
 
Example 12
Source File: PositionHandler.java    From springdoc-openapi with Apache License 2.0 4 votes vote down vote up
public Mono<ServerResponse> findById(ServerRequest request) {
    String id = request.pathVariable("id");
    return null;
}
 
Example 13
Source File: MovieHandler.java    From spring-5-examples with MIT License 4 votes vote down vote up
public Mono<ServerResponse> eventStream(final ServerRequest request) {

    val id = request.pathVariable("id");
    val body = movieService.streamEvents(id);
    return ServerResponse.ok().contentType(TEXT_EVENT_STREAM).body(body, MovieEvent.class);
  }
 
Example 14
Source File: FileItemsHandler.java    From streaming-file-server with MIT License 4 votes vote down vote up
public Mono<ServerResponse> searchAny(final ServerRequest request) {
  final String filename = request.pathVariable("filename");
  return jsonOk().body(reactiveRepository.findAny(filename)
                                         .subscribeOn(Schedulers.elastic()), FileItem.class);
}
 
Example 15
Source File: MovieHandler.java    From spring-5-examples with MIT License 4 votes vote down vote up
public Mono<ServerResponse> eventStream(final ServerRequest request) {

    val id = request.pathVariable("id");
    val body = movieService.streamEvents(id);
    return ServerResponse.ok().contentType(TEXT_EVENT_STREAM).body(body, MovieEvent.class);
  }
 
Example 16
Source File: EmployeeHandler.java    From webflux-rxjava2-jdbc-example with Apache License 2.0 3 votes vote down vote up
public Mono<ServerResponse> deleteEmployee(ServerRequest request) {
  String id = request.pathVariable("id");

  Mono<Void> employee = repository.deleteEmployee(id);

  return ServerResponse.ok().contentType(MediaType.APPLICATION_JSON).build(employee);
}
 
Example 17
Source File: MovieHandler.java    From spring-5-examples with MIT License 3 votes vote down vote up
public Mono<ServerResponse> getMovie(final ServerRequest request) {

    val id = request.pathVariable("id");
    val body = movieService.getById(id);

    return ServerResponse.ok().body(body, Movie.class);
  }
 
Example 18
Source File: MovieHandler.java    From spring-5-examples with MIT License 3 votes vote down vote up
public Mono<ServerResponse> getMovie(final ServerRequest request) {

    val id = request.pathVariable("id");
    val body = movieService.getById(id);

    return ServerResponse.ok().body(body, Movie.class);
  }
 
Example 19
Source File: MovieHandler.java    From spring-5-examples with MIT License 3 votes vote down vote up
public Mono<ServerResponse> getMovie(final ServerRequest request) {

    val id = request.pathVariable("id");
    val body = movieService.getById(id);

    return ServerResponse.ok().body(body, Movie.class);
  }
 
Example 20
Source File: MovieHandler.java    From spring-5-examples with MIT License 3 votes vote down vote up
public Mono<ServerResponse> getMovie(final ServerRequest request) {

    val id = request.pathVariable("id");
    val body = movieService.getById(id);

    return ServerResponse.ok().body(body, Movie.class);
  }