Skip to content

Commit

Permalink
Merge branch 'master' into fix-5893
Browse files Browse the repository at this point in the history
  • Loading branch information
Aias00 authored Jan 21, 2025
2 parents 2db4698 + 8f3a1d0 commit f49be50
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@ Thumbs.db

# rust ignore
*.lock

.factorypath
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@

package org.apache.shenyu.plugin.api.utils;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang3.ClassUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
Expand All @@ -27,12 +32,10 @@
import org.apache.shenyu.common.utils.ReflectUtils;
import org.springframework.util.LinkedMultiValueMap;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;

/**
* Common rpc parameter builder utils.
Expand All @@ -41,6 +44,11 @@ public final class BodyParamUtils {

private static final Pattern QUERY_PARAM_PATTERN = Pattern.compile("([^&=]+)(=?)([^&]+)?");

// Caffeine cache with maximum size of 5000
private static final Cache<String, Boolean> BASE_TYPE_CACHE = Caffeine.newBuilder()
.maximumSize(5000)
.build();

private BodyParamUtils() {
}

Expand Down Expand Up @@ -127,17 +135,20 @@ private static boolean isNameMapping(final String parameterTypes) {
return parameterTypes.startsWith("{") && parameterTypes.endsWith("}");
}


/**
* isBaseType.
*
* @param paramType the parameter type.
* @return whether the base type is.
*/
private static boolean isBaseType(final String paramType) {
try {
return ReflectUtils.isPrimitives(ClassUtils.getClass(paramType));
} catch (ClassNotFoundException e) {
return false;
}
return BASE_TYPE_CACHE.get(paramType, key -> {
try {
return ReflectUtils.isPrimitives(ClassUtils.getClass(key));
} catch (ClassNotFoundException e) {
return false;
}
});
}
}

0 comments on commit f49be50

Please sign in to comment.