View Javadoc

1   /*
2    * Copyright 2007 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 1.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/ecl1.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.apache.log4j.Logger;
23  import org.kuali.rice.ksb.messaging.ServiceInfo;
24  import org.kuali.rice.ksb.service.KSBServiceLocator;
25  
26  /**
27   * Abstract superclass for CXF http client based service connectors.
28   * 
29   * @author Kuali Rice Team (rice.collab@kuali.org)
30   *
31   */
32  public abstract class AbstractCxfClientServiceConnector extends AbstractServiceConnector {
33  	
34  	private static final Logger LOG = Logger.getLogger(AbstractCxfClientServiceConnector.class);
35  	private static final String HTTP_CLIENT_POLICY_BEAN = "httpClientPolicy";
36  	
37  	public AbstractCxfClientServiceConnector(ServiceInfo serviceInfo) {
38  		super(serviceInfo);
39  	}
40  	
41  	/**
42  	 * This method sets the client policy.  It assumes this is a CXF web client
43  	 * and uses the configured httpClientPolicy bean (if one exists).
44  	 * @param service
45  	 */
46  	@Override
47  	protected void applyClientPolicy(Object service) {
48  		// set http client policy
49  		HTTPClientPolicy policy = 
50  			(HTTPClientPolicy)KSBServiceLocator.getService(HTTP_CLIENT_POLICY_BEAN);
51  		if (policy != null) {
52  			try {
53  				Client cl = ClientProxy.getClient(service);
54  				((HTTPConduit)cl.getConduit()).setClient(policy);
55  			} catch (Exception e) {
56  				LOG.warn("unable to set HTTP client policy", e);
57  			}
58  		}
59  
60  		super.applyClientPolicy(service);
61  	}
62  	
63  }