本文整理汇总了Java中org.springframework.web.reactive.function.server.ServerRequest类的典型用法代码示例。如果您正苦于以下问题:Java ServerRequest类的具体用法?Java ServerRequest怎么用?Java ServerRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ServerRequest类属于org.springframework.web.reactive.function.server包,在下文中一共展示了ServerRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: update
import org.springframework.web.reactive.function.server.ServerRequest; //导入依赖的package包/类
public Mono<ServerResponse> update(ServerRequest req) {
return Mono
.zip(
(data) -> {
Post p = (Post) data[0];
Post p2 = (Post) data[1];
p.setTitle(p2.getTitle());
p.setContent(p2.getContent());
return p;
},
this.posts.findById(req.pathVariable("id")),
req.bodyToMono(Post.class)
)
.cast(Post.class)
.flatMap(post -> this.posts.save(post))
.flatMap(post -> ServerResponse.noContent().build());
}
示例2: logRequest
import org.springframework.web.reactive.function.server.ServerRequest; //导入依赖的package包/类
public void logRequest(ServerRequest request, MultiValueMap<String, ?> map) {
if (configHolder.getConfig().getLogging().isHeaders()) {
logRequestHeaders(request);
}
if (configHolder.getConfig().getLogging().isBody()) {
map.forEach((key, values) -> values.forEach(value -> {
if (value instanceof Part) {
val part = (Part) value;
part.headers().forEach((headerKey, headerValues) -> headerValues.forEach(headerValue ->
log.info("{} [{}] {}: {}", RECEIVED, key, headerKey, headerValue)));
} else {
log.info("{} {}={}", RECEIVED, key, value);
}
}));
}
}
示例3: getLocationTest
import org.springframework.web.reactive.function.server.ServerRequest; //导入依赖的package包/类
@Test
void getLocationTest() {
ServerRequest serverRequest = mock(ServerRequest.class);
when(serverRequest.pathVariable(ADDRESS_VARIABLE)).thenReturn(GOOGLE_ADDRESS);
doReturn(GOOGLE_LOCATION).when(geoLocationService).fromAddress(any());
doReturn(SUNRISE_SUNSET).when(sunriseSunsetService).fromGeographicCoordinates(any());
apiHandler.getLocation(serverRequest).subscribe(this::verifyServerResponse);
reset(geoLocationService);
reset(sunriseSunsetService);
}
示例4: delete
import org.springframework.web.reactive.function.server.ServerRequest; //导入依赖的package包/类
public Mono<ServerResponse> delete(ServerRequest serverRequest) {
return this.userRepository.findById(serverRequest.pathVariable("id"))
.flatMap(user -> ServerResponse
.noContent()
.build(this.userRepository.delete(user)))
.switchIfEmpty(ServerResponse.notFound().build());
}
示例5: update
import org.springframework.web.reactive.function.server.ServerRequest; //导入依赖的package包/类
@Transactional public Mono<ServerResponse> update(ServerRequest request) {
return request.bodyToMono(UserParam.class)
.flatMap(param -> userRepository.findById(request.pathVariable(ID)) // Find user by id.
.flatMap(user -> param2Po(param, user)
.flatMap(u -> ServerResponse.status(HttpStatus.OK)
.contentType(MediaType.APPLICATION_JSON_UTF8)
.body(userRepository.save(u), User.class)))
.switchIfEmpty(
ServerResponse.notFound().build())); // If user find failed, return NOT_FOUND
}
示例6: extract
import org.springframework.web.reactive.function.server.ServerRequest; //导入依赖的package包/类
public Mono<RequestContext> extract(ServerRequest request) {
val builder = RequestContext.builder()
.requestHeaders(request.headers().asHttpHeaders().toSingleValueMap())
.pathVariables(request.pathVariables())
.requestParams(request.queryParams().toSingleValueMap())
.constants(configHolder.getConfig().getConstants());
return extractBody(request)
.map(body -> builder.requestBody(body).build())
.switchIfEmpty(Mono.fromSupplier(builder::build));
}
示例7: countDepts
import org.springframework.web.reactive.function.server.ServerRequest; //导入依赖的package包/类
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());
}
示例8: index
import org.springframework.web.reactive.function.server.ServerRequest; //导入依赖的package包/类
public Mono<ServerResponse> index(ServerRequest request) {
String categoryId = request.pathVariable("category");
final Map<String, Object> data = new HashMap<>();
return categoryRepository.findById(categoryId)
.doOnNext(record -> data.put("record", record))
.flux()
.flatMap(record -> articleRepository.findByCategoryId(record.getId(), 10))
.collectList()
.doOnNext(list -> data.put("list", list))
.flatMap(list -> ServerResponse.ok().render("category/index", data));
}
示例9: index
import org.springframework.web.reactive.function.server.ServerRequest; //导入依赖的package包/类
public Mono<ServerResponse> index(ServerRequest request) {
Map<String, Object> data = new HashMap<>();
return articleRepository.findAll(20)
.collectList()
.doOnNext(list -> data.put("list", list))
.flatMap(list -> ServerResponse.ok().render("index", data));
}
示例10: countEmpsPerDept
import org.springframework.web.reactive.function.server.ServerRequest; //导入依赖的package包/类
public Mono<ServerResponse> countEmpsPerDept(ServerRequest req) {
Function<Employee, Integer> ages = (emp) -> emp.getAge();
Function<Employee, Mono<Integer>> flatMapAge = (emp) -> Mono.just(emp).map(ages);
Mono<Integer> count = Flux.fromIterable(employeeServiceImpl.findAllEmps()).filter((emp) -> emp.getDeptid().equals(Integer.parseInt(req.pathVariable("deptid"))))
.flatMap(flatMapAge)
.reduce((total, increment) -> total + increment);
return ok().contentType(MediaType.APPLICATION_STREAM_JSON).body(count, Integer.class)
.switchIfEmpty(ServerResponse.notFound().build());
}
示例11: countEmps
import org.springframework.web.reactive.function.server.ServerRequest; //导入依赖的package包/类
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());
}
示例12: setup
import org.springframework.web.reactive.function.server.ServerRequest; //导入依赖的package包/类
@Before
public void setup(){
request = mock(ServerRequest.class);
serviceLocator = mock(ReactiveBankServiceLocator.class);
reactorLoanBrokerAgent = new ReactorLoanBrokerAgent(serviceLocator,WebClient.create(new ReactorClientHttpConnector()));
loanBrokerHandler = new LoanBrokerHandler(reactorLoanBrokerAgent);
}
示例13: buildResponseTest
import org.springframework.web.reactive.function.server.ServerRequest; //导入依赖的package包/类
@Test
void buildResponseTest() {
final ServerRequest serverRequest = mock(ServerRequest.class);
when(serverRequest.pathVariable(ADDRESS_VARIABLE)).thenReturn(GOOGLE_ADDRESS);
doReturn(GOOGLE_LOCATION).when(geoLocationService).fromAddress(any());
doReturn(SUNRISE_SUNSET).when(sunriseSunsetService).fromGeographicCoordinates(any());
Mono.just(GOOGLE_ADDRESS).transform(apiHandler::buildResponse).subscribe(this::verifyServerResponse);
reset(geoLocationService);
reset(sunriseSunsetService);
}
示例14: countDepts
import org.springframework.web.reactive.function.server.ServerRequest; //导入依赖的package包/类
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());
}
示例15: countLogins
import org.springframework.web.reactive.function.server.ServerRequest; //导入依赖的package包/类
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());
}