redirect prefixes
This commit is contained in:
@@ -423,12 +423,12 @@ The supported formats for an encoded externalRedirect expression are:
|
||||
externalRedirect:<servlet relative path>
|
||||
externalRedirect:contextRelative:<context relative path>
|
||||
externalRedirect:serverRelative:<server relative path>
|
||||
externalRedirect:url:<fully qualified URL>
|
||||
externalRedirect:<fully qualified http:// or https:// URL>
|
||||
</pre>
|
||||
For example:
|
||||
<pre>
|
||||
externalRedirect:/hotels/index
|
||||
externalRedirect:url:http://someOtherSystem?orderId=${order.id}&callbackUrl=${flowExecutionUrl}
|
||||
externalRedirect:http://someOtherSystem?orderId=${order.id}&callbackUrl=${flowExecutionUrl}
|
||||
</pre>
|
||||
The flowRedirect: prefix may be used to redirect to another flow:
|
||||
<pre>
|
||||
@@ -902,12 +902,12 @@ The supported formats for an encoded externalRedirect expression are:
|
||||
externalRedirect:<servlet relative path>
|
||||
externalRedirect:contextRelative:<context relative path>
|
||||
externalRedirect:serverRelative:<server relative path>
|
||||
externalRedirect:url:<fully qualified URL>
|
||||
externalRedirect:<fully qualified http:// or https:// URL>
|
||||
</pre>
|
||||
For example:
|
||||
<pre>
|
||||
externalRedirect:/hotels/index
|
||||
externalRedirect:url:http://someOtherSystem?orderId=${order.id}
|
||||
externalRedirect:http://someOtherSystem?orderId=${order.id}
|
||||
</pre>
|
||||
The flowRedirect: prefix may be used to redirect to another flow:
|
||||
<pre>
|
||||
|
||||
@@ -60,10 +60,9 @@ public interface FlowHandler {
|
||||
* <li>servletRelative: - the location is relative to the current servlet</li>
|
||||
* <li>contextRelative: - the location is relative to the current web application</li>
|
||||
* <li>serverRelative: - the location is relative to the server root</li>
|
||||
* <li>url: - the location is a fully qualified URL to an external resource</li>
|
||||
* </ul>
|
||||
* 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.
|
||||
* <p>
|
||||
* For servlet-relative, context-relative, and server-relative URLs, a leading slash is optional.
|
||||
*
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user