Coverage Report - org.kuali.rice.ksb.messaging.serviceexporters.RESTServiceExporter
 
Classes in this File Line Coverage Branch Coverage Complexity
RESTServiceExporter
0%
0/33
0%
0/10
2.667
 
 1  
 /*
 2  
  * Copyright 2005-2007 The Kuali Foundation
 3  
  *
 4  
  *
 5  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 6  
  * you may not use this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  *
 9  
  * http://www.opensource.org/licenses/ecl2.php
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.kuali.rice.ksb.messaging.serviceexporters;
 18  
 
 19  
 import java.util.List;
 20  
 
 21  
 import org.apache.cxf.binding.BindingFactoryManager;
 22  
 import org.apache.cxf.endpoint.Server;
 23  
 import org.apache.cxf.interceptor.LoggingInInterceptor;
 24  
 import org.apache.cxf.interceptor.LoggingOutInterceptor;
 25  
 import org.apache.cxf.jaxrs.JAXRSBindingFactory;
 26  
 import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
 27  
 import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
 28  
 import org.apache.log4j.Logger;
 29  
 import org.kuali.rice.ksb.messaging.RESTServiceDefinition;
 30  
 import org.kuali.rice.ksb.messaging.ServiceDefinition;
 31  
 import org.kuali.rice.ksb.messaging.ServiceInfo;
 32  
 import org.kuali.rice.ksb.service.KSBContextServiceLocator;
 33  
 
 34  
 
 35  
 /**
 36  
  * ServiceExporter for RESTful services.  This class handles the service binding and exposure via CXF.
 37  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 38  
  */
 39  
 public class RESTServiceExporter extends AbstractWebServiceExporter implements ServiceExporter {
 40  
 
 41  0
         private static final Logger LOG = Logger.getLogger(RESTServiceExporter.class);
 42  
 
 43  
         private ServiceInfo serviceInfo;
 44  
         private KSBContextServiceLocator serviceLocator;
 45  
 
 46  
         public RESTServiceExporter(ServiceInfo serviceInfo) {
 47  0
                 this(serviceInfo, null);
 48  0
         }
 49  
 
 50  
         public RESTServiceExporter(ServiceInfo serviceInfo, KSBContextServiceLocator serviceLocator) {
 51  0
             super(serviceInfo, serviceLocator);
 52  0
         }
 53  
 
 54  
         /**
 55  
          * This publishes the cxf service onto the cxf bus.
 56  
          *
 57  
          * @param serviceImpl
 58  
          * @throws Exception
 59  
          */
 60  
         @Override
 61  
         public void publishService(ServiceDefinition serviceDef, Object serviceImpl, String address) throws Exception{
 62  0
                 RESTServiceDefinition restServiceDef = (RESTServiceDefinition)serviceDef;
 63  
 
 64  0
                 LOG.info("Creating JAXRSService " + (getServiceInfo().getQname()));
 65  0
                 JAXRSServerFactoryBean svrFactory = new JAXRSServerFactoryBean();
 66  0
         svrFactory.setBus(getCXFBus());
 67  
 
 68  0
         List<Object> resources = restServiceDef.getResources();
 69  0
         if (resources != null && !resources.isEmpty()) {
 70  0
                 svrFactory.setServiceBeans(resources);
 71  
         } else {
 72  0
         Class<?> resourceClass = this.getClass().getClassLoader().loadClass(restServiceDef.getResourceClass());
 73  0
                 svrFactory.setResourceClasses(resourceClass);
 74  0
                 svrFactory.setResourceProvider(resourceClass, new SingletonResourceProvider(serviceImpl));
 75  
         }
 76  
 
 77  0
         svrFactory.setServiceName(getServiceInfo().getQname());
 78  0
         svrFactory.setAddress(address);
 79  0
         svrFactory.setExtensionMappings(restServiceDef.getExtensionMappings());
 80  0
         svrFactory.setLanguageMappings(restServiceDef.getLanguageMappings());
 81  
 
 82  0
         List<Object> providers = restServiceDef.getProviders();
 83  0
         if (providers != null)
 84  0
                 svrFactory.setProviders(providers);
 85  
 
 86  0
         BindingFactoryManager bindingFactoryManager = getCXFBus().getExtension(BindingFactoryManager.class);
 87  0
         JAXRSBindingFactory bindingFactory = new JAXRSBindingFactory();
 88  0
         bindingFactory.setBus(getCXFBus());
 89  0
         bindingFactoryManager.registerBindingFactory(JAXRSBindingFactory.JAXRS_BINDING_ID, bindingFactory);
 90  
 
 91  
                 //Set logging interceptors
 92  0
         if (LOG.isDebugEnabled()) {
 93  0
                 svrFactory.getInInterceptors().add(new LoggingInInterceptor());
 94  
         }
 95  
 //        svrFactory.getInInterceptors().add(new RESTConnector.VerifyingInInterceptor());
 96  0
         if (LOG.isDebugEnabled()) {
 97  0
                 svrFactory.getOutInterceptors().add(new LoggingOutInterceptor());
 98  
         }
 99  
 //                svrFactory.getOutInterceptors().add(new RESTConnector.SigningOutInterceptor());
 100  
 
 101  0
                 svrFactory.setPublishedEndpointUrl(getServiceInfo().getActualEndpointUrl());
 102  0
                 Server server = svrFactory.create();
 103  0
         }
 104  
 
 105  
 }