View Javadoc

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