|  1 |     | 
     | 
  |  2 |     | 
     | 
  |  3 |     | 
     | 
  |  4 |     | 
     | 
  |  5 |     | 
     | 
  |  6 |     | 
     | 
  |  7 |     | 
     | 
  |  8 |     | 
     | 
  |  9 |     | 
     | 
  |  10 |     | 
     | 
  |  11 |     | 
     | 
  |  12 |     | 
     | 
  |  13 |     | 
     | 
  |  14 |     | 
     | 
  |  15 |     | 
     | 
  |  16 |     | 
     | 
  |  17 |     | 
   package org.kuali.rice.ksb.messaging.bam;  | 
  |  18 |     | 
     | 
  |  19 |     | 
   import java.lang.reflect.Method;  | 
  |  20 |     | 
   import java.lang.reflect.Proxy;  | 
  |  21 |     | 
     | 
  |  22 |     | 
   import org.kuali.rice.core.proxy.BaseTargetedInvocationHandler;  | 
  |  23 |     | 
   import org.kuali.rice.core.resourceloader.ContextClassLoaderProxy;  | 
  |  24 |     | 
   import org.kuali.rice.core.util.ClassLoaderUtils;  | 
  |  25 |     | 
   import org.kuali.rice.core.util.ExceptionUtils;  | 
  |  26 |     | 
   import org.kuali.rice.ksb.messaging.ServiceInfo;  | 
  |  27 |     | 
   import org.kuali.rice.ksb.messaging.bam.service.BAMService;  | 
  |  28 |     | 
   import org.kuali.rice.ksb.service.KSBServiceLocator;  | 
  |  29 |     | 
     | 
  |  30 |     | 
     | 
  |  31 |     | 
     | 
  |  32 |     | 
     | 
  |  33 |     | 
     | 
  |  34 |     | 
     | 
  |  35 |     | 
     | 
  |  36 |     | 
     | 
  |  37 |     | 
     | 
  |  38 |     | 
     | 
  |  39 |     | 
   public class BAMClientProxy extends BaseTargetedInvocationHandler { | 
  |  40 |     | 
     | 
  |  41 |     | 
           private ServiceInfo serviceInfo;  | 
  |  42 |     | 
             | 
  |  43 |     | 
           private BAMClientProxy(Object target, ServiceInfo serviceInfo) { | 
  |  44 |    0 |                    super(target);  | 
  |  45 |    0 |                    this.serviceInfo = serviceInfo;  | 
  |  46 |    0 |            }  | 
  |  47 |     | 
             | 
  |  48 |     | 
           public static Object wrap(Object target, ServiceInfo serviceInfo) { | 
  |  49 |    0 |                    return Proxy.newProxyInstance(ClassLoaderUtils.getDefaultClassLoader(), ContextClassLoaderProxy.getInterfacesToProxyIncludeSpring(target), new BAMClientProxy(target, serviceInfo));   | 
  |  50 |     | 
           }  | 
  |  51 |     | 
             | 
  |  52 |     | 
           protected Object invokeInternal(Object proxyObject, Method method, Object[] arguments) throws Throwable { | 
  |  53 |    0 |                    BAMTargetEntry bamTargetEntry = KSBServiceLocator.getBAMService().recordClientInvocation(this.serviceInfo, getTarget(), method, arguments);  | 
  |  54 |     | 
                   try { | 
  |  55 |    0 |                            return method.invoke(getTarget(), arguments);          | 
  |  56 |    0 |                    } catch (Throwable throwable) { | 
  |  57 |    0 |                            throwable = ExceptionUtils.unwrapActualCause(throwable);  | 
  |  58 |    0 |                            KSBServiceLocator.getBAMService().recordClientInvocationError(throwable, bamTargetEntry);  | 
  |  59 |    0 |                            throw throwable;  | 
  |  60 |     | 
                   }  | 
  |  61 |     | 
           }  | 
  |  62 |     | 
   }  |