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