From 47f7fe11336d92d8db4dcc9b1012028349aa2d13 Mon Sep 17 00:00:00 2001 From: Keith Donald Date: Fri, 12 Sep 2008 17:18:08 +0000 Subject: [PATCH] polish --- .../webflow/context/servlet/DefaultFlowUrlHandler.java | 10 +++++++--- .../context/servlet/DefaultFlowUrlHandlerTests.java | 9 +++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/spring-webflow/src/main/java/org/springframework/webflow/context/servlet/DefaultFlowUrlHandler.java b/spring-webflow/src/main/java/org/springframework/webflow/context/servlet/DefaultFlowUrlHandler.java index cf10ae39..09b2e4b7 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/context/servlet/DefaultFlowUrlHandler.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/context/servlet/DefaultFlowUrlHandler.java @@ -22,6 +22,7 @@ import java.util.Map; import javax.servlet.http.HttpServletRequest; +import org.springframework.web.util.WebUtils; import org.springframework.webflow.core.collection.AttributeMap; /** @@ -66,10 +67,13 @@ public class DefaultFlowUrlHandler implements FlowUrlHandler { public String getFlowId(HttpServletRequest request) { String pathInfo = request.getPathInfo(); - if (pathInfo == null) { - throw new IllegalStateException("The HttpServletRequest pathInfo is null; unable to extract flowId"); + if (pathInfo != null) { + return pathInfo.substring(1); + } else { + String servletPath = request.getServletPath(); + int lastSlash = servletPath.lastIndexOf("/"); + return WebUtils.extractFilenameFromUrlPath(servletPath.substring(lastSlash)); } - return request.getPathInfo().substring(1); } public String createFlowExecutionUrl(String flowId, String flowExecutionKey, HttpServletRequest request) { diff --git a/spring-webflow/src/test/java/org/springframework/webflow/context/servlet/DefaultFlowUrlHandlerTests.java b/spring-webflow/src/test/java/org/springframework/webflow/context/servlet/DefaultFlowUrlHandlerTests.java index c7001613..53c7d0aa 100644 --- a/spring-webflow/src/test/java/org/springframework/webflow/context/servlet/DefaultFlowUrlHandlerTests.java +++ b/spring-webflow/src/test/java/org/springframework/webflow/context/servlet/DefaultFlowUrlHandlerTests.java @@ -10,6 +10,7 @@ import org.springframework.webflow.core.collection.LocalAttributeMap; public class DefaultFlowUrlHandlerTests extends TestCase { private DefaultFlowUrlHandler urlHandler = new DefaultFlowUrlHandler(); + private MockHttpServletRequest request = new MockHttpServletRequest(); public void testGetFlowId() { @@ -20,6 +21,14 @@ public class DefaultFlowUrlHandlerTests extends TestCase { assertEquals("foo", urlHandler.getFlowId(request)); } + public void testGetFlowIdNoPathInfo() { + request.setContextPath("/springtravel"); + request.setServletPath("/app/foo.htm"); + request.setPathInfo(null); + request.setRequestURI("/springtravel/app/foo.htm"); + assertEquals("foo", urlHandler.getFlowId(request)); + } + public void testGetFlowExecutionKey() { request.setContextPath("/springtravel"); request.setServletPath("/app");