View Javadoc

1   /**
2    * Copyright 2005-2013 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.kew.routemanager;
17  
18  import org.kuali.rice.kew.messaging.exceptionhandling.ExceptionRoutingServiceImpl;
19  import org.kuali.rice.kew.test.TestUtilities;
20  import org.kuali.rice.ksb.messaging.PersistedMessageBO;
21  import org.kuali.rice.test.ThreadMonitor;
22  
23  
24  
25  public class TestExceptionRoutingServiceImpl extends ExceptionRoutingServiceImpl {
26  
27      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
28  	    .getLogger(TestExceptionRoutingServiceImpl.class);
29      
30  	@Override
31  	public void placeInExceptionRouting(Throwable throwable, PersistedMessageBO persistedMessage, String documentId) {
32          LOG.info("Invoking placeInExceptionRouting on TestExceptionRoutingServiceImpl");
33  		ExceptionThreader exceptionThreader = new ExceptionThreader(throwable, persistedMessage, documentId, this);
34  		ThreadMonitor.addThread(exceptionThreader);
35  		exceptionThreader.start();
36          LOG.info("ExceptionThreader has been started");
37  	}
38  	
39  	private static class ExceptionThreader extends Thread {
40  
41  		private Throwable throwable;
42  		private PersistedMessageBO message;
43  		String documentId;
44  		private TestExceptionRoutingServiceImpl testExceptionService;
45  		
46  		public ExceptionThreader(Throwable throwable, PersistedMessageBO message, String documentId, TestExceptionRoutingServiceImpl testExceptionService) {
47  			this.throwable = throwable;
48  			this.message = message;
49  			this.documentId = documentId;
50  			this.testExceptionService = testExceptionService;
51  			TestUtilities.setExceptionThreader(this);
52  		}
53  
54  		public void run() {
55  		    try {
56  			    testExceptionService.callRealPlaceInExceptionRouting(throwable, message, documentId);
57  		    } catch (Exception e) {
58  			    LOG.error("Exception encountered when attempting to callRealPlaceInExceptionRouting", e);
59  		    }
60  		}
61  	}
62  	
63  	public void callRealPlaceInExceptionRouting(Throwable throwable, PersistedMessageBO message, String documentId) throws Exception {
64          LOG.info("Invoking the real place in exception routing");
65  		super.placeInExceptionRouting(throwable, message, documentId);
66          LOG.info("Document should now be in exception status");
67  	}	
68  }