处理参数2次URLEncoding问题
This commit is contained in:
parent
b16f79d0dc
commit
b2b2db4b02
@ -19,7 +19,6 @@ import java.io.UnsupportedEncodingException;
|
|||||||
import java.lang.reflect.InvocationHandler;
|
import java.lang.reflect.InvocationHandler;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Parameter;
|
import java.lang.reflect.Parameter;
|
||||||
import java.net.URLEncoder;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -49,7 +48,7 @@ public class RestRemoteHandler implements InvocationHandler {
|
|||||||
* @param args
|
* @param args
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Object handle(Method method, Object[] args) throws UnsupportedEncodingException {
|
public Object handle(Method method, Object[] args) {
|
||||||
if (method.getParameters().length == 0) {
|
if (method.getParameters().length == 0) {
|
||||||
throw new ParamsException("方法没有参数");
|
throw new ParamsException("方法没有参数");
|
||||||
}
|
}
|
||||||
@ -124,7 +123,7 @@ public class RestRemoteHandler implements InvocationHandler {
|
|||||||
* @param parameters
|
* @param parameters
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private Map<String, String> getPathVariableParams(Parameter[] parameters, Object[] args) throws UnsupportedEncodingException {
|
private Map<String, String> getPathVariableParams(Parameter[] parameters, Object[] args) {
|
||||||
Map<String, String> pathVariableParamsMap = new HashMap<>();
|
Map<String, String> pathVariableParamsMap = new HashMap<>();
|
||||||
for (int i = 0; i < parameters.length; i++) {
|
for (int i = 0; i < parameters.length; i++) {
|
||||||
Parameter parameter = parameters[i];
|
Parameter parameter = parameters[i];
|
||||||
@ -140,7 +139,7 @@ public class RestRemoteHandler implements InvocationHandler {
|
|||||||
if (arg == null) {
|
if (arg == null) {
|
||||||
throw new SystemException("路径参数不能为空: " + variableName);
|
throw new SystemException("路径参数不能为空: " + variableName);
|
||||||
}
|
}
|
||||||
pathVariableParamsMap.put(variableName, URLEncoder.encode(String.valueOf(arg), "UTF-8"));
|
pathVariableParamsMap.put(variableName, String.valueOf(arg));
|
||||||
}
|
}
|
||||||
return pathVariableParamsMap;
|
return pathVariableParamsMap;
|
||||||
}
|
}
|
||||||
@ -152,7 +151,7 @@ public class RestRemoteHandler implements InvocationHandler {
|
|||||||
* @param args
|
* @param args
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private Map<String, String> getQueryVariableParams(Parameter[] parameters, Object[] args) throws UnsupportedEncodingException {
|
private Map<String, String> getQueryVariableParams(Parameter[] parameters, Object[] args) {
|
||||||
Map<String, String> queryVariableParamsMap = new HashMap<>();
|
Map<String, String> queryVariableParamsMap = new HashMap<>();
|
||||||
for (int i = 0; i < parameters.length; i++) {
|
for (int i = 0; i < parameters.length; i++) {
|
||||||
Parameter parameter = parameters[i];
|
Parameter parameter = parameters[i];
|
||||||
@ -168,7 +167,7 @@ public class RestRemoteHandler implements InvocationHandler {
|
|||||||
if (arg == null) {
|
if (arg == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
queryVariableParamsMap.put(variableName, URLEncoder.encode(String.valueOf(arg), "UTF-8"));
|
queryVariableParamsMap.put(variableName, String.valueOf(arg));
|
||||||
}
|
}
|
||||||
return queryVariableParamsMap;
|
return queryVariableParamsMap;
|
||||||
}
|
}
|
||||||
@ -259,7 +258,7 @@ public class RestRemoteHandler implements InvocationHandler {
|
|||||||
* @return
|
* @return
|
||||||
* @throws UnsupportedEncodingException
|
* @throws UnsupportedEncodingException
|
||||||
*/
|
*/
|
||||||
private Map<String, String> getQueryMapParams(Parameter[] parameters, Object[] args) throws UnsupportedEncodingException {
|
private Map<String, String> getQueryMapParams(Parameter[] parameters, Object[] args) {
|
||||||
for (int i = 0; i < parameters.length; i++) {
|
for (int i = 0; i < parameters.length; i++) {
|
||||||
Parameter parameter = parameters[i];
|
Parameter parameter = parameters[i];
|
||||||
if (!parameter.isAnnotationPresent(RemoteQueryParamsMap.class)) {
|
if (!parameter.isAnnotationPresent(RemoteQueryParamsMap.class)) {
|
||||||
@ -274,7 +273,7 @@ public class RestRemoteHandler implements InvocationHandler {
|
|||||||
Map<String, Object> argMap = (Map<String, Object>) args[i];
|
Map<String, Object> argMap = (Map<String, Object>) args[i];
|
||||||
Map<String, String> queryMap = new HashMap<>();
|
Map<String, String> queryMap = new HashMap<>();
|
||||||
for (Map.Entry<String, Object> kv : argMap.entrySet()) {
|
for (Map.Entry<String, Object> kv : argMap.entrySet()) {
|
||||||
queryMap.put(kv.getKey(), URLEncoder.encode(String.valueOf(kv.getValue()), "UTF-8"));
|
queryMap.put(kv.getKey(), String.valueOf(kv.getValue()));
|
||||||
}
|
}
|
||||||
return queryMap;
|
return queryMap;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user