org.springframework.web.servlet.function.ServerRequest Java Examples

The following examples show how to use org.springframework.web.servlet.function.ServerRequest. 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: HandlerFunctionAdapter.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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));
}
 
Example #2
Source File: HandlerFunctionAdapter.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private ServerRequest getServerRequest(HttpServletRequest servletRequest) {
	ServerRequest serverRequest =
			(ServerRequest) servletRequest.getAttribute(RouterFunctions.REQUEST_ATTRIBUTE);
	Assert.state(serverRequest != null, () -> "Required attribute '" +
			RouterFunctions.REQUEST_ATTRIBUTE + "' is missing");
	return serverRequest;
}
 
Example #3
Source File: RouterFunctionMapping.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Nullable
@Override
protected Object getHandlerInternal(@NotNull HttpServletRequest servletRequest) throws Exception {
	if (this.routerFunction != null) {
		ServerRequest request = ServerRequest.create(servletRequest, this.messageConverters);
		servletRequest.setAttribute(RouterFunctions.REQUEST_ATTRIBUTE, request);
		return this.routerFunction.route(request).orElse(null);
	}
	else {
		return null;
	}
}
 
Example #4
Source File: HandlerFunctionAdapter.java    From spring-analysis-note with MIT License 4 votes vote down vote up
public ServerRequestContext(ServerRequest serverRequest) {
	this.serverRequest = serverRequest;
}
 
Example #5
Source File: RouterFunctionProvider.java    From springdoc-openapi with Apache License 2.0 4 votes vote down vote up
@Override
public void resources(Function<ServerRequest, Optional<Resource>> lookupFunction) {
	// Not yet needed
}
 
Example #6
Source File: HelloApplication.java    From springdoc-openapi with Apache License 2.0 4 votes vote down vote up
ServerResponse handleGetAllPeople(ServerRequest serverRequest) {
	return ok().body(personService.all());
}
 
Example #7
Source File: HelloApplication.java    From springdoc-openapi with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example #8
Source File: HelloApplication.java    From springdoc-openapi with Apache License 2.0 4 votes vote down vote up
ServerResponse handleGetPersonById(ServerRequest r) {
	return ok().body(personService.byId(Long.parseLong(r.pathVariable("id"))));
}
 
Example #9
Source File: SampleHandler.java    From spring-fu with Apache License 2.0 4 votes vote down vote up
public ServerResponse hello(ServerRequest request) {
	return ok().body(sampleService.generateMessage());
}
 
Example #10
Source File: SampleHandler.java    From spring-fu with Apache License 2.0 4 votes vote down vote up
public ServerResponse json(ServerRequest request) {
	return ok().body(new Sample(sampleService.generateMessage()));
}
 
Example #11
Source File: ProductController.java    From tutorials with MIT License 4 votes vote down vote up
private boolean authenticate(ServerRequest req) {
    return Boolean.TRUE;
}