List of usage examples for org.springframework.aop.framework ProxyFactory getProxy
public Object getProxy()
From source file:com.newlandframework.avatarmq.netty.MessageEventWrapper.java
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { super.channelRead(ctx, msg); ProxyFactory weaver = new ProxyFactory(wrapper); NameMatchMethodPointcutAdvisor advisor = new NameMatchMethodPointcutAdvisor(); advisor.setMappedName(MessageEventWrapper.proxyMappedName); advisor.setAdvice(new MessageEventAdvisor(wrapper, msg)); weaver.addAdvisor(advisor);/*from ww w. j a va 2 s .c o m*/ MessageEventHandler proxyObject = (MessageEventHandler) weaver.getProxy(); proxyObject.handleMessage(ctx, msg); }
From source file:net.paslavsky.springrest.SpringRestClientFactoryBean.java
@Override @SuppressWarnings("unchecked") protected T createInstance() throws Exception { ProxyFactory factory = new ProxyFactory(); if (getObjectType().isInterface()) { factory.setInterfaces(getObjectType()); } else {/*from w w w .j ava 2 s . c o m*/ factory.setTargetClass(getObjectType()); } factory.addAdvisor(createRestMethodAdvisor()); factory.addAdvisor(createToStringPointcutAdvisor()); return (T) factory.getProxy(); }
From source file:net.sf.oval.test.integration.spring.SpringAOPAllianceBeanValidationTest.java
public void testCGLIBProxying() { {/*from w ww . j a va 2 s . c om*/ final ProxyFactory prFactory = new ProxyFactory(new TestServiceWithoutInterface()); prFactory.setProxyTargetClass(true); prFactory.addAdvice(new GuardInterceptor(new Guard(new BeanValidationAnnotationsConfigurer()))); final TestServiceWithoutInterface testServiceWithoutInterface = (TestServiceWithoutInterface) prFactory .getProxy(); try { testServiceWithoutInterface.getSomething(null); fail(); } catch (final ConstraintsViolatedException ex) { assertEquals("NOT_NULL", ex.getConstraintViolations()[0].getMessage()); } try { testServiceWithoutInterface.getSomething("123456"); fail(); } catch (final ConstraintsViolatedException ex) { assertEquals("MAX_LENGTH", ex.getConstraintViolations()[0].getMessage()); } } { final ProxyFactory prFactory = new ProxyFactory(new TestServiceWithInterface()); prFactory.setProxyTargetClass(true); prFactory.addAdvice(new GuardInterceptor(new Guard(new BeanValidationAnnotationsConfigurer()))); final TestServiceWithInterface testServiceWithInterface = (TestServiceWithInterface) prFactory .getProxy(); try { testServiceWithInterface.getSomething(null); fail(); } catch (final ConstraintsViolatedException ex) { assertEquals("NOT_NULL", ex.getConstraintViolations()[0].getMessage()); } try { testServiceWithInterface.getSomething("123456"); fail(); } catch (final ConstraintsViolatedException ex) { assertEquals("MAX_LENGTH", ex.getConstraintViolations()[0].getMessage()); } } }
From source file:org.LexGrid.LexBIG.caCore.client.proxy.LexEVSProxyHelperImpl.java
@Override protected Object convertObjectToProxy(ApplicationService as, Object obj) { if (null == obj) return null; //Check to see if the returned object is an EVSRemoteExecutionResults. //If so, unwrap it and update the proxy target if (obj instanceof RemoteExecutionResults) { RemoteExecutionResults results = (RemoteExecutionResults) obj; //if the returned results are null, return null if (results.getReturnValue() == null) return null; //Get the current proxy target and update it with the retuned value //from the server Advised advised = (Advised) AopContext.currentProxy(); advised.setTargetSource(new SingletonTargetSource(results.getObj())); obj = results.getReturnValue();// ww w. j ava 2 s.c o m } if (obj instanceof RemoteShell) { Class<?>[] targetInterfaces = ((RemoteShell) obj).getTargetInterfaces(); Class<?> targetClass = ((RemoteShell) obj).getTargetClass(); ProxyFactory pf = new ProxyFactory(targetInterfaces); pf.addAdvice(new LexEVSBeanProxy(as, this)); pf.setProxyTargetClass(true); pf.setTargetClass(targetClass); pf.setTarget(obj); return pf.getProxy(); } if (obj instanceof Integer || obj instanceof Float || obj instanceof Double || obj instanceof Character || obj instanceof Long || obj instanceof Boolean || obj instanceof String || obj instanceof Date || obj instanceof LexEVSBeanProxy || obj instanceof BeanProxy) return obj; if (!LexEVSCaCoreUtils.isLexBigClass(obj.getClass())) { return obj; } // Don't proxy client-safe LexBig objects if (isClientSafe(obj.getClass())) { return obj; } else { return LexEVSCaCoreUtils.createProxy(obj, as, this); } }
From source file:org.jdal.remoting.rmi.RmiNativeRemoteReference.java
/** * {@inheritDoc}/*w w w . j a va2s . c o m*/ */ @SuppressWarnings("unchecked") public RemoteClient createRemoteClient() { ProxyFactory pf = null; if (getServiceInterface().isAssignableFrom(remoteService.getClass())) { pf = new ProxyFactory(remoteService); } else { pf = new ProxyFactory(getServiceInterface(), new RmiServiceInterceptor((RmiInvocationHandler) remoteService)); } pf.addInterface(RemoteClient.class); pf.addAdvisor(new RemoteClientAdvisor(this)); return (RemoteClient) pf.getProxy(); }
From source file:fr.mby.utils.spring.beans.factory.annotation.ProxywiredAnnotationBeanPostProcessor.java
/** * Instrumentalize the bean factory to proxy what we need. * //from ww w .j ava 2 s. c om * @param beanFactory * @return */ protected ConfigurableListableBeanFactory instrumentBeanFactory( final ConfigurableListableBeanFactory beanFactory) { if (this.instrumentedBeanFactory == null) { final ProxyFactory proxyFactory = new ProxyFactory(ConfigurableListableBeanFactory.class, new ResolveDependencyMethodInterceptor()); proxyFactory.setTarget(beanFactory); this.instrumentedBeanFactory = (ConfigurableListableBeanFactory) proxyFactory.getProxy(); } return this.instrumentedBeanFactory; }
From source file:org.springframework.data.rest.core.projection.ProxyProjectionFactory.java
@Override @SuppressWarnings("unchecked") public <T> T createProjection(Object source, Class<T> projectionType) { Assert.isTrue(projectionType.isInterface(), "Projection type must be an interface!"); if (source == null) { return null; }//from w w w. j av a 2 s . c o m ProxyFactory factory = new ProxyFactory(); factory.setTarget(source); factory.setOpaque(true); factory.setInterfaces(projectionType, TargetClassAware.class); factory.addAdvice(new TargetClassAwareMethodInterceptor(source.getClass())); factory.addAdvice(getMethodInterceptor(source, projectionType)); return (T) factory.getProxy(); }
From source file:aop.DeclareMixinAspectJAdvisorFactoryTest.java
protected Object createProxy(Object target, List<Advisor> advisors, Class<?>... interfaces) { ProxyFactory pf = new ProxyFactory(target); if (interfaces.length > 1 || interfaces[0].isInterface()) { pf.setInterfaces(interfaces);// www . j a v a 2 s.c o m } else { pf.setProxyTargetClass(true); } // Required everywhere we use AspectJ proxies pf.addAdvice(ExposeInvocationInterceptor.INSTANCE); for (Object a : advisors) { pf.addAdvisor((Advisor) a); } pf.setExposeProxy(true); return pf.getProxy(); }
From source file:com.alibaba.cobar.client.router.config.AbstractCobarClientInternalRouterFactoryBean.java
@SuppressWarnings("unchecked") public void afterPropertiesSet() throws Exception { DefaultCobarClientInternalRouter routerToUse = new DefaultCobarClientInternalRouter(); List<InternalRule> rules = loadRulesFromExternal(); getRuleLoader().loadRulesAndEquipRouter(rules, routerToUse, getFunctionsMap()); if (isEnableCache()) { ProxyFactory proxyFactory = new ProxyFactory(routerToUse); proxyFactory.setInterfaces(new Class[] { ICobarRouter.class }); RoutingResultCacheAspect advice = new RoutingResultCacheAspect(); if (cacheSize > 0) { advice.setInternalCache(new LRUMap(cacheSize)); }//from ww w . j a v a 2 s . c o m proxyFactory.addAdvice(advice); this.router = (ICobarRouter<IBatisRoutingFact>) proxyFactory.getProxy(); } else { this.router = routerToUse; } }
From source file:org.codehaus.grepo.core.repository.GenericRepositoryFactoryBean.java
/** * {@inheritDoc}//w w w . j a va 2 s. co m */ public Object getObject() throws Exception { // validate factory configuration validate(); // create target T target = createTarget(); configureTarget(target); // create proxy ProxyFactory proxyFactory = new ProxyFactory(); proxyFactory.setTarget(target); proxyFactory.setInterfaces(new Class[] { proxyInterface }); proxyFactory.addAdvice(configuration.getMethodInterceptor()); return proxyFactory.getProxy(); }