admin 管理员组

文章数量: 887021


2024年2月18日发(作者:数据库系统概论读写说)

import serter;import serters;import rStrategies;import Request;import WebExchange;import ;import ;

import ;import Reference;import tion;

/** * @author chenws * @date 2019/12/12 09:33:53 */@Componentpublic class CModifyRequestBodyGatewayFilterFactory extends AbstractGatewayFilterFactory {

private final List> messageReaders;

public CModifyRequestBodyGatewayFilterFactory() { eReaders = faults().messageReaders(); }

@Override @SuppressWarnings("unchecked") public GatewayFilter apply(Object config) { return (exchange, chain) -> { ServerRequest serverRequest = (exchange, eReaders);

Mono modifiedBody = Mono() .flatMap(originalBody -> modifyBody() .apply(exchange,(originalBody)));

BodyInserter bodyInserter = blisher(modifiedBody, ); HttpHeaders headers = new HttpHeaders(); (uest().getHeaders()); (T_LENGTH);

CachedBodyOutputMessage outputMessage = new CachedBodyOutputMessage(exchange, headers); return (outputMessage, new BodyInserterContext()) .then((() -> { ServerHttpRequest decorator = decorate(exchange, headers, outputMessage); return (().request(decorator).build()); }));

}; }

/** * 修改body * @return apply 返回Mono,数据是修改后的body */ private BiFunction,Mono> modifyBody(){ return (exchange,json)-> { AtomicReference result = new AtomicReference<>(); ibe( value -> { //value 即为请求body,在此处修改 (value); n(()); }, Throwable::printStackTrace ); return (()); }; }

private ServerHttpRequestDecorator decorate(ServerWebExchange exchange, HttpHeaders headers, CachedBodyOutputMessage outputMessage) { return new ServerHttpRequestDecorator(uest()) { @Override public HttpHeaders getHeaders() { long contentLength = tentLength();


本文标签: 读写 数据 概论 数据库系统 修改