handler mapping fixes

This commit is contained in:
Keith Donald
2008-12-10 14:01:51 +00:00
parent 159cbd8403
commit 4ba93b4349
4 changed files with 22 additions and 3 deletions

View File

@@ -76,7 +76,12 @@ public class DefaultFlowUrlHandler implements FlowUrlHandler {
return servletPath.substring(1);
}
} else {
return request.getContextPath().substring(1);
String contextPath = request.getContextPath();
if (StringUtils.hasText(contextPath)) {
return request.getContextPath().substring(1);
} else {
return null;
}
}
}
}
@@ -97,10 +102,15 @@ public class DefaultFlowUrlHandler implements FlowUrlHandler {
url.append('/');
url.append(flowId);
} else {
if (StringUtils.hasText(request.getServletPath())) {
String servletPath = request.getServletPath();
if (StringUtils.hasText(servletPath)) {
url.append(request.getContextPath());
url.append('/');
url.append(flowId);
int dotIndex = servletPath.lastIndexOf('.');
if (dotIndex != -1) {
url.append(servletPath.substring(dotIndex));
}
} else {
url.append('/');
url.append(flowId);

View File

@@ -90,6 +90,9 @@ public class FlowHandlerMapping extends AbstractHandlerMapping {
protected Object getHandlerInternal(HttpServletRequest request) throws Exception {
String flowId = flowUrlHandler.getFlowId(request);
if (flowId == null) {
return null;
}
if (getApplicationContext().containsBean(flowId)) {
Object handler = getApplicationContext().getBean(flowId);
if (handler instanceof FlowHandler) {

View File

@@ -58,7 +58,7 @@ public class DefaultFlowUrlHandlerTests extends TestCase {
request.setServletPath("/app/foo.htm");
request.setRequestURI("/springtravel/app/foo");
String url = urlHandler.createFlowDefinitionUrl("app/foo", null, request);
assertEquals("/springtravel/app/foo", url);
assertEquals("/springtravel/app/foo.htm", url);
}
public void testCreateFlowDefinitionUrlContextPathOnly() {

View File

@@ -68,6 +68,12 @@ public class FlowHandlerMappingTests extends TestCase {
assertNull(chain);
}
public void testGetHandlerNullFlowId() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
HandlerExecutionChain chain = mapping.getHandler(request);
assertNull(chain);
}
private static class FlowDefinitionImpl implements FlowDefinition {
private String flowId = "flow";