Skip to content
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

[FR] MVC Add method meta data to route #2629

Closed
agentgt opened this issue Sep 15, 2022 · 2 comments
Closed

[FR] MVC Add method meta data to route #2629

agentgt opened this issue Sep 15, 2022 · 2 comments

Comments

@agentgt
Copy link
Contributor

agentgt commented Sep 15, 2022

For 3.0 it would be very helpful if the Route had more metadata for MVC handlers. For example which class and method is the handler. Currently the MVC annotation processor does add the path as well annotation metadata but it would be helpful if it added:

  • Class name
  • Method name
  • Method parameters

The idea for are use case is in dev mode (or not) you could print that information out for diagnostic purposes. e.g. perhaps a meta tag on the page that says what view and controller rendered it. (the view is easy and doable today but the other meta data like class is not)

In other frameworks this information is available because they are using reflection and give you the the java reflect Method that handled the request. We do not want to do that but should give enough information to effectively get the Method (or MethodHandle) if one desires so. That is static strings like how annotations are added to the route should be enough I think.

I can put in a PR in 3.0 if you are interested?

@jknack
Copy link
Member

jknack commented Sep 15, 2022

Does it add value? I don't think so. Also, if we do it for mvc, we need to same on lambda routes... which isn't as easy as MVC.

@agentgt
Copy link
Contributor Author

agentgt commented Sep 15, 2022

Does it add value? I don't think so.

It is exceptionally valuable for us as it was easily possibly in Spring and others. Look at the bottom of this Javascript library's web page.

https://demo.unpoly.com/

It shows the name of the controller and view. That isn't easily available in Jooby.

I had to do lots of things to port our existing metrics and logging to jooby. I had to use the route path which is often not clear at all where that path's controller is.

It is valuable for:

  • Metrics
  • Diagnostics
  • AOP programming
  • Logging

Even if the parameters are not there this would still be valuable:

route.attribute("io.jooby.controller.class", Controller.class);
route.attribute("io.jooby.controller.method.name", "getSomething");

Also, if we do it for mvc, we need to same on lambda routes...

Annotations are not really supported on lambdas either. I think it's fine that isn't available on lambdas. Lambdas can wire whatever name they want manually since they have the route.

In MVC there is way no way to edit aka post process the route after it is created.

I suppose if you don't want to modify the route attributes you could provide an SPI such that you call:

public interface MVCRouteProcessor {
    public void processRoute(Route route, Class<?> controller, String methodName, String.... parameterNames, paramtersTypes... etc);

}

Then call the above from the generated code... I'm kidding the above is disgusting.

Please just add the Controller Class<?> (not the synthetic one) and method name to the attributes should be good enough.

Of course you could add setMvcMethodName and setMvcControllerClass on the Route itself but that seems pretty nasty as well.

@jknack jknack added this to the 3.0.0.M8 milestone May 21, 2023
@jknack jknack closed this as completed in ed1aca2 May 21, 2023
@jknack jknack added the router label May 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants