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.serviceexporters;
17  
18  
19  import org.apache.cxf.Bus;
20  import org.apache.cxf.aegis.databinding.AegisDatabinding;
21  import org.apache.cxf.endpoint.ServerRegistry;
22  import org.apache.cxf.frontend.ServerFactoryBean;
23  import org.apache.cxf.interceptor.LoggingInInterceptor;
24  import org.apache.cxf.interceptor.LoggingOutInterceptor;
25  import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
26  import org.apache.log4j.Logger;
27  import org.kuali.rice.core.api.exception.RiceRuntimeException;
28  import org.kuali.rice.ksb.api.bus.ServiceDefinition;
29  import org.kuali.rice.ksb.api.bus.support.SoapServiceDefinition;
30  import org.kuali.rice.ksb.impl.cxf.interceptors.ImmutableCollectionsInInterceptor;
31  import org.kuali.rice.ksb.security.soap.CXFWSS4JInInterceptor;
32  import org.kuali.rice.ksb.security.soap.CXFWSS4JOutInterceptor;
33  
34  
35  /**
36   *
37   * @author Kuali Rice Team (rice.collab@kuali.org)
38   */
39  public class SOAPServiceExporter extends AbstractWebServiceExporter implements ServiceExporter {
40  
41  	static final Logger LOG = Logger.getLogger(SOAPServiceExporter.class);
42  		
43  	public SOAPServiceExporter(SoapServiceDefinition serviceDefinition, Bus cxfBus, ServerRegistry cxfServerRegistry) {
44  	    super(serviceDefinition, cxfBus, cxfServerRegistry);
45  	}
46  
47  	/**
48  	 * This publishes the cxf service onto the cxf bus.
49  	 * 
50  	 * @param serviceImpl
51  	 * @throws Exception
52  	 */
53  	@Override
54      public void publishService(ServiceDefinition serviceDefinition, Object serviceImpl, String address) {
55  		ServerFactoryBean svrFactory;
56  		
57  		SoapServiceDefinition soapServiceDefinition = (SoapServiceDefinition)serviceDefinition;
58  		
59  		//Use the correct bean factory depending on pojo service or jaxws service
60  		if (soapServiceDefinition.isJaxWsService()){
61  			LOG.info("Creating JaxWsService " + soapServiceDefinition.getServiceName());
62  			svrFactory = new JaxWsServerFactoryBean();
63  		} else {
64  			svrFactory = new ServerFactoryBean();
65  			
66  			//JAXB Binding not supported for pojo service (CXF-897)
67  			svrFactory.getServiceFactory().setDataBinding(new AegisDatabinding());
68  		}
69  	
70  		svrFactory.setBus(getCXFBus());
71  		svrFactory.setServiceName(soapServiceDefinition.getServiceName());
72  		svrFactory.setAddress(address);
73  		svrFactory.setPublishedEndpointUrl(soapServiceDefinition.getEndpointUrl().toExternalForm());
74  		svrFactory.setServiceBean(serviceImpl);
75  		
76  		try {
77  			svrFactory.setServiceClass(Class.forName(soapServiceDefinition.getServiceInterface()));
78  		} catch (ClassNotFoundException e) {
79  			throw new RiceRuntimeException("Failed to publish service " + soapServiceDefinition.getServiceName() + " because service interface could not be loaded: " + soapServiceDefinition.getServiceInterface(), e);
80  		}
81  		
82  		//Set logging and security interceptors
83  		svrFactory.getInInterceptors().add(new LoggingInInterceptor());
84  		svrFactory.getInInterceptors().add(new CXFWSS4JInInterceptor(soapServiceDefinition.getBusSecurity()));
85          svrFactory.getInInterceptors().add(new ImmutableCollectionsInInterceptor());
86  		
87  		svrFactory.getOutInterceptors().add(new LoggingOutInterceptor());
88  		svrFactory.getOutInterceptors().add(new CXFWSS4JOutInterceptor(soapServiceDefinition.getBusSecurity()));
89  
90  		svrFactory.getInFaultInterceptors().add(new CXFWSS4JInInterceptor(soapServiceDefinition.getBusSecurity()));
91  		svrFactory.getOutFaultInterceptors().add(new CXFWSS4JOutInterceptor(soapServiceDefinition.getBusSecurity()));
92  		
93  		svrFactory.create();
94  	}
95  
96  }