Skip to content

Commit

Permalink
Merge pull request #867 from caelum/issue778
Browse files Browse the repository at this point in the history
Closes #778. Checking result.used() before forward
  • Loading branch information
Turini committed Nov 12, 2014
2 parents ba8d016 + ad44686 commit fc19dd2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package br.com.caelum.vraptor.core;


import static br.com.caelum.vraptor.view.Results.logic;
import static java.util.Collections.unmodifiableMap;

import java.util.HashMap;
Expand Down Expand Up @@ -75,12 +76,19 @@ public DefaultResult(HttpServletRequest request, Container container, ExceptionM

@Override
public <T extends View> T use(Class<T> view) {

messages.assertAbsenceOfErrors();

responseCommitted = true;
return container.instanceFor(view);
}

@Override
public <T> T forwardTo(Class<T> controller) {
messages.assertAbsenceOfErrors();
return container.instanceFor(logic()).forwardTo(controller);
}

@Override
public Result on(Class<? extends Exception> exception) {
return exceptions.record(exception);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import org.slf4j.LoggerFactory;

import br.com.caelum.vraptor.Get;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.View;
import br.com.caelum.vraptor.controller.ControllerMethod;
import br.com.caelum.vraptor.controller.DefaultControllerMethod;
import br.com.caelum.vraptor.controller.HttpMethod;
Expand Down Expand Up @@ -67,18 +69,20 @@ public class DefaultLogicResult implements LogicResult {
private final TypeNameExtractor extractor;
private final FlashScope flash;
private final MethodInfo methodInfo;
private final Result result;

/**
* @deprecated CDI eyes only
*/
protected DefaultLogicResult() {
this(null, null, null, null, null, null, null, null, null);
this(null, null, null, null, null, null, null, null, null, null);
}

@Inject
public DefaultLogicResult(Proxifier proxifier, Router router, MutableRequest request, HttpServletResponse response,
Container container, PathResolver resolver, TypeNameExtractor extractor, FlashScope flash, MethodInfo methodInfo) {
Container container, PathResolver resolver, TypeNameExtractor extractor, FlashScope flash, MethodInfo methodInfo, Result result) {
this.proxifier = proxifier;
this.result = result;
this.response = unproxifyIfPossible(response);
this.request = unproxifyIfPossible(request);
this.router = router;
Expand Down Expand Up @@ -111,7 +115,8 @@ public Object intercept(T proxy, Method method, Object[] args, SuperMethod super
if (!(returnType == void.class)) {
request.setAttribute(extractor.nameFor(returnType), methodResult);
}
if (response.isCommitted()) {

if (response.isCommitted() || result.used()) {
logger.debug("Response already commited, not forwarding.");
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public class DefaultLogicResultTest {
private @Mock TypeNameExtractor extractor;
private @Mock RequestDispatcher dispatcher;
private @Mock FlashScope flash;
private @Mock Result result;

private Proxifier proxifier;

Expand Down Expand Up @@ -120,7 +121,7 @@ public void setup() {
proxifier = new JavassistProxifier();
methodInfo = new MethodInfo(new ParanamerNameProvider());
this.logicResult = new DefaultLogicResult(proxifier, router, request, response, container,
resolver, extractor, flash, methodInfo);
resolver, extractor, flash, methodInfo, result);
}

@Test
Expand Down

0 comments on commit fc19dd2

Please sign in to comment.