View Javadoc

1   /*
2    * Copyright 2005-2007 The Kuali Foundation
3    *
4    *
5    * Licensed under the Educational Community License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    * http://www.opensource.org/licenses/ecl2.php
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.kuali.rice.ksb.messaging.serviceconnectors;
18  
19  import org.apache.cxf.aegis.databinding.AegisDatabinding;
20  import org.apache.cxf.frontend.ClientProxyFactoryBean;
21  import org.apache.cxf.interceptor.LoggingInInterceptor;
22  import org.apache.cxf.interceptor.LoggingOutInterceptor;
23  import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
24  import org.kuali.rice.ksb.messaging.SOAPServiceDefinition;
25  import org.kuali.rice.ksb.messaging.ServiceInfo;
26  import org.kuali.rice.ksb.security.soap.CXFWSS4JInInterceptor;
27  import org.kuali.rice.ksb.security.soap.CXFWSS4JOutInterceptor;
28  import org.kuali.rice.ksb.security.soap.CredentialsOutHandler;
29  import org.kuali.rice.ksb.service.KSBServiceLocator;
30  
31  
32  /**
33   *
34   * @author Kuali Rice Team (rice.collab@kuali.org)
35   * @since 0.9
36   */
37  public class SOAPConnector extends AbstractCxfClientServiceConnector {
38  
39  	public SOAPConnector(final ServiceInfo serviceInfo) {
40  		super(serviceInfo);
41  	}
42  
43  	
44  	/**
45  	 * This overridden method returns a CXF client proxy for web service.
46  	 * 
47  	 * @see org.kuali.rice.ksb.messaging.serviceconnectors.ServiceConnector#getService()
48  	 */
49  	public Object getService() throws Exception {
50  		ClientProxyFactoryBean clientFactory;
51  		
52  		//Use the correct bean factory depending on pojo service or jaxws service
53  		if (((SOAPServiceDefinition)getServiceInfo().getServiceDefinition()).isJaxWsService()){			
54  			clientFactory = new JaxWsProxyFactoryBean();
55  		} else {
56  			clientFactory = new ClientProxyFactoryBean();
57  			clientFactory.getServiceFactory().setDataBinding(new AegisDatabinding());
58  		}		
59  
60  		clientFactory.setBus(KSBServiceLocator.getCXFBus());
61  		clientFactory.setServiceClass(Class.forName(((SOAPServiceDefinition) getServiceInfo().getServiceDefinition()).getServiceInterface()));
62  		clientFactory.setServiceName(getServiceInfo().getQname());
63  		clientFactory.setAddress(getServiceInfo().getActualEndpointUrl());
64  		
65  		//Set logging and security interceptors
66  		clientFactory.getOutInterceptors().add(new LoggingOutInterceptor());
67  		clientFactory.getOutInterceptors().add(new CXFWSS4JOutInterceptor(getServiceInfo()));
68  		if (getCredentialsSource() != null) {
69  			clientFactory.getOutInterceptors().add(new CredentialsOutHandler(getCredentialsSource(), getServiceInfo()));
70  		}
71  		
72  		clientFactory.getInInterceptors().add(new LoggingInInterceptor());
73  		clientFactory.getInInterceptors().add(new CXFWSS4JInInterceptor(getServiceInfo()));
74  		
75  		Object service = clientFactory.create();		
76  		return getServiceProxyWithFailureMode(service, this.getServiceInfo());
77  	}	
78  
79  }