Search code examples
javajodd

Define Jodd Madvoc mappings from external file


I am using Jodd Madvoc web framework and define actions (classes and methods) using annotations. Everything works fine, but now I need to have these action definitions in an external file, so Madvoc don't need to scan my class path for the action classes (and for some other reasons).

I could probably code this by myself, since Madvoc is quite open for extension, but just wonder if there is already a way to do this?

Thank you!


Solution

  • What you are asking for is the so-called routing file. And the answer is: yes, Madvoc has support for routing files, since v3.6 (that was one of the new features, so thats maybe why you didn't know about it:). Anyway, all you have to do is to have a route file and use different configurator: RouteMadvocConfigurator instead of default one. This configurator reads routing file from the class path and defines the actions from it. You should be able to specify all action flags using routing file, including async flag, interceptors and so on. Nice thing about the routing file is that it's syntax is not so strict, so you can make your own format easily.

    Here is an example of routing file:

    `/hello.html` "jodd.madvoc.action.HelloAction#view"
    GET /helloWorld.html    jodd.madvoc.action.HelloAction#world
    /zigzag/${id}       jodd.madvoc.action.ArgsAction#zigzag    /zigzag
    

    As said, the format is loose, so you can e.g. define http method name everywhere you like in the line and so on.

    You can see more details in official documentation.