001 /** 002 * Copyright 2005-2011 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 */ 016 package org.kuali.rice.ksb.messaging.exceptionhandling; 017 018 import org.kuali.rice.ksb.messaging.PersistedMessageBO; 019 import org.kuali.rice.test.TestUtilities; 020 021 022 public class TestExceptionHandlerServiceImpl extends DefaultExceptionServiceImpl { 023 024 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger 025 .getLogger(TestExceptionHandlerServiceImpl.class); 026 027 public void placeInExceptionRouting(Throwable throwable, PersistedMessageBO message, Object service) { 028 LOG.info("Executing placeInExceptionRouting - creating and starting the ExceptionThreader"); 029 ExceptionThreader exceptionThreader = new ExceptionThreader(throwable, message, service, this); 030 exceptionThreader.start(); 031 } 032 033 private static class ExceptionThreader extends Thread { 034 035 private Throwable throwable; 036 private PersistedMessageBO message; 037 private Object service; 038 private TestExceptionHandlerServiceImpl testExceptionService; 039 040 public ExceptionThreader(Throwable throwable, PersistedMessageBO message, Object service, TestExceptionHandlerServiceImpl testExceptionService) { 041 this.throwable = throwable; 042 this.message = message; 043 this.service = service; 044 this.testExceptionService = testExceptionService; 045 TestUtilities.setExceptionThreader(this); 046 } 047 048 public void run() { 049 LOG.info("Running the ExceptionThreader - sleeping for 3 seconds - " + this.toString()); 050 try { 051 Thread.sleep(3000); 052 } catch (InterruptedException e) { 053 e.printStackTrace(); 054 } 055 try { 056 LOG.info("Executing 'real' placeInExceptionRouting from ExceptionThreader."); 057 this.testExceptionService.callRealPlaceInExceptionRouting(this.throwable, this.message, this.service); 058 } catch (Throwable t) { 059 LOG.fatal("Error executing callRealPlaceInExceptionRouting.", t); 060 } 061 } 062 } 063 064 public void callRealPlaceInExceptionRouting(Throwable throwable, PersistedMessageBO message, Object service) throws Exception { 065 LOG.info("Executing callRealPlaceInExceptionRouting from TestExceptionHandlerServiceImpl."); 066 super.placeInExceptionRouting(throwable, message, service); 067 LOG.info("Message was successfully placed in exception routing."); 068 } 069 070 }