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
Fixing problem overriding extractControllerNameFrom method from RoutesParser. #678
Conversation
What do you think ? @lucascs @garcia-jj @Turini @dtelaroli |
Hmm, thank you to try fix this case too soon :) But I think that this is not the solution. If I'm not wrong, your code will always call Because some reason, @dtelaroli needs a point to override this behavior. So we need to change in another place. Sorry because I could not see this code yet (too short time), so may @lucascs or @Turini can help us, or fix my think if I'm wrong. |
Please, don't close this pull request yet. Wait a more comments, because I can be wrong. |
Thanks @garcia-jj for yout feedback. Really, I always call the Thanks again. |
This issue is required to implement this issue caelum/vraptor-i18n#22 |
As I said, is an ignorant solution, but maybe an way to think better about it... Or no... rsrs |
I think that the original implementation workflow it's strange. The method workflow: Maybe it's the moment to refactor with strategies for all cases. A question: When used the relative method @path should return controller name without controller @path? I think it would be interesting, otherwise the relative path do nothing different of the absolute path. |
When you use |
Really, I was wrong. It's just returned if method isn't annotated with |
And how about the relative path? |
What do you mean with relative path ? |
@path("myURI") If is relative should resolved to: /controller/myURI |
It's the default VRaptor behavior... But if you override the |
Ok. So it's does not relative, just fix wrong path. |
Yes, this PR just fix the wrong path when the |
👌 |
But as discussed with @garcia-jj, probably isn't the correct solution... I'll think in other way. |
I understood. My question was to clarification. |
I added a verification if the class has So, when a method has |
What do you think about something like this ? @garcia-jj @Turini @lucascs @dtelaroli |
I think that this pull request is wrong. Let me explain the behavior regarding routes. If you have only But you can use annotations like We can't append controller name if If I'm no wrong, the real problem is that @dtelaroli can't override this behaviour because our implementation have some bug. So we need to find this bug. Please, let me know if I'm going nuts :) |
@dtelaroli Did you wrote a component that override this behavior, right? And you told to us that doesn't work. Can you share this component with us? Because I want to do some tests here. Thank you |
When has annotation in the method but not in the class, the convention is ignored, but we need call the |
Hmm, now I see your point, makes sense. Let me wait for Lucas and Turini |
I just call |
As you can see here: https://github.com/renanigt/vraptor4/blob/fixingOverridingRoutesParser/vraptor-core/src/main/java/br/com/caelum/vraptor/http/route/PathAnnotationRoutesParser.java#L259 Thanks for the feedback @garcia-jj |
As I said, I don't think that is a bug, but I need a way to change the final URI for all actions, in addition to the component is in production a long time, is unsafe change it. Indeed, I agree that the extractControllerNameFrom is not the proper way. I found other way to solve my issue, overriding the DefaultRouter#builderFor adding the prefix, because I need only add a prefix. Otherwise, I think that the any component of routes should provide easy customization, and the PathAnnotationRoutesParser design is not helping. Eg.:
These are just suggestions. Agree you that needs improve? Otherwise I think that we can close these issues. |
I think it's a bug. We just need to fix it. This PR solve the problem if accepted, but if not, we still need fix by another way. In my opinion of course. |
Sorry for the errors, I'm on cellphone. |
I'm waiting... As I said, I need for it to solve other PR. |
Let's wait for @lucascs @Turini @garcia-jj suggestions. 😃 |
This is the expected extension: @Specializes @ApplicationScoped
public class PrefixedRoutesParser extends PathAnnotationRoutesParser {
//delegate constructor
@Override
protected String[] getURIsFor(Method javaMethod, Class<?> type) {
String[] uris = super.getURIsFor(javaMethod, type);
for (int i = 0; i < uris.length; i++) {
uris[i] = "/prefix" + uris[i];
}
return uris;
}
} no need for extra code on VRaptor. You can also make the prefix depend on the controller and the method the way you like. This method works both for annotated and convention URIs. This and #676 should be closed. Does it make sense? Perhaps we should add a cookbook about it. |
Makes total sense @lucascs. Can I close ? |
Yes, please |
Closing. |
Thanks @lucascs |
Related to #673 and #676.
The problem occurs because when a method has
@Path
annotation, theextractControllerNameFrom
method fromPathAnnotationRoutesParser
class isn't called, so theextractControllerNameFrom
method overridden by the subclass isn't called either.I think I can did an ignorant solution, but maybe an idea.
I changed some asserts of the initial test from @dtelaroli based on
PathAnnotationRoutesParserTest
.