This is an automated email from the ASF dual-hosted git repository. hefengen pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/shenyu.git
The following commit(s) were added to refs/heads/master by this push: new 8efa519da9 logging plugin add requestMethod (#5608) 8efa519da9 is described below commit 8efa519da98f4f48f74eb4d16d5061f5b84bd657 Author: crudboy <965211...@qq.com> AuthorDate: Mon Aug 5 21:33:21 2024 +0800 logging plugin add requestMethod (#5608) * logging plugin add requestMethod * not delete setMethod --- .../plugin/logging/common/AbstractLoggingPlugin.java | 1 + .../logging/common/entity/ShenyuRequestLog.java | 20 ++++++++++++++++++++ .../divide/context/DivideShenyuContextDecorator.java | 4 ++-- .../context/DivideShenyuContextDecoratorTest.java | 6 ++---- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-common/src/main/java/org/apache/shenyu/plugin/logging/common/AbstractLoggingPlugin.java b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-common/src/main/java/org/apache/shenyu/plugin/logging/common/AbstractLoggingPlugin.java index ae09c4d135..d964b6d9c1 100644 --- a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-common/src/main/java/org/apache/shenyu/plugin/logging/common/AbstractLoggingPlugin.java +++ b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-common/src/main/java/org/apache/shenyu/plugin/logging/common/AbstractLoggingPlugin.java @@ -103,6 +103,7 @@ public abstract class AbstractLoggingPlugin<L extends ShenyuRequestLog> extends L requestInfo = this.doLogExecute(exchange, selector, rule); requestInfo.setRequestUri(request.getURI().toString()); requestInfo.setMethod(request.getMethod().name()); + requestInfo.setRequestMethod(request.getMethod().name()); requestInfo.setRequestHeader(LogCollectUtils.getHeaders(request.getHeaders())); requestInfo.setQueryParams(request.getURI().getQuery()); requestInfo.setClientIp(HostAddressUtils.acquireIp(exchange)); diff --git a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-common/src/main/java/org/apache/shenyu/plugin/logging/common/entity/ShenyuRequestLog.java b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-common/src/main/java/org/apache/shenyu/plugin/logging/common/entity/ShenyuRequestLog.java index c35c67a671..deedde6e70 100644 --- a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-common/src/main/java/org/apache/shenyu/plugin/logging/common/entity/ShenyuRequestLog.java +++ b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-common/src/main/java/org/apache/shenyu/plugin/logging/common/entity/ShenyuRequestLog.java @@ -28,6 +28,8 @@ public class ShenyuRequestLog { private String method; + private String requestMethod; + private String requestHeader; private String responseHeader; @@ -193,6 +195,24 @@ public class ShenyuRequestLog { this.method = method; } + /** + * get requestMethod. + * + * @return requestMethod + */ + public String getRequestMethod() { + return requestMethod; + } + + /** + * set method. + * + * @param requestMethod requestMethod + */ + public void setRequestMethod(final String requestMethod) { + this.requestMethod = requestMethod; + } + /** * get requestHeader. * diff --git a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-divide/src/main/java/org/apache/shenyu/plugin/divide/context/DivideShenyuContextDecorator.java b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-divide/src/main/java/org/apache/shenyu/plugin/divide/context/DivideShenyuContextDecorator.java index 82a9349e61..199548c508 100644 --- a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-divide/src/main/java/org/apache/shenyu/plugin/divide/context/DivideShenyuContextDecorator.java +++ b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-divide/src/main/java/org/apache/shenyu/plugin/divide/context/DivideShenyuContextDecorator.java @@ -29,11 +29,11 @@ import java.util.Optional; * The type Divide shenyu context decorator. */ public class DivideShenyuContextDecorator implements ShenyuContextDecorator { - + @Override public ShenyuContext decorator(final ShenyuContext shenyuContext, final MetaData metaData) { String path = shenyuContext.getPath(); - shenyuContext.setMethod(shenyuContext.getHttpMethod()); + shenyuContext.setMethod(path); shenyuContext.setRealUrl(path); shenyuContext.setRpcType(RpcTypeEnum.HTTP.getName()); shenyuContext.setModule(Optional.ofNullable(metaData).map(MetaData::getAppName) diff --git a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-divide/src/test/java/org/apache/shenyu/plugin/divide/context/DivideShenyuContextDecoratorTest.java b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-divide/src/test/java/org/apache/shenyu/plugin/divide/context/DivideShenyuContextDecoratorTest.java index 1d388befa7..f609f52ae9 100644 --- a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-divide/src/test/java/org/apache/shenyu/plugin/divide/context/DivideShenyuContextDecoratorTest.java +++ b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-divide/src/test/java/org/apache/shenyu/plugin/divide/context/DivideShenyuContextDecoratorTest.java @@ -35,8 +35,6 @@ public final class DivideShenyuContextDecoratorTest { private static final String MOCK_CONTEXT_PATH = "mockContextPath"; - private static final String MOCK_METHOD = "GET"; - private DivideShenyuContextDecorator divideShenyuContextDecorator; @BeforeEach @@ -52,9 +50,9 @@ public final class DivideShenyuContextDecoratorTest { MetaData metaData = new MetaData(); ShenyuContext shenyuContext = new ShenyuContext(); shenyuContext.setPath(MOCK_CONTEXT_PATH); - shenyuContext.setHttpMethod(MOCK_METHOD); + shenyuContext.setHttpMethod(MOCK_CONTEXT_PATH); ShenyuContext decorator = divideShenyuContextDecorator.decorator(shenyuContext, metaData); - assert MOCK_METHOD.equals(decorator.getMethod()); + assert MOCK_CONTEXT_PATH.equals(decorator.getMethod()); assert MOCK_CONTEXT_PATH.equals(decorator.getRealUrl()); } }