1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.ksb.messaging;
17
18 import org.kuali.rice.core.api.util.ClassLoaderUtils;
19 import org.kuali.rice.core.impl.resourceloader.ContextClassLoaderProxy;
20 import org.kuali.rice.ksb.api.bus.ServiceDefinition;
21 import org.kuali.rice.ksb.messaging.bam.BAMServerProxy;
22 import org.springframework.aop.framework.ProxyFactory;
23 import org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter;
24 import org.springframework.remoting.support.RemoteInvocationTraceInterceptor;
25
26 import java.util.Arrays;
27 import java.util.List;
28
29
30 public class KSBHttpInvokerServiceExporter extends HttpInvokerServiceExporter {
31
32 private List<Class<?>> serviceInterfaces;
33 private ServiceDefinition serviceDefinition;
34 private boolean registerTraceInterceptor = true;
35
36 public ServiceDefinition getServiceDefinition() {
37 return this.serviceDefinition;
38 }
39
40 public void setServiceDefinition(ServiceDefinition serviceDefinition) {
41 this.serviceDefinition = serviceDefinition;
42 }
43
44
45
46
47 @Override
48 public void setRegisterTraceInterceptor(boolean registerTraceInterceptor) {
49
50 this.registerTraceInterceptor = registerTraceInterceptor;
51 super.setRegisterTraceInterceptor(registerTraceInterceptor);
52 }
53
54 protected Object getProxyForService() {
55 checkService();
56 checkServiceInterface();
57 ProxyFactory proxyFactory = new ProxyFactory();
58 for (Class<?> serviceInterface : getServiceInterfaces()) {
59 proxyFactory.addInterface(serviceInterface);
60 }
61 if (registerTraceInterceptor == true) {
62 proxyFactory.addAdvice(new RemoteInvocationTraceInterceptor(getExporterName()));
63 }
64 ClassLoader classLoader = serviceDefinition.getServiceClassLoader();
65 if (classLoader == null) {
66 classLoader = ClassLoaderUtils.getDefaultClassLoader();
67 }
68 Object service = ContextClassLoaderProxy.wrap(getService(), classLoader);
69 service = BAMServerProxy.wrap(service, getServiceDefinition());
70 proxyFactory.setTarget(service);
71 return proxyFactory.getProxy(classLoader);
72 }
73
74 @Override
75 protected void checkServiceInterface() throws IllegalArgumentException {
76 if (this.serviceInterfaces == null) {
77 this.serviceInterfaces = Arrays.asList(ContextClassLoaderProxy.getInterfacesToProxy(getService()));
78 }
79 if (getServiceInterfaces().isEmpty()) {
80 throw new IllegalArgumentException("At least one service interface should be defined.");
81 }
82 }
83
84 public List<Class<?>> getServiceInterfaces() {
85 return this.serviceInterfaces;
86 }
87
88 public void setServiceInterfaces(List<Class<?>> serviceInterfaces) {
89 this.serviceInterfaces = serviceInterfaces;
90 }
91
92 public Object getService() {
93 return super.getService();
94 }
95
96 }