View Javadoc

1   /**
2    * Copyright 2005-2011 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.apache.cxf.aegis.databinding.AegisDatabinding;
21  import org.apache.cxf.frontend.ClientProxyFactoryBean;
22  import org.apache.cxf.interceptor.LoggingInInterceptor;
23  import org.apache.cxf.interceptor.LoggingOutInterceptor;
24  import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
25  import org.kuali.rice.core.api.exception.RiceRuntimeException;
26  import org.kuali.rice.core.cxf.interceptors.ImmutableCollectionsInInterceptor;
27  import org.kuali.rice.ksb.api.bus.support.SoapServiceConfiguration;
28  import org.kuali.rice.ksb.security.soap.CXFWSS4JInInterceptor;
29  import org.kuali.rice.ksb.security.soap.CXFWSS4JOutInterceptor;
30  import org.kuali.rice.ksb.security.soap.CredentialsOutHandler;
31  import org.kuali.rice.ksb.service.KSBServiceLocator;
32  
33  
34  /**
35   *
36   * @author Kuali Rice Team (rice.collab@kuali.org)
37   * @since 0.9
38   */
39  public class SOAPConnector extends AbstractServiceConnector {
40  	
41  	public SOAPConnector(final SoapServiceConfiguration serviceConfiguration, final URL alternateEndpointUrl) {
42  		super(serviceConfiguration, alternateEndpointUrl);
43  	}
44  
45      @Override
46  	public SoapServiceConfiguration getServiceConfiguration() {
47  		return (SoapServiceConfiguration) super.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 (getServiceConfiguration().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(getServiceConfiguration().getServiceInterface()));
68  		} catch (ClassNotFoundException e) {
69  			throw new RiceRuntimeException("Failed to connect to soap service " + getServiceConfiguration().getServiceName() + " because failed to load interface class: " + getServiceConfiguration().getServiceInterface(), e);
70  		}
71  		clientFactory.setBus(KSBServiceLocator.getCXFBus());
72  		clientFactory.setServiceName(getServiceConfiguration().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(getServiceConfiguration().getBusSecurity()));
78  		if (getCredentialsSource() != null) {
79  			clientFactory.getOutInterceptors().add(new CredentialsOutHandler(getCredentialsSource(), getServiceConfiguration()));
80  		}
81  		
82  		clientFactory.getInInterceptors().add(new LoggingInInterceptor());
83  		clientFactory.getInInterceptors().add(new CXFWSS4JInInterceptor(getServiceConfiguration().getBusSecurity()));
84          clientFactory.getInInterceptors().add(new ImmutableCollectionsInInterceptor());
85  
86  		
87  		Object service = clientFactory.create();		
88  		return getServiceProxyWithFailureMode(service, getServiceConfiguration());
89  	}	
90  }