Java Code Examples for org.springframework.web.reactive.function.server.ServerResponse#writeTo()

The following examples show how to use org.springframework.web.reactive.function.server.ServerResponse#writeTo() . 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: ServerResponseResultHandler.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public Mono<Void> handleResult(ServerWebExchange exchange, HandlerResult result) {
	ServerResponse response = (ServerResponse) result.getReturnValue();
	Assert.state(response != null, "No ServerResponse");
	return response.writeTo(exchange, new ServerResponse.Context() {
		@Override
		public List<HttpMessageWriter<?>> messageWriters() {
			return messageWriters;
		}
		@Override
		public List<ViewResolver> viewResolvers() {
			return viewResolvers;
		}
	});
}
 
Example 2
Source File: JsonExceptionHandler.java    From open-cloud with MIT License 5 votes vote down vote up
/**
 * 参考AbstractErrorWebExceptionHandler
 *
 * @param exchange
 * @param response
 * @return
 */
private Mono<? extends Void> write(ServerWebExchange exchange,
                                   ServerResponse response,Throwable ex) {
    exchange.getResponse().getHeaders()
            .setContentType(response.headers().getContentType());
    // 保存日志
    accessLogService.sendLog(exchange, (Exception) ex);
    return response.writeTo(exchange, new ResponseContext());
}
 
Example 3
Source File: ServerResponseResultHandler.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public Mono<Void> handleResult(ServerWebExchange exchange, HandlerResult result) {
	ServerResponse response = (ServerResponse) result.getReturnValue();
	Assert.state(response != null, "No ServerResponse");
	return response.writeTo(exchange, new ServerResponse.Context() {
		@Override
		public List<HttpMessageWriter<?>> messageWriters() {
			return messageWriters;
		}
		@Override
		public List<ViewResolver> viewResolvers() {
			return viewResolvers;
		}
	});
}
 
Example 4
Source File: JsonExceptionHandler.java    From MyShopPlus with Apache License 2.0 4 votes vote down vote up
private Mono<? extends Void> write(ServerWebExchange exchange, ServerResponse response) {
    exchange.getResponse().getHeaders().setContentType(response.headers().getContentType());
    return response.writeTo(exchange, new ResponseContext());
}
 
Example 5
Source File: GatewayExceptionHandler.java    From spring-microservice-exam with MIT License 4 votes vote down vote up
private Mono<? extends Void> write(ServerWebExchange exchange,
                                   ServerResponse response) {
    exchange.getResponse().getHeaders().setContentType(response.headers().getContentType());
    return response.writeTo(exchange, new ResponseContext());
}
 
Example 6
Source File: SentinelGatewayBlockExceptionHandler.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 4 votes vote down vote up
private Mono<Void> writeResponse(ServerResponse response, ServerWebExchange exchange) {
    return response.writeTo(exchange, contextSupplier.get());
}
 
Example 7
Source File: SentinelBlockExceptionHandler.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 4 votes vote down vote up
private Mono<Void> writeResponse(ServerResponse response, ServerWebExchange exchange) {
    return response.writeTo(exchange, contextSupplier.get());
}
 
Example 8
Source File: SentinelGatewayBlockExceptionHandler.java    From Sentinel with Apache License 2.0 4 votes vote down vote up
private Mono<Void> writeResponse(ServerResponse response, ServerWebExchange exchange) {
    return response.writeTo(exchange, contextSupplier.get());
}
 
Example 9
Source File: SentinelBlockExceptionHandler.java    From Sentinel with Apache License 2.0 4 votes vote down vote up
private Mono<Void> writeResponse(ServerResponse response, ServerWebExchange exchange) {
    return response.writeTo(exchange, contextSupplier.get());
}
 
Example 10
Source File: CustomExceptionHandler.java    From lion with Apache License 2.0 4 votes vote down vote up
/**
 * 参考AbstractErrorWebExceptionHandler
 */
private Mono<Void> write(ServerWebExchange exchange, ServerResponse response) {
    exchange.getResponse().getHeaders()
            .setContentType(response.headers().getContentType());
    return response.writeTo(exchange, new ResponseContext());
}
 
Example 11
Source File: SpringWebfluxUnhandledExceptionHandler.java    From backstopper with Apache License 2.0 4 votes vote down vote up
protected Mono<? extends Void> write(ServerWebExchange exchange, ServerResponse response) {
    // force content-type since writeTo won't overwrite response header values
    exchange.getResponse().getHeaders().setContentType(response.headers().getContentType());
    return response.writeTo(exchange, new ResponseContext(messageWriters, viewResolvers));
}
 
Example 12
Source File: SpringWebfluxApiExceptionHandler.java    From backstopper with Apache License 2.0 4 votes vote down vote up
protected Mono<? extends Void> write(ServerWebExchange exchange, ServerResponse response) {
    // force content-type since writeTo won't overwrite response header values
    exchange.getResponse().getHeaders().setContentType(response.headers().getContentType());
    return response.writeTo(exchange, new ResponseContext(messageWriters, viewResolvers));
}
 
Example 13
Source File: ExceptionHandle.java    From microservice-recruit with Apache License 2.0 3 votes vote down vote up
/**
 * 参考AbstractErrorWebExceptionHandler
 *
 * @param exchange
 * @param response
 * @return
 */
private Mono<? extends Void> write(ServerWebExchange exchange,
                                   ServerResponse response) {
    exchange.getResponse().getHeaders()
            .setContentType(response.headers().getContentType());
    return response.writeTo(exchange, new ResponseContext());
}
 
Example 14
Source File: ExceptionHandle.java    From microservice-recruit with Apache License 2.0 3 votes vote down vote up
/**
 * 参考AbstractErrorWebExceptionHandler
 *
 * @param exchange
 * @param response
 * @return
 */
private Mono<? extends Void> write(ServerWebExchange exchange,
                                   ServerResponse response) {
    exchange.getResponse().getHeaders()
            .setContentType(response.headers().getContentType());
    return response.writeTo(exchange, new ResponseContext());
}