From 12423471b5a059a5713f6bcdbef7e67817309634 Mon Sep 17 00:00:00 2001 From: Keith Donald Date: Thu, 24 Apr 2008 19:16:18 +0000 Subject: [PATCH] redirect prefixes --- .../model/builder/xml/spring-webflow-2.0.xsd | 8 ++-- .../webflow/mvc/servlet/FlowHandler.java | 5 +-- .../mvc/servlet/FlowHandlerAdapter.java | 18 +------- .../mvc/servlet/FlowControllerTests.java | 2 +- .../mvc/servlet/FlowHandlerAdapterTests.java | 43 ++++++++----------- 5 files changed, 28 insertions(+), 48 deletions(-) diff --git a/spring-webflow/src/main/java/org/springframework/webflow/engine/model/builder/xml/spring-webflow-2.0.xsd b/spring-webflow/src/main/java/org/springframework/webflow/engine/model/builder/xml/spring-webflow-2.0.xsd index 81ee3ba1..5438f95d 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/engine/model/builder/xml/spring-webflow-2.0.xsd +++ b/spring-webflow/src/main/java/org/springframework/webflow/engine/model/builder/xml/spring-webflow-2.0.xsd @@ -423,12 +423,12 @@ The supported formats for an encoded externalRedirect expression are: externalRedirect: externalRedirect:contextRelative: externalRedirect:serverRelative: - externalRedirect:url: + externalRedirect: For example:
 	externalRedirect:/hotels/index
-	externalRedirect:url:http://someOtherSystem?orderId=${order.id}&callbackUrl=${flowExecutionUrl}
+	externalRedirect:http://someOtherSystem?orderId=${order.id}&callbackUrl=${flowExecutionUrl}
 
The flowRedirect: prefix may be used to redirect to another flow:
@@ -902,12 +902,12 @@ The supported formats for an encoded externalRedirect expression are:
 	externalRedirect:
 	externalRedirect:contextRelative:
 	externalRedirect:serverRelative:
-	externalRedirect:url:
+	externalRedirect:
 
For example:
 	externalRedirect:/hotels/index
-	externalRedirect:url:http://someOtherSystem?orderId=${order.id}
+	externalRedirect:http://someOtherSystem?orderId=${order.id}
 
