Coverage Report - org.kuali.rice.ksb.messaging.serviceconnectors.AbstractServiceConnector
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractServiceConnector
0%
0/18
0%
0/2
1.333
 
 1  
 /*
 2  
  * Copyright 2007 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 org.apache.cxf.endpoint.Client;
 19  
 import org.apache.cxf.frontend.ClientProxy;
 20  
 import org.apache.cxf.transport.http.HTTPConduit;
 21  
 import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
 22  
 import org.kuali.rice.core.security.credentials.CredentialsSource;
 23  
 import org.kuali.rice.ksb.messaging.BusClientFailureProxy;
 24  
 import org.kuali.rice.ksb.messaging.ServiceInfo;
 25  
 import org.kuali.rice.ksb.messaging.bam.BAMClientProxy;
 26  
 import org.kuali.rice.ksb.service.KSBServiceLocator;
 27  
 import org.springframework.util.Assert;
 28  
 
 29  
 
 30  
 /**
 31  
  * Abstract implementation of the ServiceConnector that holds the ServiceInfo
 32  
  * and the CredentialsSource as well as providing convenience proxy methods.
 33  
  * 
 34  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 35  
  * @since 0.9
 36  
  * 
 37  
  */
 38  
 public abstract class AbstractServiceConnector implements ServiceConnector {
 39  
         
 40  
         private static final String HTTP_CLIENT_POLICY_BEAN = "httpClientPolicy";
 41  
 
 42  
         /**
 43  
          * Maintains the information about the service.  This should never be null.
 44  
          */
 45  
         private ServiceInfo serviceInfo;
 46  
 
 47  
         /**
 48  
          * Maintains the credentials needed by the service.  This may be null.
 49  
          */
 50  
         private CredentialsSource credentialsSource;
 51  
 
 52  0
         public AbstractServiceConnector(final ServiceInfo serviceInfo) {
 53  0
                 Assert.notNull(serviceInfo, "serviceInfo cannot be null");
 54  0
                 this.serviceInfo = serviceInfo;
 55  0
         }
 56  
 
 57  
         public ServiceInfo getServiceInfo() {
 58  0
                 return this.serviceInfo;
 59  
         }
 60  
 
 61  
         public void setServiceInfo(final ServiceInfo serviceInfo) {
 62  0
                 this.serviceInfo = serviceInfo;
 63  0
         }
 64  
 
 65  
         public void setCredentialsSource(final CredentialsSource credentialsSource) {
 66  0
                 this.credentialsSource = credentialsSource;
 67  0
         }
 68  
 
 69  
         protected CredentialsSource getCredentialsSource() {
 70  0
                 return this.credentialsSource;
 71  
         }
 72  
 
 73  
         protected Object getServiceProxyWithFailureMode(final Object service,
 74  
                         final ServiceInfo serviceInfo) {
 75  
                 // HACK: TODO: rip out or clean up
 76  
                 // set http client policy
 77  0
                 HTTPClientPolicy policy = 
 78  
                         (HTTPClientPolicy)KSBServiceLocator.getService(HTTP_CLIENT_POLICY_BEAN);
 79  0
                 if (policy != null) {
 80  
                         try {
 81  0
                                 Client cl = ClientProxy.getClient(service);
 82  0
                                 ((HTTPConduit)cl.getConduit()).setClient(policy);
 83  0
                         } catch (ClassCastException e) {
 84  
                                 // ignore for now
 85  0
                         }
 86  
                 }
 87  
                 
 88  0
                 Object bamWrappedClientProxy = BAMClientProxy
 89  
                                 .wrap(service, serviceInfo);
 90  0
                 return BusClientFailureProxy.wrap(bamWrappedClientProxy, serviceInfo);
 91  
         }
 92  
 }