001/**
002 * Copyright 2005-2017 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 */
016package org.kuali.rice.ksb.messaging.servlet;
017
018import javax.servlet.http.HttpServletRequest;
019import javax.servlet.http.HttpServletResponse;
020
021import org.apache.cxf.BusFactory;
022import org.apache.cxf.transport.servlet.ServletController;
023import org.kuali.rice.ksb.service.KSBServiceLocator;
024import org.springframework.web.servlet.ModelAndView;
025import org.springframework.web.servlet.mvc.Controller;
026
027/**
028 * An adapter for the {@link ServletController} so that it conforms to Springs MVC {@link Controller} interface. 
029 * 
030 * 
031 * @author Kuali Rice Team (rice.collab@kuali.org)
032 *
033 */
034public class CXFServletControllerAdapter implements Controller{
035
036        private ServletController controller;
037                
038        /**
039         * This method invokes the cxf servlet controller
040         * 
041         * @see org.springframework.web.servlet.mvc.Controller#handleRequest(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
042         */
043        public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
044                                                
045        try {
046                BusFactory.setThreadDefaultBus(KSBServiceLocator.getCXFBus());
047            controller.invoke(request, response);
048        } finally {
049            BusFactory.setThreadDefaultBus(null);
050        }
051
052                return null;
053        }
054                
055        public void setController(ServletController controller){
056                this.controller = controller;
057        }
058}