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