01: /*
02: * Copyright 2005-2006 The Kuali Foundation.
03: *
04: *
05: * Licensed under the Educational Community License, Version 1.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.opensource.org/licenses/ecl1.php
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package edu.iu.uis.eden.messaging.bam;
18:
19: import java.lang.reflect.Method;
20: import java.lang.reflect.Proxy;
21:
22: import org.kuali.bus.services.KSBServiceLocator;
23: import org.kuali.rice.proxy.BaseTargetedInvocationHandler;
24: import org.kuali.rice.resourceloader.ContextClassLoaderProxy;
25: import org.kuali.rice.util.ExceptionUtils;
26:
27: import edu.iu.uis.eden.messaging.ServiceInfo;
28:
29: /**
30: * A service-side proxy for that records an entry in the BAM for invocations
31: * on the proxied service endpoint.
32: *
33: * @see BAMService
34: *
35: * @author Kuali Rice Team (kuali-rice@googlegroups.com)
36: */
37:
38: public class BAMServerProxy extends BaseTargetedInvocationHandler {
39:
40: private ServiceInfo entry;
41:
42: private BAMServerProxy(Object target, ServiceInfo entry) {
43: super (target);
44: this .entry = entry;
45: }
46:
47: public static Object wrap(Object target, ServiceInfo entry) {
48: return Proxy.newProxyInstance(target.getClass()
49: .getClassLoader(), ContextClassLoaderProxy
50: .getInterfacesToProxyIncludeSpring(target),
51: new BAMServerProxy(target, entry));
52: }
53:
54: protected Object invokeInternal(Object proxiedObject,
55: Method method, Object[] arguments) throws Throwable {
56: BAMTargetEntry bamTargetEntry = KSBServiceLocator
57: .getBAMService().recordServerInvocation(getTarget(),
58: this .entry, method, arguments);
59: try {
60: return method.invoke(getTarget(), arguments);
61: } catch (Throwable throwable) {
62: throwable = ExceptionUtils.unwrapActualCause(throwable);
63: KSBServiceLocator.getBAMService()
64: .recordServerInvocationError(throwable,
65: bamTargetEntry);
66: throw throwable;
67: }
68: }
69: }
|