Permalink
Browse files

Proper way to store redirects in flow responses.

  • Loading branch information...
1 parent ce8e405 commit 9ea9e5a379ae4543b96b1746df4f41e989ee2acd @aectann aectann committed May 10, 2012
@@ -1,6 +1,7 @@
package org.amplafi.flow;
import java.io.Writer;
+import java.net.URI;
import org.amplafi.flow.web.FlowResponse;
@@ -10,6 +11,7 @@
private Exception exception;
private String errorMessage;
private FlowState flowState;
+ private URI redirectUri;
public BaseFlowResponse(Writer writer) {
this.writer = writer;
@@ -57,16 +59,17 @@ public void setFlowState(FlowState flowState) {
}
@Override
- public String getRedirect() {
- String redirect = null;
- if (flowState != null && flowState.getCurrentPage() != null && flowState.getCurrentPage().startsWith("http")) {
- redirect = flowState.getCurrentPage();
- }
- return redirect;
+ public URI getRedirect() {
+ return redirectUri;
}
@Override
public boolean isRedirectSet() {
return getRedirect() != null;
}
+
+ @Override
+ public void setRedirectURI(URI redirectUri) {
+ this.redirectUri = redirectUri;
+ }
}
@@ -136,7 +136,10 @@ public void service(FlowRequest flowRequest, FlowResponse flowResponse) {
}
doActualService(flowRequest, flowResponse, initial);
}
- flowResponse.render(renderer);
+ //Only render when client is supposed to see the result.
+ if (!flowResponse.isRedirectSet()) {
+ flowResponse.render(renderer);
+ }
}
protected void doActualService(FlowRequest request, FlowResponse flowResponse, Map<String, String> initial) {
@@ -271,8 +274,9 @@ protected FlowState completeFlowState(FlowRequest flowRequest, FlowResponse flow
flowResponse.setFlowState(flowState);
}
} catch (FlowValidationException e) {
- flowResponse.setError("Error", e);
+ flowResponse.setError("Validation error", e);
flowResponse.setFlowState(e.getFlowState());
+ flowResponse.setRedirectURI(e.getRedirectUri());
} catch (Exception e) {
flowResponse.setError("Error", e);
if (flowState != null && !flowState.isPersisted()) {
@@ -1,6 +1,7 @@
package org.amplafi.flow.web;
import java.io.Writer;
+import java.net.URI;
import org.amplafi.flow.FlowRenderer;
import org.amplafi.flow.FlowState;
@@ -29,7 +30,9 @@
void setFlowState(FlowState flowState);
- String getRedirect();
+ URI getRedirect();
boolean isRedirectSet();
+
+ void setRedirectURI(URI redirectUri);
}

0 comments on commit 9ea9e5a

Please sign in to comment.