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 java.net.URL;
20  
21  import org.apache.cxf.aegis.databinding.AegisDatabinding;
22  import org.apache.cxf.frontend.ClientProxyFactoryBean;
23  import org.apache.cxf.interceptor.LoggingInInterceptor;
24  import org.apache.cxf.interceptor.LoggingOutInterceptor;
25  import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
26  import org.kuali.rice.core.api.exception.RiceRuntimeException;
27  import org.kuali.rice.core.cxf.interceptors.ImmutableCollectionsInInterceptor;
28  import org.kuali.rice.ksb.api.bus.support.SoapServiceConfiguration;
29  import org.kuali.rice.ksb.security.soap.CXFWSS4JInInterceptor;
30  import org.kuali.rice.ksb.security.soap.CXFWSS4JOutInterceptor;
31  import org.kuali.rice.ksb.security.soap.CredentialsOutHandler;
32  import org.kuali.rice.ksb.service.KSBServiceLocator;
33  
34  
35  /**
36   *
37   * @author Kuali Rice Team (rice.collab@kuali.org)
38   * @since 0.9
39   */
40  public class SOAPConnector extends AbstractServiceConnector {
41  	
42  	public SOAPConnector(final SoapServiceConfiguration serviceConfiguration, final URL alternateEndpointUrl) {
43  		super(serviceConfiguration, alternateEndpointUrl);
44  	}
45  
46  	protected SoapServiceConfiguration getSoapServiceConfiguration() {
47  		return (SoapServiceConfiguration)getServiceConfiguration();
48  	}
49  	
50  	/**
51  	 * This overridden method returns a CXF client praoxy for web service.
52  	 * 
53  	 * @see org.kuali.rice.ksb.messaging.serviceconnectors.ServiceConnector#getService()
54  	 */
55  	public Object getService() {
56  		ClientProxyFactoryBean clientFactory;
57  		
58  		//Use the correct bean factory depending on pojo service or jaxws service
59  		if (getSoapServiceConfiguration().isJaxWsService()){			
60  			clientFactory = new JaxWsProxyFactoryBean();
61  		} else {
62  			clientFactory = new ClientProxyFactoryBean();
63  			clientFactory.getServiceFactory().setDataBinding(new AegisDatabinding());
64  		}		
65  
66  		try {
67  			clientFactory.setServiceClass(Class.forName(getSoapServiceConfiguration().getServiceInterface()));
68  		} catch (ClassNotFoundException e) {
69  			throw new RiceRuntimeException("Failed to connect to soap service " + getServiceConfiguration().getServiceName() + " because failed to load interface class: " + getSoapServiceConfiguration().getServiceInterface(), e);
70  		}
71  		clientFactory.setBus(KSBServiceLocator.getCXFBus());
72  		clientFactory.setServiceName(getSoapServiceConfiguration().getServiceName());
73  		clientFactory.setAddress(getActualEndpointUrl().toExternalForm());
74  		
75  		//Set logging, transformation, and security interceptors
76  		clientFactory.getOutInterceptors().add(new LoggingOutInterceptor());
77  		clientFactory.getOutInterceptors().add(new CXFWSS4JOutInterceptor(getSoapServiceConfiguration().getBusSecurity()));
78  		if (getCredentialsSource() != null) {
79  			clientFactory.getOutInterceptors().add(new CredentialsOutHandler(getCredentialsSource(), getSoapServiceConfiguration()));
80  		}
81  		
82  		clientFactory.getInInterceptors().add(new LoggingInInterceptor());
83  		clientFactory.getInInterceptors().add(new CXFWSS4JInInterceptor(getSoapServiceConfiguration().getBusSecurity()));
84          clientFactory.getInInterceptors().add(new ImmutableCollectionsInInterceptor());
85  
86  		
87  		Object service = clientFactory.create();		
88  		return getServiceProxyWithFailureMode(service, getSoapServiceConfiguration());
89  	}	
90  }