1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.ksb.messaging.bam; |
17 | |
|
18 | |
import org.kuali.rice.core.api.config.property.Config; |
19 | |
import org.kuali.rice.core.api.config.property.ConfigContext; |
20 | |
import org.kuali.rice.core.api.util.ClassLoaderUtils; |
21 | |
import org.kuali.rice.core.api.util.reflect.BaseTargetedInvocationHandler; |
22 | |
import org.kuali.rice.core.impl.resourceloader.ContextClassLoaderProxy; |
23 | |
import org.kuali.rice.ksb.api.bus.ServiceConfiguration; |
24 | |
import org.kuali.rice.ksb.messaging.bam.service.BAMService; |
25 | |
import org.kuali.rice.ksb.service.KSBServiceLocator; |
26 | |
|
27 | |
import java.lang.reflect.InvocationTargetException; |
28 | |
import java.lang.reflect.Method; |
29 | |
import java.lang.reflect.Proxy; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
public class BAMClientProxy extends BaseTargetedInvocationHandler { |
41 | |
|
42 | |
private ServiceConfiguration serviceConfiguration; |
43 | |
|
44 | |
private BAMClientProxy(Object target, ServiceConfiguration serviceConfiguration) { |
45 | 0 | super(target); |
46 | 0 | this.serviceConfiguration = serviceConfiguration; |
47 | 0 | } |
48 | |
|
49 | |
public static boolean isBamSupported() { |
50 | 0 | return KSBServiceLocator.getBAMService() != null && Boolean.valueOf(ConfigContext.getCurrentContextConfig().getProperty(Config.BAM_ENABLED)); |
51 | |
} |
52 | |
|
53 | |
public static Object wrap(Object target, ServiceConfiguration serviceConfiguration) { |
54 | 0 | if (!isBamSupported()) { |
55 | 0 | return target; |
56 | |
} |
57 | 0 | return Proxy.newProxyInstance(ClassLoaderUtils.getDefaultClassLoader(), ContextClassLoaderProxy.getInterfacesToProxy(target), new BAMClientProxy(target, serviceConfiguration)); |
58 | |
} |
59 | |
|
60 | |
protected Object invokeInternal(Object proxyObject, Method method, Object[] arguments) throws Throwable { |
61 | 0 | BAMTargetEntry bamTargetEntry = KSBServiceLocator.getBAMService().recordClientInvocation(this.serviceConfiguration, getTarget(), method, arguments); |
62 | |
try { |
63 | 0 | return method.invoke(getTarget(), arguments); |
64 | 0 | } catch (Throwable throwable) { |
65 | 0 | if (throwable instanceof InvocationTargetException) { |
66 | 0 | throwable = throwable.getCause(); |
67 | |
} |
68 | 0 | KSBServiceLocator.getBAMService().recordClientInvocationError(throwable, bamTargetEntry); |
69 | 0 | throw throwable; |
70 | |
} |
71 | |
} |
72 | |
} |