001 /** 002 * Copyright 2005-2012 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.kew.messaging.exceptionhandling; 017 018 import org.apache.commons.lang.StringUtils; 019 import org.kuali.rice.kew.api.WorkflowRuntimeException; 020 import org.kuali.rice.kew.service.KEWServiceLocator; 021 import org.kuali.rice.ksb.messaging.PersistedMessageBO; 022 import org.kuali.rice.ksb.messaging.exceptionhandling.DefaultMessageExceptionHandler; 023 import org.kuali.rice.ksb.messaging.exceptionhandling.MessageExceptionHandler; 024 import org.kuali.rice.ksb.service.KSBServiceLocator; 025 026 /** 027 * A {@link MessageExceptionHandler} which handles putting documents into 028 * exception routing. 029 * 030 * @author Kuali Rice Team (rice.collab@kuali.org) 031 */ 032 public class DocumentMessageExceptionHandler extends DefaultMessageExceptionHandler { 033 034 @Override 035 protected void placeInException(Throwable throwable, PersistedMessageBO message) throws Exception { 036 KEWServiceLocator.getExceptionRoutingService().placeInExceptionRouting(throwable, message, getDocumentId(message)); 037 } 038 039 040 041 @Override 042 public void handleExceptionLastDitchEffort(Throwable throwable, PersistedMessageBO message, Object service) throws Exception { 043 KEWServiceLocator.getExceptionRoutingService().placeInExceptionRoutingLastDitchEffort(throwable, message, getDocumentId(message)); 044 } 045 046 047 048 @Override 049 protected void scheduleExecution(Throwable throwable, PersistedMessageBO message) throws Exception { 050 String description = "DocumentId: " + getDocumentId(message); 051 KSBServiceLocator.getExceptionRoutingService().scheduleExecution(throwable, message, description); 052 } 053 054 protected String getDocumentId(PersistedMessageBO message) { 055 if (!StringUtils.isEmpty(message.getValue1())) { 056 return message.getValue1(); 057 } 058 throw new WorkflowRuntimeException("Unable to put this message in exception routing service name " + message.getServiceName()); 059 } 060 }