001    /**
002     * Copyright 2005-2012 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.rice.ksb.messaging.serviceconnectors;
017    
018    import org.apache.cxf.aegis.databinding.AegisDatabinding;
019    import org.apache.cxf.frontend.ClientProxyFactoryBean;
020    import org.apache.cxf.interceptor.LoggingInInterceptor;
021    import org.apache.cxf.interceptor.LoggingOutInterceptor;
022    import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
023    import org.kuali.rice.core.api.exception.RiceRuntimeException;
024    import org.kuali.rice.ksb.api.bus.support.SoapServiceConfiguration;
025    import org.kuali.rice.ksb.impl.cxf.interceptors.ImmutableCollectionsInInterceptor;
026    import org.kuali.rice.ksb.security.soap.CXFWSS4JInInterceptor;
027    import org.kuali.rice.ksb.security.soap.CXFWSS4JOutInterceptor;
028    import org.kuali.rice.ksb.security.soap.CredentialsOutHandler;
029    import org.kuali.rice.ksb.service.KSBServiceLocator;
030    
031    import java.net.URL;
032    
033    
034    /**
035     *
036     * @author Kuali Rice Team (rice.collab@kuali.org)
037     * @since 0.9
038     */
039    public class SOAPConnector extends AbstractServiceConnector {
040            
041            public SOAPConnector(final SoapServiceConfiguration serviceConfiguration, final URL alternateEndpointUrl) {
042                    super(serviceConfiguration, alternateEndpointUrl);
043            }
044    
045        @Override
046            public SoapServiceConfiguration getServiceConfiguration() {
047                    return (SoapServiceConfiguration) super.getServiceConfiguration();
048            }
049            
050            /**
051             * This overridden method returns a CXF client praoxy for web service.
052             * 
053             * @see org.kuali.rice.ksb.messaging.serviceconnectors.ServiceConnector#getService()
054             */
055            public Object getService() {
056                    ClientProxyFactoryBean clientFactory;
057                    
058                    //Use the correct bean factory depending on pojo service or jaxws service
059                    if (getServiceConfiguration().isJaxWsService()){
060                            clientFactory = new JaxWsProxyFactoryBean();
061                    } else {
062                            clientFactory = new ClientProxyFactoryBean();
063                            clientFactory.getServiceFactory().setDataBinding(new AegisDatabinding());
064                    }               
065    
066                    try {
067                            clientFactory.setServiceClass(Class.forName(getServiceConfiguration().getServiceInterface()));
068                    } catch (ClassNotFoundException e) {
069                            throw new RiceRuntimeException("Failed to connect to soap service " + getServiceConfiguration().getServiceName() + " because failed to load interface class: " + getServiceConfiguration().getServiceInterface(), e);
070                    }
071                    clientFactory.setBus(KSBServiceLocator.getCXFBus());
072                    clientFactory.setServiceName(getServiceConfiguration().getServiceName());
073                    clientFactory.setAddress(getActualEndpointUrl().toExternalForm());
074                    
075                    //Set logging, transformation, and security interceptors
076                    clientFactory.getOutInterceptors().add(new LoggingOutInterceptor());
077                    clientFactory.getOutInterceptors().add(new CXFWSS4JOutInterceptor(getServiceConfiguration().getBusSecurity()));
078                    if (getCredentialsSource() != null) {
079                            clientFactory.getOutInterceptors().add(new CredentialsOutHandler(getCredentialsSource(), getServiceConfiguration()));
080                    }
081                    
082                    clientFactory.getInInterceptors().add(new LoggingInInterceptor());
083                    clientFactory.getInInterceptors().add(new CXFWSS4JInInterceptor(getServiceConfiguration().getBusSecurity()));
084            clientFactory.getInInterceptors().add(new ImmutableCollectionsInInterceptor());
085    
086                    
087                    Object service = clientFactory.create();                
088                    return getServiceProxyWithFailureMode(service, getServiceConfiguration());
089            }       
090    }