View Javadoc
1   /**
2    * Copyright 2005-2016 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.serviceconnectors;
17  
18  import java.net.URL;
19  
20  import org.kuali.rice.core.api.security.credentials.CredentialsSource;
21  import org.kuali.rice.ksb.api.bus.ServiceConfiguration;
22  import org.kuali.rice.ksb.messaging.BusClientFailureProxy;
23  import org.kuali.rice.ksb.messaging.bam.BAMClientProxy;
24  import org.springframework.util.Assert;
25  
26  
27  /**
28   * Abstract implementation of the ServiceConnector that holds the ServiceInfo
29   * and the CredentialsSource as well as providing convenience proxy methods.
30   * 
31   * @author Kuali Rice Team (rice.collab@kuali.org)
32   * @since 0.9
33   * 
34   */
35  public abstract class AbstractServiceConnector implements ServiceConnector {
36  
37  	/**
38  	 * Maintains the information about the service.  This should never be null.
39  	 */
40  	private ServiceConfiguration serviceConfiguration;
41  	private URL alternateEndpointUrl;
42  
43  	/**
44  	 * Maintains the credentials needed by the service.  This may be null.
45  	 */
46  	private CredentialsSource credentialsSource;
47  
48  	public AbstractServiceConnector(final ServiceConfiguration serviceConfiguration) {
49  		this(serviceConfiguration, null);
50  	}
51  	
52  	public AbstractServiceConnector(final ServiceConfiguration serviceConfiguration, URL alternateEndpointUrl) {
53  		Assert.notNull(serviceConfiguration, "serviceConfiguration cannot be null");
54  		this.serviceConfiguration = serviceConfiguration;
55  		this.alternateEndpointUrl = alternateEndpointUrl;
56  	}
57  	
58  	public URL getActualEndpointUrl() {
59  		if (alternateEndpointUrl != null) {
60              return alternateEndpointUrl;
61          }
62          return getServiceConfiguration().getEndpointUrl();
63  	}
64  
65  	public ServiceConfiguration getServiceConfiguration() {
66  		return this.serviceConfiguration;
67  	}
68  
69  	public void setCredentialsSource(final CredentialsSource credentialsSource) {
70  		this.credentialsSource = credentialsSource;
71  	}
72  
73  	protected CredentialsSource getCredentialsSource() {
74  		return this.credentialsSource;
75  	}
76  
77  	protected Object getServiceProxyWithFailureMode(final Object service,
78  			final ServiceConfiguration serviceConfiguration) {
79  		Object bamWrappedClientProxy = BAMClientProxy.wrap(service, serviceConfiguration);
80          if (!serviceConfiguration.isQueue()) {
81              return bamWrappedClientProxy;
82          }
83  		return BusClientFailureProxy.wrap(bamWrappedClientProxy, serviceConfiguration);
84  	}
85  }