View Javadoc

1   /**
2    * Copyright 2005-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.ksb.messaging;
17  
18  import org.apache.log4j.Logger;
19  import org.kuali.rice.core.api.util.ClassLoaderUtils;
20  import org.kuali.rice.ksb.api.bus.support.JavaServiceConfiguration;
21  import org.springframework.aop.framework.ProxyFactory;
22  import org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean;
23  
24  import java.util.ArrayList;
25  import java.util.List;
26  
27  
28  public class KSBHttpInvokerProxyFactoryBean extends HttpInvokerProxyFactoryBean {
29  	private static final Logger LOG = Logger.getLogger(KSBHttpInvokerProxyFactoryBean.class);
30  
31  	private Object serviceProxy;
32  
33  	private JavaServiceConfiguration serviceConfiguration;
34  
35  	public JavaServiceConfiguration getServiceConfiguration() {
36  		return this.serviceConfiguration;
37  	}
38  
39  	public void setServiceConfiguration(JavaServiceConfiguration serviceConfiguration) {
40  		this.serviceConfiguration = serviceConfiguration;
41  	}
42  
43  	@Override
44  	public void afterPropertiesSet() {
45  		ProxyFactory proxyFactory = new ProxyFactory(getServiceInterfaces());
46  		proxyFactory.addAdvice(this);
47  		LOG.debug("Http proxying service " + getServiceConfiguration());
48  		this.serviceProxy = proxyFactory.getProxy();
49  	}
50  
51  	@Override
52  	public Object getObject() {
53  		return this.serviceProxy;
54  	}
55  
56  	@Override
57  	public Class<?> getObjectType() {
58  		return getObject().getClass();
59  	}
60  
61  	@Override
62  	public boolean isSingleton() {
63  		return false;
64  	}
65  
66  	public Class<?>[] getServiceInterfaces() {
67  		List<Class<?>> serviceInterfaces = new ArrayList<Class<?>>();
68  		try {
69  			for (String interfaceName : getServiceConfiguration().getServiceInterfaces()) {
70  				Class<?> clazz = Class.forName(interfaceName, true, ClassLoaderUtils.getDefaultClassLoader());
71  				LOG.debug("Adding service interface '" + clazz + "' to proxy object for service " + getServiceConfiguration());
72  				serviceInterfaces.add(clazz);
73  			}
74  		} catch (ClassNotFoundException e) {
75  			throw new RuntimeException(e);
76  		}
77  		return serviceInterfaces.toArray(new Class[0]);
78  	}
79  }