You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2024/08/02 05:31:10 UTC
(dubbo) branch 3.3 updated: Rest filter support pattern & some bugfix (#14482)
This is an automated email from the ASF dual-hosted git repository.
albumenj pushed a commit to branch 3.3
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/3.3 by this push:
new 693ba11589 Rest filter support pattern & some bugfix (#14482)
693ba11589 is described below
commit 693ba115899c1f6baf7fa7ee4ab71b38a0dbcdcc
Author: Sean Yang <ox...@gmail.com>
AuthorDate: Fri Aug 2 13:31:04 2024 +0800
Rest filter support pattern & some bugfix (#14482)
---
.../dubbo/rpc/protocol/tri/rest/RestConstants.java | 2 -
.../tri/rest/filter/AbstractRestFilter.java | 3 +-
.../rest/filter/RestExtensionExecutionFilter.java | 88 +++++++++++++++++++++-
.../rpc/protocol/tri/rest/mapping/RadixTree.java | 26 ++++---
.../tri/rest/mapping/condition/PathExpression.java | 8 +-
.../rpc/protocol/tri/rest/util/KeyString.java | 4 +-
.../protocol/tri/rest/filter/RestFilterTest.groovy | 45 +++++++++++
.../protocol/tri/rest/mapping/RadixTreeTest.groovy | 18 ++++-
.../mapping/condition/PathExpressionTest.groovy | 6 +-
.../protocol/tri/rest/filter/TestRestFilter.java | 67 ++++++++++++++++
.../tri/rest/filter/TestRestFilterFactory.java | 30 ++++++++
...ubbo.rpc.protocol.tri.rest.filter.RestExtension | 1 +
12 files changed, 273 insertions(+), 25 deletions(-)
diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/RestConstants.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/RestConstants.java
index d267d58144..c6434979fb 100644
--- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/RestConstants.java
+++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/RestConstants.java
@@ -23,8 +23,6 @@ import org.apache.dubbo.rpc.protocol.tri.rest.mapping.meta.HandlerMeta;
public final class RestConstants {
- public static final String REST = "rest";
-
public static final String REST_FILTER_KEY = "rest.filter";
public static final String EXTENSION_KEY = "extension";
public static final String EXTENSIONS_ATTRIBUTE_KEY = "restExtensionsAttributeKey";
diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/filter/AbstractRestFilter.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/filter/AbstractRestFilter.java
index 2517287fdf..c28e40868a 100644
--- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/filter/AbstractRestFilter.java
+++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/filter/AbstractRestFilter.java
@@ -16,6 +16,7 @@
*/
package org.apache.dubbo.rpc.protocol.tri.rest.filter;
+import org.apache.dubbo.common.utils.ArrayUtils;
import org.apache.dubbo.rpc.protocol.tri.rest.util.RestUtils;
import java.util.Arrays;
@@ -47,7 +48,7 @@ public abstract class AbstractRestFilter<E> implements RestFilter {
sb.append(", priority=").append(priority);
}
String[] patterns = getPatterns();
- if (patterns != null) {
+ if (ArrayUtils.isNotEmpty(patterns)) {
sb.append(", patterns=").append(Arrays.toString(patterns));
}
return sb.append('}').toString();
diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/filter/RestExtensionExecutionFilter.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/filter/RestExtensionExecutionFilter.java
index 4a37f28ca0..a0067522d6 100644
--- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/filter/RestExtensionExecutionFilter.java
+++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/filter/RestExtensionExecutionFilter.java
@@ -21,6 +21,10 @@ import org.apache.dubbo.common.beans.support.InstantiationStrategy;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.common.extension.ExtensionAccessorAware;
+import org.apache.dubbo.common.logger.Logger;
+import org.apache.dubbo.common.logger.LoggerFactory;
+import org.apache.dubbo.common.utils.ArrayUtils;
+import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.remoting.http12.HttpRequest;
import org.apache.dubbo.remoting.http12.HttpResponse;
@@ -35,20 +39,27 @@ import org.apache.dubbo.rpc.protocol.tri.ExceptionUtils;
import org.apache.dubbo.rpc.protocol.tri.rest.Messages;
import org.apache.dubbo.rpc.protocol.tri.rest.RestConstants;
import org.apache.dubbo.rpc.protocol.tri.rest.RestInitializeException;
+import org.apache.dubbo.rpc.protocol.tri.rest.mapping.RadixTree;
+import org.apache.dubbo.rpc.protocol.tri.rest.mapping.RadixTree.Match;
import org.apache.dubbo.rpc.protocol.tri.rest.util.RestUtils;
import org.apache.dubbo.rpc.protocol.tri.rest.util.TypeUtils;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.BitSet;
import java.util.Comparator;
import java.util.List;
+import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.function.Supplier;
@Activate(group = CommonConstants.PROVIDER, order = 1000)
public class RestExtensionExecutionFilter extends RestFilterAdapter {
+ private static final Logger LOGGER = LoggerFactory.getLogger(RestExtensionExecutionFilter.class);
private static final String KEY = RestExtensionExecutionFilter.class.getSimpleName();
+ private final Map<RestFilter, RadixTree<Boolean>> filterTreeCache = CollectionUtils.newConcurrentHashMap();
private final ApplicationModel applicationModel;
private final List<RestExtensionAdapter<Object>> extensionAdapters;
@@ -61,7 +72,7 @@ public class RestExtensionExecutionFilter extends RestFilterAdapter {
@Override
protected Result invoke(Invoker<?> invoker, Invocation invocation, HttpRequest request, HttpResponse response)
throws RpcException {
- RestFilter[] filters = getFilters(invoker);
+ RestFilter[] filters = matchFilters(getFilters(invoker), request.path());
DefaultFilterChain chain = new DefaultFilterChain(filters, invocation, () -> invoker.invoke(invocation));
invocation.put(KEY, chain);
try {
@@ -127,13 +138,65 @@ public class RestExtensionExecutionFilter extends RestFilterAdapter {
chain.onError(t, request, response);
}
+ private RestFilter[] matchFilters(RestFilter[] filters, String path) {
+ int len = filters.length;
+ BitSet bitSet = new BitSet(len);
+ out:
+ for (int i = 0; i < len; i++) {
+ RestFilter filter = filters[i];
+ String[] patterns = filter.getPatterns();
+ if (ArrayUtils.isEmpty(patterns)) {
+ continue;
+ }
+ RadixTree<Boolean> filterTree = filterTreeCache.computeIfAbsent(filter, f -> {
+ RadixTree<Boolean> tree = new RadixTree<>();
+ for (String pattern : patterns) {
+ if (StringUtils.isNotEmpty(pattern)) {
+ if (pattern.charAt(0) == '!') {
+ tree.addPath(pattern.substring(1), false);
+ } else {
+ tree.addPath(pattern, true);
+ }
+ }
+ }
+ return tree;
+ });
+
+ List<Match<Boolean>> matches = filterTree.match(path);
+ int size = matches.size();
+ if (size == 0) {
+ bitSet.set(i);
+ continue;
+ }
+ for (int j = 0; j < size; j++) {
+ if (!matches.get(j).getValue()) {
+ bitSet.set(i);
+ continue out;
+ }
+ }
+ }
+ if (bitSet.isEmpty()) {
+ return filters;
+ }
+ RestFilter[] matched = new RestFilter[len - bitSet.cardinality()];
+ for (int i = 0, j = 0; i < len; i++) {
+ if (!bitSet.get(i)) {
+ matched[j++] = filters[i];
+ }
+ }
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug("Matched filters for path '{}' is {}", path, Arrays.toString(matched));
+ }
+ return matched;
+ }
+
+ @SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
private RestFilter[] getFilters(Invoker<?> invoker) {
URL url = invoker.getUrl();
RestFilter[] filters = getFilters(url);
if (filters != null) {
return filters;
}
- //noinspection SynchronizationOnLocalVariableOrMethodParameter
synchronized (invoker) {
filters = getFilters(url);
if (filters != null) {
@@ -150,6 +213,7 @@ public class RestExtensionExecutionFilter extends RestFilterAdapter {
}
private RestFilter[] loadFilters(URL url) {
+ LOGGER.info("Loading rest filters for {}", url);
List<RestFilter> extensions = new ArrayList<>();
// 1. load from extension config
@@ -186,13 +250,29 @@ public class RestExtensionExecutionFilter extends RestFilterAdapter {
extension = ((Supplier<?>) extension).get();
}
if (extension instanceof RestFilter) {
- extensions.add((RestFilter) extension);
+ addRestFilter(extension, (RestFilter) extension, extensions);
return;
}
for (RestExtensionAdapter<Object> adapter : extensionAdapters) {
if (adapter.accept(extension)) {
- extensions.add(adapter.adapt(extension));
+ addRestFilter(extension, adapter.adapt(extension), extensions);
}
}
}
+
+ private void addRestFilter(Object extension, RestFilter filter, List<RestFilter> extensions) {
+ extensions.add(filter);
+ if (!LOGGER.isInfoEnabled()) {
+ return;
+ }
+ StringBuilder sb = new StringBuilder(64);
+ sb.append("Rest filter [").append(extension).append("] loaded");
+ if (filter.getPriority() != 0) {
+ sb.append(", priority=").append(filter.getPriority());
+ }
+ if (ArrayUtils.isNotEmpty(filter.getPatterns())) {
+ sb.append(", patterns=").append(Arrays.toString(filter.getPatterns()));
+ }
+ LOGGER.info(sb.toString());
+ }
}
diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/mapping/RadixTree.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/mapping/RadixTree.java
index 7e45bced4e..809f3437fb 100644
--- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/mapping/RadixTree.java
+++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/mapping/RadixTree.java
@@ -145,7 +145,6 @@ public final class RadixTree<T> {
for (int i = 0, size = directMatches.size(); i < size; i++) {
matches.add(directMatches.get(i));
}
- return;
}
matchRecursive(root, path, 1, new HashMap<>(), matches);
@@ -157,11 +156,12 @@ public final class RadixTree<T> {
public List<Match<T>> match(KeyString path) {
List<Match<T>> matches = directPathMap.get(path);
- if (matches != null) {
- return new ArrayList<>(matches);
+ if (matches == null) {
+ matches = new ArrayList<>();
+ } else {
+ matches = new ArrayList<>(matches);
}
- matches = new ArrayList<>();
matchRecursive(root, path, 1, new HashMap<>(), matches);
return matches;
}
@@ -175,8 +175,10 @@ public final class RadixTree<T> {
int end = path.indexOf('/', start);
Node<T> node = current.children.get(new KeyString(path, start, end));
if (node != null) {
- if (node.isLeaf()) {
- addMatch(node, variableMap, matches);
+ if (end == -1) {
+ if (node.isLeaf()) {
+ addMatch(node, variableMap, matches);
+ }
return;
}
matchRecursive(node, path, end + 1, variableMap, matches);
@@ -191,13 +193,19 @@ public final class RadixTree<T> {
if (segment.match(path, start, end, workVariableMap)) {
workVariableMap.putAll(variableMap);
Node<T> child = entry.getValue();
- if (segment.isTailMatching() || child.isLeaf()) {
+ if (segment.isTailMatching()) {
addMatch(child, workVariableMap, matches);
} else {
- matchRecursive(child, path, end + 1, workVariableMap, matches);
+ if (end == -1) {
+ if (child.isLeaf()) {
+ addMatch(child, workVariableMap, matches);
+ }
+ } else {
+ matchRecursive(child, path, end + 1, workVariableMap, matches);
+ }
}
if (!workVariableMap.isEmpty()) {
- workVariableMap = new HashMap<>();
+ workVariableMap = new LinkedHashMap<>();
}
}
}
diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/mapping/condition/PathExpression.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/mapping/condition/PathExpression.java
index ead98873a0..06b48d4f09 100644
--- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/mapping/condition/PathExpression.java
+++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/mapping/condition/PathExpression.java
@@ -61,17 +61,21 @@ public final class PathExpression implements Comparable<PathExpression> {
}
Map<String, String> variableMap = new LinkedHashMap<>();
int start, end = 0;
- for (PathSegment segment : segments) {
+ for (int i = 0, len = segments.length; i < len; i++) {
+ PathSegment segment = segments[i];
if (end != -1) {
start = end + 1;
end = path.indexOf('/', start);
if (segment.match(new KeyString(path), start, end, variableMap)) {
+ if (i == len - 1 && segment.isTailMatching()) {
+ return variableMap;
+ }
continue;
}
}
return null;
}
- return variableMap;
+ return end == -1 ? variableMap : null;
}
public int compareTo(PathExpression other, String lookupPath) {
diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/util/KeyString.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/util/KeyString.java
index 2ddac3c70c..681ef6768f 100644
--- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/util/KeyString.java
+++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/util/KeyString.java
@@ -96,12 +96,12 @@ public final class KeyString implements CharSequence {
@Override
public String toString() {
- return value.substring(offset, length - offset);
+ return value.substring(offset, offset + length);
}
public int indexOf(char ch, int start) {
int index = value.indexOf(ch, offset + start);
- return index == -1 ? -1 : index - offset;
+ return index == -1 || index >= offset + length ? -1 : index - offset;
}
public boolean regionMatches(int start, String value, int i, int length) {
diff --git a/dubbo-rpc/dubbo-rpc-triple/src/test/groovy/org/apache/dubbo/rpc/protocol/tri/rest/filter/RestFilterTest.groovy b/dubbo-rpc/dubbo-rpc-triple/src/test/groovy/org/apache/dubbo/rpc/protocol/tri/rest/filter/RestFilterTest.groovy
new file mode 100644
index 0000000000..2affdd5a09
--- /dev/null
+++ b/dubbo-rpc/dubbo-rpc-triple/src/test/groovy/org/apache/dubbo/rpc/protocol/tri/rest/filter/RestFilterTest.groovy
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.dubbo.rpc.protocol.tri.rest.filter
+
+import org.apache.dubbo.common.URL
+import org.apache.dubbo.rpc.Invoker
+import org.apache.dubbo.rpc.model.ApplicationModel
+
+import spock.lang.Specification
+
+class RestFilterTest extends Specification {
+
+ @SuppressWarnings('GroovyAccessibility')
+ def "test filter patterns"() {
+ given:
+ Invoker invoker = Mock(Invoker)
+ invoker.getUrl() >> URL.valueOf("tri://127.0.0.1/test?extension=org.apache.dubbo.rpc.protocol.tri.rest.filter.TestRestFilter")
+
+ var filter = new RestExtensionExecutionFilter(ApplicationModel.defaultModel())
+ expect:
+ filter.matchFilters(filter.getFilters(invoker), path).length == len
+ where:
+ path | len
+ '/filter/one' | 1
+ '/filter/one/1' | 1
+ '/one.filter' | 2
+ '/filter/two' | 2
+ }
+
+}
diff --git a/dubbo-rpc/dubbo-rpc-triple/src/test/groovy/org/apache/dubbo/rpc/protocol/tri/rest/mapping/RadixTreeTest.groovy b/dubbo-rpc/dubbo-rpc-triple/src/test/groovy/org/apache/dubbo/rpc/protocol/tri/rest/mapping/RadixTreeTest.groovy
index 35bbe55031..b40080486d 100644
--- a/dubbo-rpc/dubbo-rpc-triple/src/test/groovy/org/apache/dubbo/rpc/protocol/tri/rest/mapping/RadixTreeTest.groovy
+++ b/dubbo-rpc/dubbo-rpc-triple/src/test/groovy/org/apache/dubbo/rpc/protocol/tri/rest/mapping/RadixTreeTest.groovy
@@ -21,7 +21,7 @@ import spock.lang.Specification
class RadixTreeTest extends Specification {
- def "Match"() {
+ def "match"() {
given:
def tree = new RadixTree<String>()
tree.addPath('/a/*', 'abc')
@@ -33,7 +33,7 @@ class RadixTreeTest extends Specification {
!match.empty
}
- def "Clear"() {
+ def "clear"() {
given:
def tree = new RadixTree<String>()
tree.addPath('/a/*', 'abc')
@@ -44,4 +44,18 @@ class RadixTreeTest extends Specification {
then:
tree.empty
}
+
+ def "test end match"() {
+ given:
+ def tree = new RadixTree<Boolean>()
+ tree.addPath('/a/*/*', true)
+ expect:
+ tree.match(path).size() == len
+ where:
+ path | len
+ '/a' | 0
+ '/a/b' | 0
+ '/a/b/c' | 1
+ '/a/b/c/d' | 0
+ }
}
diff --git a/dubbo-rpc/dubbo-rpc-triple/src/test/groovy/org/apache/dubbo/rpc/protocol/tri/rest/mapping/condition/PathExpressionTest.groovy b/dubbo-rpc/dubbo-rpc-triple/src/test/groovy/org/apache/dubbo/rpc/protocol/tri/rest/mapping/condition/PathExpressionTest.groovy
index cbcec0922e..1061fcea65 100644
--- a/dubbo-rpc/dubbo-rpc-triple/src/test/groovy/org/apache/dubbo/rpc/protocol/tri/rest/mapping/condition/PathExpressionTest.groovy
+++ b/dubbo-rpc/dubbo-rpc-triple/src/test/groovy/org/apache/dubbo/rpc/protocol/tri/rest/mapping/condition/PathExpressionTest.groovy
@@ -173,7 +173,7 @@ class PathExpressionTest extends Specification {
'/resources/**' | '/resources/a/b/c' | true
'/resources/{*path}' | '/resources/a/b/c' | [path: 'a/b/c']
'/resources/*' | '/resources/a' | true
- '/resources/*' | '/resources/a/b/c' | true
+ '/resources/{*}' | '/resources/a/b/c' | true
'/{id:\\d+}' | '/123' | [id: '123']
'/{id:\\d+}' | '/one' | false
'/a?cd/ef' | '/abcd/ef' | true
@@ -194,8 +194,8 @@ class PathExpressionTest extends Specification {
expect:
parse(path).match(value) != null
where:
- path | value
- '/resources/*' | '/resources/a/b/c'
+ path | value
+ '/resources/{*}' | '/resources/a/b/c'
}
def "CompareTo"() {
diff --git a/dubbo-rpc/dubbo-rpc-triple/src/test/java/org/apache/dubbo/rpc/protocol/tri/rest/filter/TestRestFilter.java b/dubbo-rpc/dubbo-rpc-triple/src/test/java/org/apache/dubbo/rpc/protocol/tri/rest/filter/TestRestFilter.java
new file mode 100644
index 0000000000..6a732d26e9
--- /dev/null
+++ b/dubbo-rpc/dubbo-rpc-triple/src/test/java/org/apache/dubbo/rpc/protocol/tri/rest/filter/TestRestFilter.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.rpc.protocol.tri.rest.filter;
+
+import org.apache.dubbo.common.logger.Logger;
+import org.apache.dubbo.common.logger.LoggerFactory;
+import org.apache.dubbo.remoting.http12.HttpRequest;
+import org.apache.dubbo.remoting.http12.HttpResponse;
+import org.apache.dubbo.rpc.Result;
+import org.apache.dubbo.rpc.protocol.tri.rest.filter.RestFilter.Listener;
+
+public class TestRestFilter implements RestFilter, Listener {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(TestRestFilter.class);
+
+ private final int priority;
+ private final String[] patterns;
+
+ public TestRestFilter() {
+ this(50);
+ }
+
+ public TestRestFilter(int priority, String... patterns) {
+ this.priority = priority;
+ this.patterns = patterns;
+ }
+
+ @Override
+ public int getPriority() {
+ return priority;
+ }
+
+ @Override
+ public String[] getPatterns() {
+ return patterns;
+ }
+
+ @Override
+ public void doFilter(HttpRequest request, HttpResponse response, FilterChain chain) throws Exception {
+ LOGGER.info("{} path '{}' doFilter", request.path(), this);
+ chain.doFilter(request, response);
+ }
+
+ @Override
+ public void onResponse(Result result, HttpRequest request, HttpResponse response) throws Exception {
+ LOGGER.info("{} path '{}' onResponse", request.path(), this);
+ }
+
+ @Override
+ public void onError(Throwable t, HttpRequest request, HttpResponse response) throws Exception {
+ LOGGER.info("{} path '{}' onError", request.path(), this);
+ }
+}
diff --git a/dubbo-rpc/dubbo-rpc-triple/src/test/java/org/apache/dubbo/rpc/protocol/tri/rest/filter/TestRestFilterFactory.java b/dubbo-rpc/dubbo-rpc-triple/src/test/java/org/apache/dubbo/rpc/protocol/tri/rest/filter/TestRestFilterFactory.java
new file mode 100644
index 0000000000..98bc11e0ee
--- /dev/null
+++ b/dubbo-rpc/dubbo-rpc-triple/src/test/java/org/apache/dubbo/rpc/protocol/tri/rest/filter/TestRestFilterFactory.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.rpc.protocol.tri.rest.filter;
+
+import org.apache.dubbo.common.extension.Activate;
+
+import java.util.function.Supplier;
+
+@Activate
+public class TestRestFilterFactory implements RestExtension, Supplier<RestFilter> {
+
+ @Override
+ public RestFilter get() {
+ return new TestRestFilter(100, "/filter/*", "/*.filter", "!/filter/one");
+ }
+}
diff --git a/dubbo-rpc/dubbo-rpc-triple/src/test/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.protocol.tri.rest.filter.RestExtension b/dubbo-rpc/dubbo-rpc-triple/src/test/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.protocol.tri.rest.filter.RestExtension
index e69de29bb2..364b5759c2 100644
--- a/dubbo-rpc/dubbo-rpc-triple/src/test/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.protocol.tri.rest.filter.RestExtension
+++ b/dubbo-rpc/dubbo-rpc-triple/src/test/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.protocol.tri.rest.filter.RestExtension
@@ -0,0 +1 @@
+test-rest-filter-factory=org.apache.dubbo.rpc.protocol.tri.rest.filter.TestRestFilterFactory