| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
package org.kuali.rice.ksb.messaging.config; |
| 18 | |
|
| 19 | |
import org.apache.commons.httpclient.contrib.ssl.EasySSLProtocolSocketFactory; |
| 20 | |
import org.apache.commons.httpclient.protocol.Protocol; |
| 21 | |
import org.apache.commons.httpclient.protocol.ProtocolSocketFactory; |
| 22 | |
import org.kuali.rice.core.api.config.ConfigurationException; |
| 23 | |
import org.kuali.rice.core.api.config.property.Config; |
| 24 | |
import org.kuali.rice.core.api.config.property.ConfigContext; |
| 25 | |
import org.kuali.rice.core.api.lifecycle.Lifecycle; |
| 26 | |
import org.kuali.rice.core.api.resourceloader.ResourceLoader; |
| 27 | |
import org.kuali.rice.core.framework.persistence.jpa.OrmUtils; |
| 28 | |
import org.kuali.rice.core.impl.config.module.ModuleConfigurer; |
| 29 | |
import org.kuali.rice.core.api.lifecycle.BaseLifecycle; |
| 30 | |
import org.kuali.rice.core.impl.lifecycle.ServiceDelegatingLifecycle; |
| 31 | |
import org.kuali.rice.core.api.resourceloader.ResourceLoader; |
| 32 | |
import org.kuali.rice.core.util.ClassLoaderUtils; |
| 33 | |
import org.kuali.rice.core.util.RiceConstants; |
| 34 | |
import org.kuali.rice.ksb.messaging.AlternateEndpoint; |
| 35 | |
import org.kuali.rice.ksb.messaging.AlternateEndpointLocation; |
| 36 | |
import org.kuali.rice.ksb.messaging.MessageFetcher; |
| 37 | |
import org.kuali.rice.ksb.messaging.ServiceDefinition; |
| 38 | |
import org.kuali.rice.ksb.messaging.resourceloader.KSBResourceLoaderFactory; |
| 39 | |
import org.kuali.rice.ksb.messaging.serviceconnectors.HttpInvokerConnector; |
| 40 | |
import org.kuali.rice.ksb.service.KSBServiceLocator; |
| 41 | |
import org.kuali.rice.ksb.util.KSBConstants; |
| 42 | |
import org.quartz.Scheduler; |
| 43 | |
import org.springframework.transaction.PlatformTransactionManager; |
| 44 | |
|
| 45 | |
import javax.sql.DataSource; |
| 46 | |
import java.util.ArrayList; |
| 47 | |
import java.util.Collection; |
| 48 | |
import java.util.Collections; |
| 49 | |
import java.util.LinkedList; |
| 50 | |
import java.util.List; |
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | 0 | public class KSBConfigurer extends ModuleConfigurer { |
| 62 | |
|
| 63 | 0 | private List<ServiceDefinition> services = new ArrayList<ServiceDefinition>(); |
| 64 | |
|
| 65 | 0 | private List<AlternateEndpointLocation> alternateEndpointLocations = new ArrayList<AlternateEndpointLocation>(); |
| 66 | |
|
| 67 | 0 | private List<AlternateEndpoint> alternateEndpoints = new ArrayList<AlternateEndpoint>(); |
| 68 | |
|
| 69 | |
private DataSource registryDataSource; |
| 70 | |
|
| 71 | |
private DataSource messageDataSource; |
| 72 | |
|
| 73 | |
private DataSource nonTransactionalMessageDataSource; |
| 74 | |
|
| 75 | |
private Scheduler exceptionMessagingScheduler; |
| 76 | |
|
| 77 | |
private PlatformTransactionManager platformTransactionManager; |
| 78 | |
|
| 79 | |
@Override |
| 80 | |
public void addAdditonalToConfig() { |
| 81 | 0 | configureDataSource(); |
| 82 | 0 | configureBus(); |
| 83 | 0 | configureScheduler(); |
| 84 | 0 | configurePlatformTransactionManager(); |
| 85 | 0 | configureAlternateEndpoints(); |
| 86 | 0 | } |
| 87 | |
|
| 88 | |
@Override |
| 89 | |
public List<String> getPrimarySpringFiles(){ |
| 90 | 0 | final List<String> springFileLocations = new ArrayList<String>(); |
| 91 | |
|
| 92 | |
|
| 93 | 0 | springFileLocations.add("classpath:org/kuali/rice/kns/config/KNSSpringBeans.xml"); |
| 94 | |
|
| 95 | 0 | springFileLocations.add("classpath:org/kuali/rice/ksb/config/KSBSpringBeans.xml"); |
| 96 | |
|
| 97 | 0 | if (OrmUtils.isJpaEnabled("rice.ksb")) { |
| 98 | 0 | springFileLocations.add("classpath:org/kuali/rice/ksb/config/KSBJPASpringBeans.xml"); |
| 99 | |
} |
| 100 | |
else { |
| 101 | 0 | springFileLocations.add("classpath:org/kuali/rice/ksb/config/KSBOJBSpringBeans.xml"); |
| 102 | |
} |
| 103 | |
|
| 104 | 0 | if (Boolean.valueOf(ConfigContext.getCurrentContextConfig().getProperty(KSBConstants.Config.LOAD_KNS_MODULE_CONFIGURATION)).booleanValue()) { |
| 105 | 0 | springFileLocations.add("classpath:org/kuali/rice/ksb/config/KSBModuleConfigurationSpringBeans.xml"); |
| 106 | |
} |
| 107 | |
|
| 108 | 0 | return springFileLocations; |
| 109 | |
} |
| 110 | |
|
| 111 | |
|
| 112 | |
|
| 113 | |
|
| 114 | |
|
| 115 | |
|
| 116 | |
@Override |
| 117 | |
public boolean shouldRenderWebInterface() { |
| 118 | 0 | return true; |
| 119 | |
} |
| 120 | |
|
| 121 | |
@Override |
| 122 | |
public Collection<ResourceLoader> getResourceLoadersToRegister() throws Exception{ |
| 123 | 0 | ResourceLoader ksbRemoteResourceLoader = KSBResourceLoaderFactory.createRootKSBRemoteResourceLoader(); |
| 124 | 0 | ksbRemoteResourceLoader.start(); |
| 125 | 0 | return Collections.singletonList(ksbRemoteResourceLoader); |
| 126 | |
} |
| 127 | |
|
| 128 | |
@Override |
| 129 | |
public List<Lifecycle> loadLifecycles() throws Exception { |
| 130 | 0 | List<Lifecycle> lifecycles = new LinkedList<Lifecycle>(); |
| 131 | |
|
| 132 | |
|
| 133 | |
|
| 134 | 0 | lifecycles.add(new BaseLifecycle() { |
| 135 | |
|
| 136 | |
@Override |
| 137 | |
public void start() throws Exception { |
| 138 | |
|
| 139 | 0 | if (Boolean.valueOf(ConfigContext.getCurrentContextConfig().getProperty(KSBConstants.Config.KSB_ALLOW_SELF_SIGNED_SSL)).booleanValue()) { |
| 140 | 0 | Protocol.registerProtocol("https", new Protocol("https", |
| 141 | |
(ProtocolSocketFactory) new EasySSLProtocolSocketFactory(), 443)); |
| 142 | |
} |
| 143 | 0 | super.start(); |
| 144 | 0 | } |
| 145 | |
}); |
| 146 | 0 | lifecycles.add(new ServiceDelegatingLifecycle(KSBConstants.ServiceNames.THREAD_POOL_SERVICE)); |
| 147 | 0 | lifecycles.add(new ServiceDelegatingLifecycle(KSBConstants.ServiceNames.SCHEDULED_THREAD_POOL_SERVICE)); |
| 148 | 0 | lifecycles.add(new ServiceDelegatingLifecycle(KSBConstants.ServiceNames.REPEAT_TOPIC_INVOKING_QUEUE)); |
| 149 | 0 | lifecycles.add(new ServiceDelegatingLifecycle(KSBConstants.ServiceNames.OBJECT_REMOTER)); |
| 150 | 0 | lifecycles.add(new ServiceDelegatingLifecycle(KSBConstants.ServiceNames.BUS_ADMIN_SERVICE)); |
| 151 | 0 | lifecycles.add(new ServiceDelegatingLifecycle(KSBConstants.ServiceNames.REMOTED_SERVICE_REGISTRY)); |
| 152 | 0 | return lifecycles; |
| 153 | |
} |
| 154 | |
|
| 155 | |
@Override |
| 156 | |
public void doAdditonalConfigurerValidations() { |
| 157 | 0 | for (final ServiceDefinition serviceDef : KSBConfigurer.this.services) { |
| 158 | 0 | serviceDef.validate(); |
| 159 | |
} |
| 160 | 0 | } |
| 161 | |
|
| 162 | |
@Override |
| 163 | |
public void doAdditionalContextStartedLogic() { |
| 164 | 0 | requeueMessages(); |
| 165 | 0 | } |
| 166 | |
|
| 167 | |
|
| 168 | |
|
| 169 | |
|
| 170 | |
|
| 171 | |
private void requeueMessages() { |
| 172 | 0 | LOG.info("Refreshing Service Registry to export services to the bus."); |
| 173 | 0 | KSBServiceLocator.getServiceDeployer().refresh(); |
| 174 | |
|
| 175 | |
|
| 176 | 0 | MessageFetcher messageFetcher = new MessageFetcher((Integer) null); |
| 177 | 0 | KSBServiceLocator.getThreadPool().execute(messageFetcher); |
| 178 | 0 | } |
| 179 | |
|
| 180 | |
protected void configureBus() { |
| 181 | 0 | LOG.debug("Configuring services for Service Namespace " + ConfigContext.getCurrentContextConfig().getServiceNamespace() + " using config for classloader " + ClassLoaderUtils.getDefaultClassLoader()); |
| 182 | 0 | configureServiceList(Config.BUS_DEPLOYED_SERVICES, getServices()); |
| 183 | 0 | } |
| 184 | |
|
| 185 | |
protected void configureServiceList(String key, List<ServiceDefinition> theServices) { |
| 186 | 0 | LOG.debug("Configuring services for Service Namespace " + ConfigContext.getCurrentContextConfig().getServiceNamespace() + " using config for classloader " + ClassLoaderUtils.getDefaultClassLoader()); |
| 187 | |
@SuppressWarnings("unchecked") |
| 188 | 0 | List<ServiceDefinition> serviceDefinitions = (List<ServiceDefinition>) ConfigContext.getCurrentContextConfig().getObject(key); |
| 189 | 0 | if (serviceDefinitions == null) { |
| 190 | 0 | ConfigContext.getCurrentContextConfig().putObject(key, theServices); |
| 191 | 0 | } else if (theServices != null) { |
| 192 | 0 | LOG.debug("Services already exist. Adding additional services"); |
| 193 | 0 | serviceDefinitions.addAll(theServices); |
| 194 | |
} |
| 195 | 0 | } |
| 196 | |
|
| 197 | |
protected void configureScheduler() { |
| 198 | 0 | if (this.getExceptionMessagingScheduler() != null) { |
| 199 | 0 | LOG.info("Configuring injected exception messaging Scheduler"); |
| 200 | 0 | ConfigContext.getCurrentContextConfig().putObject(KSBConstants.Config.INJECTED_EXCEPTION_MESSAGE_SCHEDULER_KEY, this.getExceptionMessagingScheduler()); |
| 201 | |
} |
| 202 | 0 | } |
| 203 | |
|
| 204 | |
protected void configureDataSource() { |
| 205 | 0 | if (getMessageDataSource() != null && getRegistryDataSource() == null) { |
| 206 | 0 | throw new ConfigurationException("A message data source was defined but a registry data source was not defined. Both must be specified."); |
| 207 | |
} |
| 208 | 0 | if (getMessageDataSource() == null && getRegistryDataSource() != null) { |
| 209 | 0 | throw new ConfigurationException("A registry data source was defined but a message data source was not defined. Both must be specified."); |
| 210 | |
} |
| 211 | |
|
| 212 | 0 | if (getMessageDataSource() != null) { |
| 213 | 0 | ConfigContext.getCurrentContextConfig().putObject(KSBConstants.Config.KSB_MESSAGE_DATASOURCE, getMessageDataSource()); |
| 214 | |
} |
| 215 | 0 | if (getNonTransactionalMessageDataSource() != null) { |
| 216 | 0 | ConfigContext.getCurrentContextConfig().putObject(KSBConstants.Config.KSB_MESSAGE_NON_TRANSACTIONAL_DATASOURCE, getNonTransactionalMessageDataSource()); |
| 217 | |
} |
| 218 | 0 | if (getRegistryDataSource() != null) { |
| 219 | 0 | ConfigContext.getCurrentContextConfig().putObject(KSBConstants.Config.KSB_REGISTRY_DATASOURCE, getRegistryDataSource()); |
| 220 | |
} |
| 221 | 0 | } |
| 222 | |
|
| 223 | |
protected void configurePlatformTransactionManager() { |
| 224 | 0 | if (getPlatformTransactionManager() == null) { |
| 225 | 0 | return; |
| 226 | |
} |
| 227 | 0 | ConfigContext.getCurrentContextConfig().putObject(RiceConstants.SPRING_TRANSACTION_MANAGER, getPlatformTransactionManager()); |
| 228 | 0 | } |
| 229 | |
|
| 230 | |
protected void configureAlternateEndpoints() { |
| 231 | 0 | ConfigContext.getCurrentContextConfig().putObject(KSBConstants.Config.KSB_ALTERNATE_ENDPOINT_LOCATIONS, getAlternateEndpointLocations()); |
| 232 | 0 | ConfigContext.getCurrentContextConfig().putObject(KSBConstants.Config.KSB_ALTERNATE_ENDPOINTS, getAlternateEndpoints()); |
| 233 | 0 | } |
| 234 | |
|
| 235 | |
@Override |
| 236 | |
public void doAdditionalContextStoppedLogic() { |
| 237 | |
try { |
| 238 | 0 | HttpInvokerConnector.shutdownIdleConnectionTimeout(); |
| 239 | 0 | } catch (Exception e) { |
| 240 | 0 | LOG.error("Failed to shutdown idle connection timeout evictor thread.", e); |
| 241 | 0 | } |
| 242 | 0 | cleanUpConfiguration(); |
| 243 | 0 | } |
| 244 | |
|
| 245 | |
|
| 246 | |
|
| 247 | |
|
| 248 | |
|
| 249 | |
|
| 250 | |
|
| 251 | |
|
| 252 | |
protected void cleanUpConfiguration() { |
| 253 | 0 | ConfigContext.getCurrentContextConfig().removeObject(Config.BUS_DEPLOYED_SERVICES); |
| 254 | 0 | ConfigContext.getCurrentContextConfig().removeObject(KSBConstants.Config.KSB_ALTERNATE_ENDPOINTS); |
| 255 | 0 | } |
| 256 | |
|
| 257 | |
public List<ServiceDefinition> getServices() { |
| 258 | 0 | return this.services; |
| 259 | |
} |
| 260 | |
|
| 261 | |
public void setServices(List<ServiceDefinition> javaServices) { |
| 262 | 0 | this.services = javaServices; |
| 263 | 0 | } |
| 264 | |
|
| 265 | |
public DataSource getMessageDataSource() { |
| 266 | 0 | return this.messageDataSource; |
| 267 | |
} |
| 268 | |
|
| 269 | |
public void setMessageDataSource(DataSource messageDataSource) { |
| 270 | 0 | this.messageDataSource = messageDataSource; |
| 271 | 0 | } |
| 272 | |
|
| 273 | |
public DataSource getNonTransactionalMessageDataSource() { |
| 274 | 0 | return this.nonTransactionalMessageDataSource; |
| 275 | |
} |
| 276 | |
|
| 277 | |
public void setNonTransactionalMessageDataSource(DataSource nonTransactionalMessageDataSource) { |
| 278 | 0 | this.nonTransactionalMessageDataSource = nonTransactionalMessageDataSource; |
| 279 | 0 | } |
| 280 | |
|
| 281 | |
public DataSource getRegistryDataSource() { |
| 282 | 0 | return this.registryDataSource; |
| 283 | |
} |
| 284 | |
|
| 285 | |
public void setRegistryDataSource(DataSource registryDataSource) { |
| 286 | 0 | this.registryDataSource = registryDataSource; |
| 287 | 0 | } |
| 288 | |
|
| 289 | |
public Scheduler getExceptionMessagingScheduler() { |
| 290 | 0 | return this.exceptionMessagingScheduler; |
| 291 | |
} |
| 292 | |
|
| 293 | |
public void setExceptionMessagingScheduler(Scheduler exceptionMessagingScheduler) { |
| 294 | 0 | this.exceptionMessagingScheduler = exceptionMessagingScheduler; |
| 295 | 0 | } |
| 296 | |
|
| 297 | |
public PlatformTransactionManager getPlatformTransactionManager() { |
| 298 | 0 | return platformTransactionManager; |
| 299 | |
} |
| 300 | |
|
| 301 | |
public void setPlatformTransactionManager(PlatformTransactionManager springTransactionManager) { |
| 302 | 0 | this.platformTransactionManager = springTransactionManager; |
| 303 | 0 | } |
| 304 | |
|
| 305 | |
public List<AlternateEndpointLocation> getAlternateEndpointLocations() { |
| 306 | 0 | return this.alternateEndpointLocations; |
| 307 | |
} |
| 308 | |
|
| 309 | |
public void setAlternateEndpointLocations(List<AlternateEndpointLocation> alternateEndpointLocations) { |
| 310 | 0 | this.alternateEndpointLocations = alternateEndpointLocations; |
| 311 | 0 | } |
| 312 | |
|
| 313 | |
public List<AlternateEndpoint> getAlternateEndpoints() { |
| 314 | 0 | return this.alternateEndpoints; |
| 315 | |
} |
| 316 | |
|
| 317 | |
public void setAlternateEndpoints(List<AlternateEndpoint> alternateEndpoints) { |
| 318 | 0 | this.alternateEndpoints = alternateEndpoints; |
| 319 | 0 | } |
| 320 | |
|
| 321 | |
} |