KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > jtrac > web > FlowExceptionResolver


1 /*
2  * Copyright 2002-2005 the original author or authors.
3  *
4  * Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0
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
17 package info.jtrac.web;
18
19 import javax.servlet.http.HttpServletRequest JavaDoc;
20 import javax.servlet.http.HttpServletResponse JavaDoc;
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23 import org.springframework.web.servlet.HandlerExceptionResolver;
24 import org.springframework.web.servlet.ModelAndView;
25 import org.springframework.webflow.execution.repository.NoSuchFlowExecutionException;
26 import org.springframework.webflow.execution.repository.PermissionDeniedFlowExecutionAccessException;
27 import org.springframework.webflow.executor.support.FlowExecutorArgumentExtractionException;
28
29 /**
30  * Spring MVC exception handler resolver designed to gracefully handle
31  * the case where the user hit the browser back button during a WebFlow
32  */

33 public class FlowExceptionResolver implements HandlerExceptionResolver {
34     
35     protected final Log logger = LogFactory.getLog(getClass());
36     
37     public ModelAndView resolveException(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response, Object JavaDoc o, Exception JavaDoc e) {
38         logger.debug("exception type: " + e.getClass() + ", message: " + e.getMessage());
39         if (e instanceof NoSuchFlowExecutionException
40                 || e instanceof FlowExecutorArgumentExtractionException) {
41             logger.debug("session must have expired in the middle of a flow, redirecting to dashboard");
42             return new ModelAndView("redirect:/app");
43         } else if (e instanceof PermissionDeniedFlowExecutionAccessException) {
44             logger.debug("user must have hit browser back button, trying to handle gracefully");
45             return new ModelAndView("exception_flow");
46         } else {
47             return null; // not an exception we are interested in, pass control back to Spring
48
}
49     }
50     
51 }
52
Popular Tags