当前位置: 首页>>代码示例>>Java>>正文


Java ServerRequest类代码示例

本文整理汇总了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());

    }
 
开发者ID:hantsy,项目名称:spring-reactive-sample,代码行数:20,代码来源:DemoApplication.java

示例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);
            }
        }));
    }
}
 
开发者ID:int128,项目名称:httpstub,代码行数:17,代码来源:RequestResponseLogger.java

示例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);
}
 
开发者ID:LearningByExample,项目名称:reactive-ms-example,代码行数:14,代码来源:ApiHandlerTests.java

示例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());
}
 
开发者ID:rbarbioni,项目名称:spring-boot-microservices-docker,代码行数:8,代码来源:UserHandler.java

示例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
}
 
开发者ID:saintdan,项目名称:spring-webflux-microservices-boilerplate,代码行数:11,代码来源:UserHandler.java

示例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));
}
 
开发者ID:int128,项目名称:httpstub,代码行数:11,代码来源:RequestExtractor.java

示例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());
}
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:10,代码来源:DeptDataHandler.java

示例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));
}
 
开发者ID:adaikiss,项目名称:mustache-showcase,代码行数:12,代码来源:CategoryHandler.java

示例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));
}
 
开发者ID:adaikiss,项目名称:mustache-showcase,代码行数:8,代码来源:HomeHandler.java

示例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());
}
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:10,代码来源:EmpDataHandler.java

示例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());
}
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:11,代码来源:EmpDataHandler.java

示例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);
}
 
开发者ID:noorulhaq,项目名称:reactive.loanbroker.system,代码行数:8,代码来源:LoanBrokerTests.java

示例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);
}
 
开发者ID:LearningByExample,项目名称:reactive-ms-example,代码行数:14,代码来源:ApiHandlerTests.java

示例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());
}
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:11,代码来源:DataHandler.java

示例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());
}
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:11,代码来源:LoginHandler.java


注:本文中的org.springframework.web.reactive.function.server.ServerRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。