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.apache.log4j.Logger;
024    import org.kuali.rice.core.api.exception.RiceRuntimeException;
025    import org.kuali.rice.ksb.api.bus.support.SoapServiceConfiguration;
026    import org.kuali.rice.ksb.impl.cxf.interceptors.ImmutableCollectionsInInterceptor;
027    import org.kuali.rice.ksb.security.soap.CXFWSS4JInInterceptor;
028    import org.kuali.rice.ksb.security.soap.CXFWSS4JOutInterceptor;
029    import org.kuali.rice.ksb.security.soap.CredentialsOutHandler;
030    import org.kuali.rice.ksb.service.KSBServiceLocator;
031    
032    import java.net.URL;
033    
034    
035    /**
036     *
037     * @author Kuali Rice Team (rice.collab@kuali.org)
038     * @since 0.9
039     */
040    public class SOAPConnector extends AbstractServiceConnector {
041    
042        private static final Logger LOG = Logger.getLogger(SOAPConnector.class);
043    
044            public SOAPConnector(final SoapServiceConfiguration serviceConfiguration, final URL alternateEndpointUrl) {
045                    super(serviceConfiguration, alternateEndpointUrl);
046            }
047    
048        @Override
049            public SoapServiceConfiguration getServiceConfiguration() {
050                    return (SoapServiceConfiguration) super.getServiceConfiguration();
051            }
052            
053            /**
054             * This overridden method returns a CXF client praoxy for web service.
055             * 
056             * @see org.kuali.rice.ksb.messaging.serviceconnectors.ServiceConnector#getService()
057             */
058            public Object getService() {
059                    ClientProxyFactoryBean clientFactory;
060                    
061                    //Use the correct bean factory depending on pojo service or jaxws service
062                    if (getServiceConfiguration().isJaxWsService()){
063                            clientFactory = new JaxWsProxyFactoryBean();
064                    } else {
065                            clientFactory = new ClientProxyFactoryBean();
066                            clientFactory.getServiceFactory().setDataBinding(new AegisDatabinding());
067                    }               
068    
069                    try {
070                            clientFactory.setServiceClass(Class.forName(getServiceConfiguration().getServiceInterface()));
071                    } catch (ClassNotFoundException e) {
072                            throw new RiceRuntimeException("Failed to connect to soap service " + getServiceConfiguration().getServiceName() + " because failed to load interface class: " + getServiceConfiguration().getServiceInterface(), e);
073                    }
074                    clientFactory.setBus(KSBServiceLocator.getCXFBus());
075                    clientFactory.setServiceName(getServiceConfiguration().getServiceName());
076                    clientFactory.setAddress(getActualEndpointUrl().toExternalForm());
077                    
078                    //Set logging, transformation, and security interceptors
079                clientFactory.getOutInterceptors().add(new LoggingOutInterceptor());
080                    clientFactory.getOutInterceptors().add(new CXFWSS4JOutInterceptor(getServiceConfiguration().getBusSecurity()));
081                    if (getCredentialsSource() != null) {
082                            clientFactory.getOutInterceptors().add(new CredentialsOutHandler(getCredentialsSource(), getServiceConfiguration()));
083                    }
084    
085                clientFactory.getInInterceptors().add(new LoggingInInterceptor());
086            clientFactory.getInInterceptors().add(new CXFWSS4JInInterceptor(getServiceConfiguration().getBusSecurity()));
087            clientFactory.getInInterceptors().add(new ImmutableCollectionsInInterceptor());
088    
089                    
090                    Object service = clientFactory.create();                
091                    return getServiceProxyWithFailureMode(service, getServiceConfiguration());
092            }       
093    }