1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.ksb.messaging.exceptionhandling;
17
18 import org.kuali.rice.ksb.messaging.PersistedMessageBO;
19 import org.kuali.rice.test.TestUtilities;
20
21
22 public class TestExceptionHandlerServiceImpl extends DefaultExceptionServiceImpl {
23
24 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
25 .getLogger(TestExceptionHandlerServiceImpl.class);
26
27 public void placeInExceptionRouting(Throwable throwable, PersistedMessageBO message, Object service) {
28 LOG.info("Executing placeInExceptionRouting - creating and starting the ExceptionThreader");
29 ExceptionThreader exceptionThreader = new ExceptionThreader(throwable, message, service, this);
30 exceptionThreader.start();
31 }
32
33 private static class ExceptionThreader extends Thread {
34
35 private Throwable throwable;
36 private PersistedMessageBO message;
37 private Object service;
38 private TestExceptionHandlerServiceImpl testExceptionService;
39
40 public ExceptionThreader(Throwable throwable, PersistedMessageBO message, Object service, TestExceptionHandlerServiceImpl testExceptionService) {
41 this.throwable = throwable;
42 this.message = message;
43 this.service = service;
44 this.testExceptionService = testExceptionService;
45 TestUtilities.setExceptionThreader(this);
46 }
47
48 public void run() {
49 LOG.info("Running the ExceptionThreader - sleeping for 3 seconds - " + this.toString());
50 try {
51 Thread.sleep(3000);
52 } catch (InterruptedException e) {
53 e.printStackTrace();
54 }
55 try {
56 LOG.info("Executing 'real' placeInExceptionRouting from ExceptionThreader.");
57 this.testExceptionService.callRealPlaceInExceptionRouting(this.throwable, this.message, this.service);
58 } catch (Throwable t) {
59 LOG.fatal("Error executing callRealPlaceInExceptionRouting.", t);
60 }
61 }
62 }
63
64 public void callRealPlaceInExceptionRouting(Throwable throwable, PersistedMessageBO message, Object service) throws Exception {
65 LOG.info("Executing callRealPlaceInExceptionRouting from TestExceptionHandlerServiceImpl.");
66 super.placeInExceptionRouting(throwable, message, service);
67 LOG.info("Message was successfully placed in exception routing.");
68 }
69
70 }