mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
Merge branch 'master' of https://github.com/AlibabaTech/druid
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package com.alibaba.druid.util;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@@ -20,13 +19,13 @@ public class ReflectionUtils {
|
||||
try {
|
||||
result = HttpServletRequest.class.getClassLoader().loadClass(className);
|
||||
} catch (ClassNotFoundException e) {
|
||||
LOG.warn(e.getMessage(), e);
|
||||
if (LOG.isDebugEnabled()) LOG.debug("can'r find class in web container classLoader ", e);
|
||||
}
|
||||
if (result == null) {
|
||||
try {
|
||||
result = Thread.currentThread().getContextClassLoader().loadClass(className);
|
||||
} catch (ClassNotFoundException e) {
|
||||
LOG.warn(e.getMessage(), e);
|
||||
LOG.error("can'r find class in current thread context classLoader ", e);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@@ -38,33 +37,19 @@ public class ReflectionUtils {
|
||||
Method m = classObject.getMethod(methodName);
|
||||
return m.invoke(classObject);
|
||||
} catch (Exception e) {
|
||||
LOG.error(e.getMessage(), e);
|
||||
LOG.warn("callStaticMethod fail:class=" + classObject.getName() + " method=" + methodName, e);
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Object callObjectMethod(Object obj, String methodName) {
|
||||
public static Object callObjectMethod(Object obj, String methodName, Object... methodParams) {
|
||||
try {
|
||||
Constructor<?> ctor = ((Class<?>) obj).getConstructor();
|
||||
Object instance = ctor.newInstance();
|
||||
Method m = ((Class<?>) obj).getMethod(methodName); // 获取方法
|
||||
return m.invoke(instance);
|
||||
Method m = obj.getClass().getMethod(methodName);
|
||||
return m.invoke(obj, methodParams);
|
||||
} catch (Exception e) {
|
||||
LOG.error(e.getMessage(), e);
|
||||
LOG.warn("callObjectMethod fail:class=" + obj.getClass().getName() + " method=" + methodName, e);
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Object callObjectMethod(Object obj, String methodName, Object methodParam) {
|
||||
try {
|
||||
Constructor<?> ctor = ((Class<?>) obj).getConstructor();
|
||||
Object instance = ctor.newInstance();
|
||||
Method m = ((Class<?>) obj).getMethod(methodName, methodParam.getClass()); // 获取方法
|
||||
return m.invoke(instance);
|
||||
} catch (Exception e) {
|
||||
LOG.error(e.getMessage(), e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void getTest() {
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.alibaba.druid.util;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.druid.support.logging.Log;
|
||||
import com.alibaba.druid.support.logging.LogFactory;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
|
||||
/**
|
||||
@@ -10,6 +12,8 @@ import com.alibaba.fastjson.JSON;
|
||||
*/
|
||||
public class StringUtils {
|
||||
|
||||
private final static Log LOG = LogFactory.getLog(StringUtils.class);
|
||||
|
||||
/**
|
||||
* Example: subString("12345","1","4")=23
|
||||
*
|
||||
@@ -52,6 +56,7 @@ public class StringUtils {
|
||||
try {
|
||||
return Integer.parseInt(in);
|
||||
} catch (NumberFormatException e) {
|
||||
LOG.warn("stringToInteger fail,string=" + in, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -67,6 +72,7 @@ public class StringUtils {
|
||||
try {
|
||||
return Long.parseLong(in);
|
||||
} catch (NumberFormatException e) {
|
||||
LOG.warn("stringToLong fail,string=" + in, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user