类org.springframework.web.servlet.function.ServerResponse源码实例Demo

下面列出了怎么用org.springframework.web.servlet.function.ServerResponse的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: tutorials   文件: SpringBootMvcFnApplication.java
@Bean
RouterFunction<ServerResponse> allApplicationRoutes(ProductController pc, ProductService ps) {
    return route().add(pc.remainingProductRoutes(ps))
        .before(req -> {
            LOG.info("Found a route which matches " + req.uri()
                .getPath());
            return req;
        })
        .after((req, res) -> {
            if (res.statusCode() == HttpStatus.OK) {
                LOG.info("Finished processing request " + req.uri()
                    .getPath());
            } else {
                LOG.info("There was an error while processing request" + req.uri());
            }
            return res;
        })
        .onError(Throwable.class, (e, res) -> {
            LOG.error("Fatal exception has occurred", e);
            return status(HttpStatus.INTERNAL_SERVER_ERROR).build();
        })
        .build()
        .and(route(RequestPredicates.all(), req -> notFound().build()));
}
 
@Nullable
@Override
public ModelAndView handle(HttpServletRequest servletRequest,
		HttpServletResponse servletResponse,
		Object handler) throws Exception {


	HandlerFunction<?> handlerFunction = (HandlerFunction<?>) handler;

	ServerRequest serverRequest = getServerRequest(servletRequest);
	ServerResponse serverResponse = handlerFunction.handle(serverRequest);

	return serverResponse.writeTo(servletRequest, servletResponse,
			new ServerRequestContext(serverRequest));
}
 
源代码3 项目: springdoc-openapi   文件: HelloApplication.java
@Bean
@RouterOperations({ @RouterOperation(path = "/people", method = RequestMethod.GET, beanClass = PersonService.class, beanMethod = "all"),
		@RouterOperation(path = "/people/{id}", beanClass = PersonService.class, beanMethod = "byId"),
		@RouterOperation(path = "/people", method = RequestMethod.POST, beanClass = PersonService.class, beanMethod = "save") })
RouterFunction<ServerResponse> routes(PersonHandler ph) {
	String root = "";
	return route()
			.GET(root + "/people", ph::handleGetAllPeople)
			.GET(root + "/people/{id}", ph::handleGetPersonById)
			.POST(root + "/people", ph::handlePostPerson)
			.filter((serverRequest, handlerFunction) -> {
				return handlerFunction.handle(serverRequest);
			})
			.build();
}
 
源代码4 项目: tutorials   文件: ProductController.java
public RouterFunction<ServerResponse> productSearch(ProductService ps) {
    return route().nest(RequestPredicates.path("/product"), builder -> {
        builder.GET("/name/{name}", req -> ok().body(ps.findByName(req.pathVariable("name"))))
            .GET("/id/{id}", req -> ok().body(ps.findById(Integer.parseInt(req.pathVariable("id")))));
    })
        .onError(ProductService.ItemNotFoundException.class, (e, req) -> EntityResponse.fromObject(new Error(e.getMessage()))
            .status(HttpStatus.NOT_FOUND)
            .build())
        .build();
}
 
源代码5 项目: tutorials   文件: ProductController.java
public RouterFunction<ServerResponse> adminFunctions(ProductService ps) {
    return route().POST("/product", req -> ok().body(ps.save(req.body(Product.class))))
        .filter((req, next) -> authenticate(req) ? next.handle(req) : status(HttpStatus.UNAUTHORIZED).build())
        .onError(IllegalArgumentException.class, (e, req) -> EntityResponse.fromObject(new Error(e.getMessage()))
            .status(HttpStatus.BAD_REQUEST)
            .build())
        .build();
}
 
源代码6 项目: springdoc-openapi   文件: HelloApplication.java
ServerResponse handleGetAllPeople(ServerRequest serverRequest) {
	return ok().body(personService.all());
}
 
源代码7 项目: springdoc-openapi   文件: HelloApplication.java
ServerResponse handlePostPerson(ServerRequest r) throws ServletException, IOException {
	Person result = personService.save(new Person(null, r.body(Person.class).getName()));
	URI uri = URI.create("/people/" + result.getId());
	return ServerResponse.created(uri).body(result);
}
 
源代码8 项目: springdoc-openapi   文件: HelloApplication.java
ServerResponse handleGetPersonById(ServerRequest r) {
	return ok().body(personService.byId(Long.parseLong(r.pathVariable("id"))));
}
 
源代码9 项目: spring-fu   文件: SampleHandler.java
public ServerResponse hello(ServerRequest request) {
	return ok().body(sampleService.generateMessage());
}
 
源代码10 项目: spring-fu   文件: SampleHandler.java
public ServerResponse json(ServerRequest request) {
	return ok().body(new Sample(sampleService.generateMessage()));
}
 
源代码11 项目: tutorials   文件: ProductController.java
public RouterFunction<ServerResponse> productListing(ProductService ps) {
    return route().GET("/product", req -> ok().body(ps.findAll()))
        .build();
}
 
源代码12 项目: tutorials   文件: ProductController.java
public RouterFunction<ServerResponse> remainingProductRoutes(ProductService ps) {
    return route().add(productSearch(ps))
        .add(adminFunctions(ps))
        .build();
}
 
源代码13 项目: tutorials   文件: SpringBootMvcFnApplication.java
@Bean
RouterFunction<ServerResponse> productListing(ProductController pc, ProductService ps) {
    return pc.productListing(ps);
}
 
 同包方法