001 /**
002 * Copyright 2005-2013 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.ksb.messaging;
017
018 import org.apache.log4j.Logger;
019 import org.kuali.rice.core.api.util.ClassLoaderUtils;
020 import org.kuali.rice.ksb.api.bus.support.JavaServiceConfiguration;
021 import org.springframework.aop.framework.ProxyFactory;
022 import org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean;
023
024 import java.util.ArrayList;
025 import java.util.List;
026
027
028 public class KSBHttpInvokerProxyFactoryBean extends HttpInvokerProxyFactoryBean {
029 private static final Logger LOG = Logger.getLogger(KSBHttpInvokerProxyFactoryBean.class);
030
031 private Object serviceProxy;
032
033 private JavaServiceConfiguration serviceConfiguration;
034
035 public JavaServiceConfiguration getServiceConfiguration() {
036 return this.serviceConfiguration;
037 }
038
039 public void setServiceConfiguration(JavaServiceConfiguration serviceConfiguration) {
040 this.serviceConfiguration = serviceConfiguration;
041 }
042
043 @Override
044 public void afterPropertiesSet() {
045 ProxyFactory proxyFactory = new ProxyFactory(getServiceInterfaces());
046 proxyFactory.addAdvice(this);
047 LOG.debug("Http proxying service " + getServiceConfiguration());
048 this.serviceProxy = proxyFactory.getProxy();
049 }
050
051 @Override
052 public Object getObject() {
053 return this.serviceProxy;
054 }
055
056 @Override
057 public Class<?> getObjectType() {
058 return getObject().getClass();
059 }
060
061 @Override
062 public boolean isSingleton() {
063 return false;
064 }
065
066 public Class<?>[] getServiceInterfaces() {
067 List<Class<?>> serviceInterfaces = new ArrayList<Class<?>>();
068 try {
069 for (String interfaceName : getServiceConfiguration().getServiceInterfaces()) {
070 Class<?> clazz = Class.forName(interfaceName, true, ClassLoaderUtils.getDefaultClassLoader());
071 LOG.debug("Adding service interface '" + clazz + "' to proxy object for service " + getServiceConfiguration());
072 serviceInterfaces.add(clazz);
073 }
074 } catch (ClassNotFoundException e) {
075 throw new RuntimeException(e);
076 }
077 return serviceInterfaces.toArray(new Class[0]);
078 }
079 }