use of net.sf.cglib.proxy.MethodProxy in project dubbo by alibaba.
the class ProxyTest method testCglibProxy.
@Test
public void testCglibProxy() throws Exception {
ITest test = (ITest) Proxy.getProxy(ITest.class).newInstance(new InvocationHandler() {
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
System.out.println(method.getName());
return null;
}
});
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(test.getClass());
enhancer.setCallback(new MethodInterceptor() {
public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
return null;
}
});
try {
enhancer.create();
} catch (IllegalArgumentException e) {
e.printStackTrace();
Assert.fail();
}
}
use of net.sf.cglib.proxy.MethodProxy in project tomee by apache.
the class SeiFactoryImpl method initialize.
void initialize(Object serviceImpl, ClassLoader classLoader) throws ClassNotFoundException {
this.serviceImpl = serviceImpl;
Class serviceEndpointBaseClass = classLoader.loadClass(serviceEndpointClassName);
serviceEndpointClass = enhanceServiceEndpointInterface(serviceEndpointBaseClass, classLoader);
Class[] constructorTypes = new Class[] { classLoader.loadClass(GenericServiceEndpoint.class.getName()) };
this.constructor = FastClass.create(serviceEndpointClass).getConstructor(constructorTypes);
this.handlerInfoChainFactory = new HandlerInfoChainFactory(handlerInfos);
sortedOperationInfos = new OperationInfo[FastClass.create(serviceEndpointClass).getMaxIndex() + 1];
String encodingStyle = "";
for (int i = 0; i < operationInfos.length; i++) {
OperationInfo operationInfo = operationInfos[i];
Signature signature = operationInfo.getSignature();
MethodProxy methodProxy = MethodProxy.find(serviceEndpointClass, signature);
if (methodProxy == null) {
throw new ServerRuntimeException("No method proxy for operationInfo " + signature);
}
int index = methodProxy.getSuperIndex();
sortedOperationInfos[index] = operationInfo;
if (operationInfo.getOperationDesc().getUse() == Use.ENCODED) {
encodingStyle = org.apache.axis.Constants.URI_SOAP11_ENC;
}
}
//register our type descriptors
Service service = ((ServiceImpl) serviceImpl).getService();
AxisEngine axisEngine = service.getEngine();
TypeMappingRegistry typeMappingRegistry = axisEngine.getTypeMappingRegistry();
TypeMapping typeMapping = typeMappingRegistry.getOrMakeTypeMapping(encodingStyle);
typeMapping.register(BigInteger.class, Constants.XSD_UNSIGNEDLONG, new SimpleSerializerFactory(BigInteger.class, Constants.XSD_UNSIGNEDLONG), new SimpleDeserializerFactory(BigInteger.class, Constants.XSD_UNSIGNEDLONG));
typeMapping.register(URI.class, Constants.XSD_ANYURI, new SimpleSerializerFactory(URI.class, Constants.XSD_ANYURI), new SimpleDeserializerFactory(URI.class, Constants.XSD_ANYURI));
//It is essential that the types be registered before the typeInfos create the serializer/deserializers.
for (Iterator iter = typeInfo.iterator(); iter.hasNext(); ) {
TypeInfo info = (TypeInfo) iter.next();
TypeDesc.registerTypeDescForClass(info.getClazz(), info.buildTypeDesc());
}
TypeInfo.register(typeInfo, typeMapping);
}
use of net.sf.cglib.proxy.MethodProxy in project simplejpa by appoxy.
the class LazyInterceptor method handleSetMethod.
private void handleSetMethod(Object obj, Method method, Object[] args) throws Throwable {
// we basically want to mark this object as dirty if this is called and to only delete attributes if it's dirty
dirty = true;
String attributeName = NamingHelper.attributeName(method);
if (args != null && args.length == 1) {
Object valueToSet = args[0];
if (valueToSet == null) {
// FIXME support direct field accessors better here
PersistentMethod persistentMethod = (PersistentMethod) (PersistentMethod) em.getFactory().getAnnotationManager().getAnnotationInfo(obj).getPersistentProperty(attributeName);
Method getter = persistentMethod.getGetter();
MethodProxy getterProxy = MethodProxy.find(obj.getClass(), new Signature(persistentMethod.getGetter().getName(), Type.getType(getter.getReturnType()), new Type[] {}));
Object ret = getterProxy.invokeSuper(obj, null);
if (ret != null) {
nulledFields.put(attributeName, ret);
logger.fine("field " + attributeName + " is being nulled. Old value = " + ret);
}
}
}
}
use of net.sf.cglib.proxy.MethodProxy in project yyl_example by Relucent.
the class EnhancerTest method main.
public static void main(String[] args) {
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(null);
enhancer.setInterfaces(new Class[] { I.class });
enhancer.setCallback(new MethodInterceptor() {
@Override
public Object intercept(Object o, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
if (Object.class.equals(method.getDeclaringClass())) {
return methodProxy.invokeSuper(o, args);
}
System.out.println("->" + method.getName());
return null;
}
});
I a = I.class.cast(enhancer.create());
a.method();
}
use of net.sf.cglib.proxy.MethodProxy in project cloudstack by apache.
the class AsyncCallbackDispatcher method getTarget.
@SuppressWarnings("unchecked")
public T getTarget() {
Class<?> clz = _targetObject.getClass();
String clzName = clz.getName();
if (clzName.contains("EnhancerByCloudStack"))
clz = clz.getSuperclass();
Enhancer en = null;
synchronized (enMap) {
en = enMap.get(clz);
if (en == null) {
en = new Enhancer();
en.setSuperclass(clz);
en.setCallback(new MethodInterceptor() {
@Override
public Object intercept(Object arg0, Method arg1, Object[] arg2, MethodProxy arg3) throws Throwable {
return null;
}
});
enMap.put(clz, en);
}
}
try {
T t = (T) en.create();
Factory factory = (Factory) t;
factory.setCallback(0, new MethodInterceptor() {
@Override
public Object intercept(Object arg0, Method arg1, Object[] arg2, MethodProxy arg3) throws Throwable {
if (arg1.getParameterTypes().length == 0 && arg1.getName().equals("finalize")) {
return null;
} else {
_callbackMethod = arg1;
_callbackMethod.setAccessible(true);
return null;
}
}
});
return t;
} catch (Throwable e) {
s_logger.error("Unexpected exception", e);
}
return null;
}
Aggregations