gateway请求返回400
最后更新于:2022-04-02 07:11:15
### 微服务模式下 url参数包含{} gateway报错请求返回400
~~~
package org.jeecg.config;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.codec.http.HttpRequest;
import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.stereotype.Component;
import reactor.netty.ConnectionObserver;
import reactor.netty.NettyPipeline;
import java.io.UnsupportedEncodingException;
@Component
public class MyNettyWebServerCustomizer
implements WebServerFactoryCustomizer {
@Override
public void customize(NettyReactiveWebServerFactory factory) {
factory.addServerCustomizers(httpServer ->
httpServer.observe((conn, state) -> {
if (state == ConnectionObserver.State.CONNECTED) {
conn.channel().pipeline().addAfter(NettyPipeline.HttpCodec, "", new QueryHandler());
}
})
);
}
static final class QueryHandler extends ChannelInboundHandlerAdapter {
static final QueryHandler INSTANCE = new QueryHandler();
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws UnsupportedEncodingException {
if (msg instanceof HttpRequest) {
HttpRequest request = (HttpRequest) msg;
String url = request.uri();
//TODO 替换特殊字符
request.setUri(url);
}
ctx.fireChannelRead(msg);
}
@Override
public boolean isSharable() {
return true;
}
}
}
~~~
';