|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
package com.fanruan.proxy.interceptor; |
|
|
|
|
|
|
|
|
|
import com.esotericsoftware.kryo.Kryo; |
|
|
|
|
import com.fanruan.annotation.*; |
|
|
|
|
import com.fanruan.pojo.message.RpcRequest; |
|
|
|
|
import com.fanruan.service.jdbc.AbstractBind; |
|
|
|
@ -10,6 +11,7 @@ import com.fanruan.utils.Commons;
|
|
|
|
|
import java.io.Reader; |
|
|
|
|
import java.lang.reflect.Method; |
|
|
|
|
import java.lang.reflect.Parameter; |
|
|
|
|
import java.sql.SQLException; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
@ -31,6 +33,7 @@ public class InterceptorUtils {
|
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
public static final Kryo kryo = new Kryo(); |
|
|
|
|
|
|
|
|
|
public static boolean isWraps(Object o){ |
|
|
|
|
Class<?> clz = o.getClass(); |
|
|
|
@ -96,7 +99,9 @@ public class InterceptorUtils {
|
|
|
|
|
return idToInvoke; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static RpcRequest generateRequest(Class<?> clazz, Object o, Method method, Object[] objects){ |
|
|
|
|
public static RpcRequest generateRequest(Class<?> clazz, Object o, Method method, Object[] objects) throws SQLException { |
|
|
|
|
checkObject(method, objects); |
|
|
|
|
|
|
|
|
|
RpcRequest rpcRequest = new RpcRequest(); |
|
|
|
|
rpcRequest |
|
|
|
|
.setID(Commons.getID()) |
|
|
|
@ -123,6 +128,29 @@ public class InterceptorUtils {
|
|
|
|
|
return rpcRequest; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static void checkObject(Method method, Object[] objects) throws SQLException { |
|
|
|
|
for (int i=0; i<objects.length; i++){ |
|
|
|
|
Object obj = objects[i]; |
|
|
|
|
if(obj == null){ |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
try{ |
|
|
|
|
if(kryo.getDefaultSerializer(obj.getClass()) != null){ |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
}catch (IllegalArgumentException e){ |
|
|
|
|
// When kryo hasn't default serializer to handler obj, the IllegalArgumentException will be thrown.
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
obj.getClass().getDeclaredConstructor(); |
|
|
|
|
}catch (NoSuchMethodException e){ |
|
|
|
|
throw new SQLException("can't invoke " + method.getName() + "dose not have no-arg constructor"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static boolean isNotImplemented(Method method) { |
|
|
|
|
return method.isAnnotationPresent(NotImplemented.class); |
|
|
|
|
} |
|
|
|
@ -131,7 +159,5 @@ public class InterceptorUtils {
|
|
|
|
|
return method.isAnnotationPresent(LocalMethod.class); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static boolean isWithBindingParameter(Method method){ |
|
|
|
|
return method.isAnnotationPresent(WithBindingParameter.class); |
|
|
|
|
} |
|
|
|
|
public static boolean isWithBindingParameter(Method method){ return method.isAnnotationPresent(WithBindingParameter.class); } |
|
|
|
|
} |
|
|
|
|