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