Coverage Report - org.kuali.rice.ksb.messaging.exceptionhandling.DefaultExceptionServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
DefaultExceptionServiceImpl
0%
0/35
0%
0/6
2
 
 1  
 /*
 2  
  * Copyright 2007-2008 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.exceptionhandling;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.apache.log4j.Logger;
 20  
 import org.kuali.rice.ksb.messaging.AsynchronousCall;
 21  
 import org.kuali.rice.ksb.messaging.PersistedMessage;
 22  
 import org.kuali.rice.ksb.messaging.RemoteResourceServiceLocator;
 23  
 import org.kuali.rice.ksb.messaging.quartz.MessageServiceExecutorJob;
 24  
 import org.kuali.rice.ksb.messaging.quartz.MessageServiceExecutorJobListener;
 25  
 import org.kuali.rice.ksb.messaging.resourceloader.KSBResourceLoaderFactory;
 26  
 import org.kuali.rice.ksb.service.KSBServiceLocator;
 27  
 import org.quartz.JobDataMap;
 28  
 import org.quartz.JobDetail;
 29  
 import org.quartz.Scheduler;
 30  
 import org.quartz.SimpleTrigger;
 31  
 import org.quartz.Trigger;
 32  
 
 33  
 
 34  
 /**
 35  
  * Default implementation of {@link ExceptionRoutingService}.  Just saves 
 36  
  * the message in the queue as is, which should be marked Exception by the 
 37  
  * {@link MessageExceptionHandler}.
 38  
  * 
 39  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 40  
  *
 41  
  */
 42  0
 public class DefaultExceptionServiceImpl implements ExceptionRoutingService {
 43  
         
 44  0
         private static final Logger LOG = Logger.getLogger(DefaultExceptionServiceImpl.class);
 45  
 
 46  
         public void placeInExceptionRouting(Throwable throwable, PersistedMessage message, Object service) throws Exception {
 47  0
                 LOG.error("Exception caught processing message " + message.getRouteQueueId() + " " + message.getServiceName() + ": " + throwable);
 48  
                 
 49  0
                 RemoteResourceServiceLocator remoteResourceServiceLocator = KSBResourceLoaderFactory.getRemoteResourceLocator();
 50  0
                 AsynchronousCall methodCall = null;
 51  0
                 if (message.getMethodCall() != null) {
 52  0
                         methodCall = message.getMethodCall();
 53  
                 } else {
 54  0
                         methodCall = message.getPayload().getMethodCall();
 55  
                 }
 56  0
                 message.setMethodCall(methodCall);
 57  0
                 MessageExceptionHandler exceptionHandler = remoteResourceServiceLocator.getMessageExceptionHandler(methodCall.getServiceInfo().getQname());
 58  0
                 exceptionHandler.handleException(throwable, message, service);
 59  0
         }
 60  
         
 61  
         public void placeInExceptionRoutingLastDitchEffort(Throwable throwable, PersistedMessage message, Object service) throws Exception {
 62  0
                 LOG.error("Exception caught processing message " + message.getRouteQueueId() + " " + message.getServiceName() + ": " + throwable);
 63  
                 
 64  0
                 RemoteResourceServiceLocator remoteResourceServiceLocator = KSBResourceLoaderFactory.getRemoteResourceLocator();
 65  0
                 AsynchronousCall methodCall = null;
 66  0
                 if (message.getMethodCall() != null) {
 67  0
                         methodCall = message.getMethodCall();
 68  
                 } else {
 69  0
                         methodCall = message.getPayload().getMethodCall();
 70  
                 }
 71  0
                 message.setMethodCall(methodCall);
 72  0
                 MessageExceptionHandler exceptionHandler = remoteResourceServiceLocator.getMessageExceptionHandler(methodCall.getServiceInfo().getQname());
 73  0
                 exceptionHandler.handleExceptionLastDitchEffort(throwable, message, service);
 74  0
         }
 75  
         
 76  
         
 77  
 
 78  
         public void scheduleExecution(Throwable throwable, PersistedMessage message, String description) throws Exception {
 79  0
                 KSBServiceLocator.getRouteQueueService().delete(message);
 80  0
                 Scheduler scheduler = KSBServiceLocator.getScheduler();
 81  0
                 JobDataMap jobData = new JobDataMap();
 82  0
                 jobData.put(MessageServiceExecutorJob.MESSAGE_KEY, message);
 83  0
                 JobDetail jobDetail = new JobDetail("Exception_Message_Job " + Math.random(), "Exception Messaging",
 84  
                         MessageServiceExecutorJob.class);
 85  0
                 jobDetail.setJobDataMap(jobData);
 86  0
                 if (!StringUtils.isBlank(description)) {
 87  0
                     jobDetail.setDescription(description);
 88  
                 }
 89  0
                 jobDetail.addJobListener(MessageServiceExecutorJobListener.NAME);
 90  0
                 Trigger trigger = new SimpleTrigger("Exception_Message_Trigger " + Math.random(), "Exception Messaging", message
 91  
                         .getQueueDate());
 92  0
                 trigger.setJobDataMap(jobData);// 1.6 bug required or derby will choke
 93  0
                 scheduler.scheduleJob(jobDetail, trigger);    
 94  0
         }
 95  
                 
 96  
 }