Announcement Announcement Module
No announcement yet.
Interest in annotation-based Web Scripts? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Interest in annotation-based Web Scripts?

    I've been experimenting with extending the Web Script framework with the capability to configure Web Scripts solely through Java annotations, similar to how Spring MVC request mapping. (This is actually part of a larger effort to bring dynamic, OSGi-based extensions to the Alfresco platform, but the Web Script extensions are broken off into a separate project with no Alfresco or OSGi API dependencies.)

    My question is: would there be interest in making annotations a proper part of the Web Scripts framework?

    Simple example Web Script

    As you can gather from the source, the configuration that you'd normally put in a desc.xml is captured in corresponding Java annotations. The @WebScript annotation actually causes the framework to pick up the Web Script automatically through classpath component scanning, so this is all you need to get the Web Script running.

    Like Spring MVC, request and URI variables can be specified through method argument annotations. Furthermore, method arguments are resolved against the Web Script API where appropriate. So, for example, if you'd have an argument of type org.springframework.extensions.webscripts.Match, the framework would resolve its value using a call to WebScriptRequest.getServiceMatch().

    Finally, method return values could be transformed to the appropriate HTTP response. For instance, an int return value would indicate the HTTP status code. Likewise, you could reuse the HttpMessageConverter logic to do away with writing a response manually or using a response template. (Note that the example above doesn't illustrate this, and the actual logic to achieve this still needs to be written, but this capability can be integrated quite easily.)

    The overall goal would be to make creating Java-based REST API's WebScripts easier. As a Java developer, I'm not particularly interested in using server-side JavaScript or Freemarker templates when I have Spring MVC and the REST framework at my disposal. I know you can derive from AbstractWebScript and map a Web Script descriptor to a Spring bean, but this still feels like too much work.

    SVN links: