Java Code Examples for org.springframework.http.server.reactive.ServerHttpRequest#getPath()

The following examples show how to use org.springframework.http.server.reactive.ServerHttpRequest#getPath() . 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: LogFilter.java    From gateway with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 请求信息日志过滤器
 *
 * @param exchange ServerWebExchange
 * @param chain    GatewayFilterChain
 * @return Mono
 */
@Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
    ServerHttpRequest request = exchange.getRequest();
    HttpHeaders headers = request.getHeaders();
    HttpMethod method = request.getMethod();
    RequestPath path = request.getPath();
    String source = getIp(headers);
    if (source == null || source.isEmpty()) {
        source = request.getRemoteAddress().getAddress().getHostAddress();
    }

    String requestId = Util.uuid();
    String fingerprint = Util.md5(source + headers.getFirst("user-agent"));
    LogDto log = new LogDto();
    log.setRequestId(requestId);
    log.setSource(source);
    log.setMethod(method.name());
    log.setUrl(path.value());
    log.setHeaders(headers.toSingleValueMap());
    request.mutate().header("requestId", requestId).build();
    request.mutate().header("fingerprint", fingerprint).build();

    // 读取请求参数
    MultiValueMap<String, String> params = request.getQueryParams();
    log.setParams(params.isEmpty() ? null : params.toSingleValueMap());

    // 如请求方法为GET或Body为空或Body不是Json,则打印日志后结束
    long length = headers.getContentLength();
    MediaType contentType = headers.getContentType();
    if (length <= 0 || !contentType.equalsTypeAndSubtype(MediaType.APPLICATION_JSON)) {
        logger.info("请求参数: {}", log.toString());

        return chain.filter(exchange);
    }

    return readBody(exchange, chain, log);
}
 
Example 2
Source File: ExceptionHandlingWebHandler.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public Mono<Void> handle(ServerWebExchange exchange, Throwable ex) {
	ServerHttpRequest request = exchange.getRequest();
	String rawQuery = request.getURI().getRawQuery();
	String query = StringUtils.hasText(rawQuery) ? "?" + rawQuery : "";
	HttpMethod httpMethod = request.getMethod();
	String description = "HTTP " + httpMethod + " \"" + request.getPath() + query + "\"";
	return Mono.error(ex).checkpoint(description + " [ExceptionHandlingWebHandler]").cast(Void.class);
}
 
Example 3
Source File: HttpWebHandlerAdapter.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private String formatRequest(ServerHttpRequest request) {
	String rawQuery = request.getURI().getRawQuery();
	String query = StringUtils.hasText(rawQuery) ? "?" + rawQuery : "";
	return "HTTP " + request.getMethod() + " \"" + request.getPath() + query + "\"";
}
 
Example 4
Source File: HttpWebHandlerAdapter.java    From java-technology-stack with MIT License 4 votes vote down vote up
private String formatRequest(ServerHttpRequest request) {
	String rawQuery = request.getURI().getRawQuery();
	String query = StringUtils.hasText(rawQuery) ? "?" + rawQuery : "";
	return "HTTP " + request.getMethod() + " \"" + request.getPath() + query + "\"";
}
 
Example 5
Source File: ReactiveRestfulMatchUtil.java    From light-security with Apache License 2.0 2 votes vote down vote up
/**
 * 获取请求路径
 *
 * @param request 请求
 * @return 请求路径
 */
private static String getRequestPath(ServerHttpRequest request) {
    RequestPath path = request.getPath();
    return path.toString();
}