The flowRedirect: prefix may be used to redirect to another flow:
diff --git a/spring-webflow/src/main/java/org/springframework/webflow/mvc/servlet/FlowHandler.java b/spring-webflow/src/main/java/org/springframework/webflow/mvc/servlet/FlowHandler.java
index d9a831c8..03efb997 100644
--- a/spring-webflow/src/main/java/org/springframework/webflow/mvc/servlet/FlowHandler.java
+++ b/spring-webflow/src/main/java/org/springframework/webflow/mvc/servlet/FlowHandler.java
@@ -60,10 +60,9 @@ public interface FlowHandler {
 	 * 
  • servletRelative: - the location is relative to the current servlet
  • *
  • contextRelative: - the location is relative to the current web application
  • *
  • serverRelative: - the location is relative to the server root
  • - *
  • url: - the location is a fully qualified URL to an external resource
  • * - * Also, if the returned location no prefix, for example "/hotels/index", the location is treated as relative to the - * current servlet by default. + * If the returned location is a path with no prefix, for example "/hotels/index", it is treated as relative to the + * current servlet by default. Fully qualified URLs beginning with http:// or https:// may also be returned. *

    * For servlet-relative, context-relative, and server-relative URLs, a leading slash is optional. * diff --git a/spring-webflow/src/main/java/org/springframework/webflow/mvc/servlet/FlowHandlerAdapter.java b/spring-webflow/src/main/java/org/springframework/webflow/mvc/servlet/FlowHandlerAdapter.java index c9b73011..653a3fd8 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/mvc/servlet/FlowHandlerAdapter.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/mvc/servlet/FlowHandlerAdapter.java @@ -16,8 +16,6 @@ package org.springframework.webflow.mvc.servlet; import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; import java.util.Iterator; import java.util.Map; @@ -61,8 +59,6 @@ public class FlowHandlerAdapter extends WebContentGenerator implements HandlerAd private static final String SERVER_RELATIVE_LOCATION_PREFIX = "serverRelative:"; - private static final String URL_LOCATION_PREFIX = "url:"; - /** * The entry point into Spring Web Flow. */ @@ -351,18 +347,8 @@ public class FlowHandlerAdapter extends WebContentGenerator implements HandlerAd url = "/" + url; } sendRedirect(url, response); - } else if (location.startsWith(URL_LOCATION_PREFIX)) { - String url = location.substring(URL_LOCATION_PREFIX.length()); - try { - new URL(url); - sendRedirect(url, response); - } catch (MalformedURLException e) { - IllegalArgumentException iae = new IllegalArgumentException("The redirect url '" + url - + "' is invalid; specify a fully qualified URL when using the '" + URL_LOCATION_PREFIX - + "' location prefix"); - iae.initCause(e); - throw iae; - } + } else if (location.startsWith("http://") || location.startsWith("https://")) { + sendRedirect(location, response); } else { sendServletRelativeRedirect(location, request, response); } diff --git a/spring-webflow/src/test/java/org/springframework/webflow/mvc/servlet/FlowControllerTests.java b/spring-webflow/src/test/java/org/springframework/webflow/mvc/servlet/FlowControllerTests.java index 0800f47a..420b8350 100644 --- a/spring-webflow/src/test/java/org/springframework/webflow/mvc/servlet/FlowControllerTests.java +++ b/spring-webflow/src/test/java/org/springframework/webflow/mvc/servlet/FlowControllerTests.java @@ -224,7 +224,7 @@ public class FlowControllerTests extends TestCase { request.setPathInfo("/foo"); request.setRequestURI("/springtravel/app/foo"); request.setMethod("GET"); - context.requestExternalRedirect("url:http://www.paypal.com"); + context.requestExternalRedirect("http://www.paypal.com"); executor.launchExecution("foo", null, context); FlowExecutionResult result = FlowExecutionResult.createPausedResult("foo", "12345"); EasyMock.expectLastCall().andReturn(result); diff --git a/spring-webflow/src/test/java/org/springframework/webflow/mvc/servlet/FlowHandlerAdapterTests.java b/spring-webflow/src/test/java/org/springframework/webflow/mvc/servlet/FlowHandlerAdapterTests.java index 820ef6d9..419776ef 100644 --- a/spring-webflow/src/test/java/org/springframework/webflow/mvc/servlet/FlowHandlerAdapterTests.java +++ b/spring-webflow/src/test/java/org/springframework/webflow/mvc/servlet/FlowHandlerAdapterTests.java @@ -196,13 +196,13 @@ public class FlowHandlerAdapterTests extends TestCase { EasyMock.verify(new Object[] { flowExecutor }); } - public void testLaunchFlowWithExternalRedirect() throws Exception { + public void testLaunchFlowWithExternalHttpRedirect() throws Exception { request.setContextPath("/springtravel"); request.setServletPath("/app"); request.setPathInfo("/foo"); request.setRequestURI("/springtravel/app/foo"); request.setMethod("GET"); - context.requestExternalRedirect("url:http://www.paypal.com"); + context.requestExternalRedirect("http://www.paypal.com"); flowExecutor.launchExecution("foo", flowInput, context); FlowExecutionResult result = FlowExecutionResult.createPausedResult("foo", "12345"); EasyMock.expectLastCall().andReturn(result); @@ -213,6 +213,23 @@ public class FlowHandlerAdapterTests extends TestCase { EasyMock.verify(new Object[] { flowExecutor }); } + public void testLaunchFlowWithExternalHttpsRedirect() throws Exception { + request.setContextPath("/springtravel"); + request.setServletPath("/app"); + request.setPathInfo("/foo"); + request.setRequestURI("/springtravel/app/foo"); + request.setMethod("GET"); + context.requestExternalRedirect("https://www.paypal.com"); + flowExecutor.launchExecution("foo", flowInput, context); + FlowExecutionResult result = FlowExecutionResult.createPausedResult("foo", "12345"); + EasyMock.expectLastCall().andReturn(result); + EasyMock.replay(new Object[] { flowExecutor }); + flowHandlerAdapter.handle(request, response, flowHandler); + EasyMock.verify(new Object[] { flowExecutor }); + assertEquals("https://www.paypal.com", response.getRedirectedUrl()); + EasyMock.verify(new Object[] { flowExecutor }); + } + public void testLaunchFlowWithExternalRedirectServletRelative() throws Exception { request.setContextPath("/springtravel"); request.setServletPath("/app"); @@ -315,28 +332,6 @@ public class FlowHandlerAdapterTests extends TestCase { EasyMock.verify(new Object[] { flowExecutor }); } - public void testLaunchFlowWithExternalRedirectMalformedUrl() throws Exception { - request.setContextPath("/springtravel"); - request.setServletPath("/app"); - request.setPathInfo("/foo"); - request.setRequestURI("/springtravel/app/foo"); - request.setMethod("GET"); - context.requestExternalRedirect("url:/bogus"); - flowExecutor.launchExecution("foo", flowInput, context); - FlowExecutionResult result = FlowExecutionResult.createPausedResult("foo", "12345"); - EasyMock.expectLastCall().andReturn(result); - EasyMock.replay(new Object[] { flowExecutor }); - try { - flowHandlerAdapter.handle(request, response, flowHandler); - fail("Should have failed iae"); - } catch (IllegalArgumentException e) { - - } - EasyMock.verify(new Object[] { flowExecutor }); - assertEquals(null, response.getRedirectedUrl()); - EasyMock.verify(new Object[] { flowExecutor }); - } - public void testDefaultHandleFlowException() throws Exception { request.setContextPath("/springtravel"); request.setServletPath("/app");