Skip to content

Commit

Permalink
Enhance parameter resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
oxsean committed Nov 26, 2024
1 parent 73eafc1 commit ecf7420
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.apache.dubbo.remoting.http12.HttpRequest;
import org.apache.dubbo.remoting.http12.HttpResponse;
import org.apache.dubbo.remoting.http12.rest.ParamType;
import org.apache.dubbo.rpc.model.FrameworkModel;
import org.apache.dubbo.rpc.protocol.tri.rest.Messages;
import org.apache.dubbo.rpc.protocol.tri.rest.mapping.meta.AnnotationMeta;
Expand Down Expand Up @@ -89,8 +90,12 @@ public NamedValueMeta getNamedValueMeta(ParameterMeta parameter) {
}

for (ArgumentResolver resolver : resolvers) {
if (resolver.accept(parameter) && resolver instanceof AbstractArgumentResolver) {
return ((AbstractArgumentResolver) resolver).getNamedValueMeta(parameter);
if (resolver.accept(parameter)) {
if (resolver instanceof AbstractArgumentResolver) {
return ((AbstractArgumentResolver) resolver).getNamedValueMeta(parameter);
} else {
return new NamedValueMeta().setParamType(ParamType.Attribute);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ public ConstructorParameterMeta[] getParameters() {
private ConstructorParameterMeta[] initParameters(RestToolKit toolKit, String prefix, Constructor<?> ct) {
Parameter[] cps = ct.getParameters();
int len = cps.length;
if (len == 0) {
return new ConstructorParameterMeta[0];
}
String[] parameterNames = toolKit == null ? null : toolKit.getParameterNames(ct);
ConstructorParameterMeta[] parameters = new ConstructorParameterMeta[len];
for (int i = 0; i < len; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ public static Collection<String> guessHttpMethod(MethodMeta method) {
if (GET.name().equals(httpMethod)) {
for (ParameterMeta parameter : method.getParameters()) {
ParamType paramType = parameter.getNamedValueMeta().paramType();
if (paramType != null) {
if (paramType == null) {
if (parameter.isSimple()) {
continue;
}
return Arrays.asList(GET.name(), POST.name());
} else {
switch (paramType) {
case Form:
case Part:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.dubbo.common.utils.ArrayUtils;
import org.apache.dubbo.common.utils.ClassUtils;
import org.apache.dubbo.common.utils.ConcurrentHashSet;
import org.apache.dubbo.common.utils.StringUtils;

import java.io.File;
import java.lang.reflect.Array;
Expand Down Expand Up @@ -128,14 +129,23 @@ public static List<String> getSystemPrefixes() {
}

public static void addSystemPrefixes(String... prefixes) {
SYSTEM_PREFIXES.addAll(Arrays.asList(prefixes));
for (String prefix : prefixes) {
if (StringUtils.isNotEmpty(prefix)) {
SYSTEM_PREFIXES.add(prefix);
}
}
}

public static boolean isSystemType(Class<?> type) {
String name = type.getName();
List<String> systemPrefixes = getSystemPrefixes();
for (int i = 0, size = systemPrefixes.size(); i < size; i++) {
if (name.startsWith(systemPrefixes.get(i))) {
for (int i = systemPrefixes.size() - 1; i >= 0; i--) {
String prefix = systemPrefixes.get(i);
if (prefix.charAt(0) == '!') {
if (name.regionMatches(0, prefix, 1, prefix.length() - 1)) {
return false;
}
} else if (name.startsWith(prefix)) {
return true;
}
}
Expand Down

0 comments on commit ecf7420

Please sign in to comment.