List of usage examples for org.springframework.web.reactive.function.server ServerResponse notFound
static HeadersBuilder<?> notFound()
From source file:top.zhacker.ms.reactor.spring.function.handler.PersonHandler.java
public Mono<ServerResponse> getPerson(ServerRequest request) { int personId = Integer.valueOf(request.pathVariable("id")); Mono<ServerResponse> notFound = ServerResponse.notFound().build(); Mono<Person> personMono = this.repository.getPerson(personId); return personMono .flatMap(person -> ServerResponse.ok().contentType(APPLICATION_JSON).body(fromObject(person))) .switchIfEmpty(notFound);//from w w w.j a v a 2 s. c om }
From source file:com.example.TestEndpoint.java
Mono<ServerResponse> test(final ServerRequest request) { final Optional<String> value = request.queryParam("value"); return Mono.justOrEmpty(value).map(Wrapper::new) .flatMap(v -> ServerResponse.ok().body(Mono.just(v), Wrapper.class)) .switchIfEmpty(ServerResponse.notFound().build()); }
From source file:com.example.talk.TalkEndpoint.java
Mono<ServerResponse> getTalkRoom(final ServerRequest serverRequest) { final long talkId = Long.parseLong(serverRequest.pathVariable("talkId")); final Mono<TalkRoom> talkRoom = talkRoomRepository.getTalkRoomByTalkRoomId(talkId); return talkRoom.flatMap(tr -> ServerResponse.ok().contentType(MediaType.APPLICATION_JSON) .body(Mono.just(tr), TalkRoom.class)).switchIfEmpty(ServerResponse.notFound().build()); }
From source file:com.example.talk.TalkEndpoint.java
Mono<ServerResponse> all(final ServerRequest request) { return request.principal().cast(UsernamePasswordAuthenticationToken.class) .map(UsernamePasswordAuthenticationToken::getPrincipal).cast(UserAdapter.class) .map(UserAdapter::getUserId).map(talkRoomRepository::findTalkRoomByUserId) .flatMap(Flux::collectList)/* w w w .ja v a 2 s . c om*/ .flatMap(list -> ServerResponse.ok().contentType(MediaType.APPLICATION_JSON).body(Mono.just(list), new ParameterizedTypeReference<List<TalkRoom>>() { })) .switchIfEmpty(ServerResponse.notFound().build()); }