-
Notifications
You must be signed in to change notification settings - Fork 328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
checking if result is used on DefaultLogicResult #804
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ | |
import org.slf4j.LoggerFactory; | ||
|
||
import br.com.caelum.vraptor.Get; | ||
import br.com.caelum.vraptor.Result; | ||
import br.com.caelum.vraptor.controller.ControllerMethod; | ||
import br.com.caelum.vraptor.controller.DefaultControllerMethod; | ||
import br.com.caelum.vraptor.controller.HttpMethod; | ||
|
@@ -68,17 +69,20 @@ public class DefaultLogicResult implements LogicResult { | |
private final FlashScope flash; | ||
private final MethodInfo methodInfo; | ||
|
||
private 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; | ||
|
@@ -97,24 +101,26 @@ public DefaultLogicResult(Proxifier proxifier, Router router, MutableRequest req | |
@Override | ||
public <T> T forwardTo(final Class<T> type) { | ||
return proxifier.proxify(type, new MethodInvocation<T>() { | ||
|
||
@Override | ||
public Object intercept(T proxy, Method method, Object[] args, SuperMethod superMethod) { | ||
try { | ||
logger.debug("Executing {}", method); | ||
ControllerMethod old = methodInfo.getControllerMethod(); | ||
methodInfo.setControllerMethod(DefaultControllerMethod.instanceFor(type, method)); | ||
Object result = method.invoke(container.instanceFor(type), args); | ||
Object methodResult = method.invoke(container.instanceFor(type), args); | ||
methodInfo.setControllerMethod(old); | ||
|
||
Type returnType = method.getGenericReturnType(); | ||
if (!(returnType == void.class)) { | ||
request.setAttribute(extractor.nameFor(returnType), result); | ||
request.setAttribute(extractor.nameFor(returnType), methodResult); | ||
} | ||
if (!response.isCommitted()) { | ||
String path = resolver.pathFor(DefaultControllerMethod.instanceFor(type, method)); | ||
logger.debug("Forwarding to {}", path); | ||
request.getRequestDispatcher(path).forward(request, response); | ||
if (response.isCommitted() || result.used()) { | ||
return null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd log debug here, at least. |
||
} | ||
String path = resolver.pathFor(DefaultControllerMethod.instanceFor(type, method)); | ||
logger.debug("Forwarding to {}", path); | ||
request.getRequestDispatcher(path).forward(request, response); | ||
return null; | ||
} catch (InvocationTargetException e) { | ||
propagateIfPossible(e.getCause()); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,11 +72,13 @@ public class DefaultLogicResultTest { | |
private @Mock TypeNameExtractor extractor; | ||
private @Mock RequestDispatcher dispatcher; | ||
private @Mock FlashScope flash; | ||
private @Mock Result result; | ||
|
||
private Proxifier proxifier; | ||
|
||
private MethodInfo methodInfo; | ||
|
||
|
||
public static class MyComponent { | ||
int calls = 0; | ||
|
||
|
@@ -114,7 +116,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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no tests for result.used? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. E isso quebou o forward :'( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Qual o problema com o forward ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sempre que eu faço o forward o used vem true. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @andytsunami Abra uma issue explicando o cenário completo para que possamos entender o que acontece. Ou se preferir, mande um email para a nossa mailing list. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Abri a issue #825 |
||
} | ||
|
||
@Test | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
result.used() always returns true.. no more forward :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right! 💣 💣 💣
Do you want to open a pull request fixing this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure! tks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it really needed checking for
result.used()
?Atual VRaptor's version probably is breanking many application since
forward
isn't working.