handler mapping fixes
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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";
|
||||
|
||||
Reference in New Issue
Block a user