Getting started - Vuzi/jwf GitHub Wiki
Required libraries
- commons-fileupload-1.3.1 : handling of file upload and multi-part forms
- commons-io-2.4 : used by the previous library
- jackson-all-1.9.9 : handling the configuration file
- velocity-1.7 : HTML templating
- velocity-1.7-dep : used by the previous library
And that's everything !
Workflow
Please this the workflow page : https://github.com/Vuzi/jwf/wiki/Workflow
Getting stated
Configuration file
The JSON configuration file is used to define elements that would usually not needs a recompilation of the server to be changed. Almost every element loaded from the file can be retrieve with the "Configuration" singleton object.
Classes to create
The only class you'll need to create is a FrontController. A front controller, which already extends the HttpServlet class, will handle every HTTP request send to the server. Be careful, after the initialization phase everything must be thread safe.
Your class must extends the abstract class AFrontController from the package fr.vuzi.webframework.controller which provides a lot of useful functions, in top of the previously mentioned workflow.
You'll need to override at least tree function to make everything works:
- getRootDirectory: This methods is used by the server to know where to find the configuration file and the main "WEB-INF" directory used by tomcat.
- initRenderers : This methods initializes the renderers used by the server. Those renderers should be added to the main renderer. By now only a JSON (RendererJSON) and Velocity renderer (RendererVelocity) are provided.
Your method will usually looks like this :
@Override
protected void initRenderers() {
// -- JSON renderer --
renderer.addRenderer("json", new RendererJSON());
// -- Velocity renderer --
renderer.addRenderer("velocity", new RendererVelocity(dispatcher));
// -- Default type : JSON --
renderer.setDefaultType("json");
}
- initRewriterRules : This method is used by the server to know all the endpoints of your server, and which action is linked to which endpoint. All the rewrite rules must be added to the rewriter engine. You'll certainly want to use the "Configuration.URIroot" value to match the start of your site's URI.
Your method will usually looks like this :
@Override
protected void initRewriterRules() {
// Login
rewriter.addRule(new RewriteRule(Configuration.URIroot + "/api/login/?$", "GET|POST", "fr.vuzi.fileexplorer.api.action.ActionLogin"));
// Logout
rewriter.addRule(new RewriteRule(Configuration.URIroot + "/api/logout/?$", "GET|POST", "fr.vuzi.fileexplorer.api.action.ActionLogout"));
// [...]
}