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.ken.service.ws.impl;
017
018import org.apache.log4j.Logger;
019import org.kuali.rice.core.api.util.xml.XmlException;
020import org.kuali.rice.ken.bo.NotificationResponseBo;
021import org.kuali.rice.ken.service.NotificationMessageContentService;
022import org.kuali.rice.ken.service.NotificationService;
023import org.kuali.rice.ken.service.ws.NotificationWebService;
024import org.kuali.rice.ken.util.NotificationConstants;
025import org.kuali.rice.ken.util.PerformanceLog;
026import org.kuali.rice.ken.util.PerformanceLog.PerformanceStopWatch;
027
028import java.io.IOException;
029import java.rmi.RemoteException;
030
031/**
032 * Web service interface implementation that delegates directly to Spring service
033 * Spring integration strategy taken from:
034 * http://javaboutique.internet.com/tutorials/axisspring/
035 * This class extends ServletEndpointSupport so that it can obtain the Notification System Spring context
036 * from the ServletContext via getWebApplicationContext().  It then delegates to the NotificationService.
037 * @author Kuali Rice Team (rice.collab@kuali.org)
038 */
039public class NotificationWebServiceImpl /*extends ServletEndpointSupport*/ implements NotificationWebService {
040    private static final Logger LOG = Logger.getLogger(NotificationWebServiceImpl.class);
041
042    private NotificationService notificationService;
043    private NotificationMessageContentService notificationMessageContentService;
044
045    /**
046     * Callback for custom initialization after the context has been set up.
047     * @throws ServiceException if initialization failed
048     */
049    /*protected void onInit() throws ServiceException {
050        // grab the spring application context from the webapp context so that we can look up our service in spring 
051        NotificationServiceLocator locator = new SpringNotificationServiceLocator(getWebApplicationContext());
052        this.notificationService = locator.getNotificationService();
053        this.notificationMessageContentService = locator.getNotificationMessageContentService();
054    }*/
055
056    /**
057     * Invokes the underlying Java API calls via Spring service invocation.
058     * @see org.kuali.rice.ken.service.ws.NotificationWebService#sendNotification(java.lang.String)
059     */
060    public String sendNotification(String notificationMessageAsXml) throws RemoteException {
061        PerformanceStopWatch watch = PerformanceLog.startTimer("Time to send notification from web service");
062        
063        NotificationResponseBo response;
064        try {
065            response = notificationService.sendNotification(notificationMessageAsXml);
066
067        } catch(IOException ioe) {
068            response = new NotificationResponseBo();
069            response.setStatus(NotificationConstants.RESPONSE_STATUSES.FAILURE);
070            response.setMessage("Failed to process the message content: " + ioe.getMessage());
071            LOG.error("Failed to process the message content", ioe);
072        } catch(XmlException ixe) {
073            response = new NotificationResponseBo();
074            response.setStatus(NotificationConstants.RESPONSE_STATUSES.FAILURE);
075            response.setMessage("Failed to process the message content because the XML message provided to the system was invalid: " + ixe.getMessage());
076            LOG.error("Failed to process the message content because the XML message provided to the system was invalid", ixe);
077        }
078
079        String responseAsXml = notificationMessageContentService.generateNotificationResponseMessage(response);
080
081        watch.recordDuration();
082        
083        LOG.info("Notification response: " + response);
084        
085        return responseAsXml;
086    }
087}