Search in sources :

Example 1 with MadvocConfig

use of jodd.madvoc.component.MadvocConfig in project jodd by oblac.

the class Madvoc method start.

private void start(ServletContext servletContext) {
    if (servletContext != null) {
        this.servletContext = servletContext;
        servletContext.setAttribute(MADVOC_ATTR, this);
    }
    // create and initialize web application
    webapp = createWebApplication();
    webapp.initWebApplication();
    // init logger
    log = LoggerFactory.getLogger(Madvoc.class);
    log.info("Madvoc starting...");
    if (webapp.getClass().equals(WebApplication.class)) {
        log.info("Default Madvoc web application created.");
    } else {
        log.info("Madvoc web application: " + webAppClass.getName());
    }
    // params
    if (paramsFiles != null) {
        Props params = loadMadvocParams(paramsFiles);
        webapp.defineParams(params);
    }
    // configure
    webapp.registerMadvocComponents();
    madvocConfig = webapp.getComponent(MadvocConfig.class);
    if (madvocConfig == null) {
        throw new MadvocException("Madvoc configuration not found");
    }
    webapp.init(madvocConfig, servletContext);
    // filters
    FiltersManager filtersManager = webapp.getComponent(FiltersManager.class);
    if (filtersManager == null) {
        throw new MadvocException("Madvoc filers manager not found");
    }
    webapp.initFilters(filtersManager);
    // interceptors
    InterceptorsManager interceptorsManager = webapp.getComponent(InterceptorsManager.class);
    if (interceptorsManager == null) {
        throw new MadvocException("Madvoc interceptors manager not found");
    }
    webapp.initInterceptors(interceptorsManager);
    // actions
    ActionsManager actionsManager = webapp.getComponent(ActionsManager.class);
    if (actionsManager == null) {
        throw new MadvocException("Madvoc actions manager not found");
    }
    webapp.initActions(actionsManager);
    // results
    ResultsManager resultsManager = webapp.getComponent(ResultsManager.class);
    if (resultsManager == null) {
        throw new MadvocException("Madvoc results manager not found");
    }
    webapp.initResults(resultsManager);
    // configure with external configurator
    MadvocConfigurator configurator = loadMadvocConfig();
    webapp.configure(configurator);
    // prepare web application
    madvocController = webapp.getComponent(MadvocController.class);
    if (madvocController == null) {
        throw new MadvocException("Madvoc controller not found");
    }
    madvocController.init(servletContext);
    // web app is ready
    webapp.ready();
}
Also used : ActionsManager(jodd.madvoc.component.ActionsManager) ResultsManager(jodd.madvoc.component.ResultsManager) FiltersManager(jodd.madvoc.component.FiltersManager) MadvocController(jodd.madvoc.component.MadvocController) InterceptorsManager(jodd.madvoc.component.InterceptorsManager) MadvocConfigurator(jodd.madvoc.config.MadvocConfigurator) AutomagicMadvocConfigurator(jodd.madvoc.config.AutomagicMadvocConfigurator) Props(jodd.props.Props) MadvocConfig(jodd.madvoc.component.MadvocConfig)

Example 2 with MadvocConfig

use of jodd.madvoc.component.MadvocConfig in project jodd by oblac.

the class ActionMethodParserTest method testMacrosDups.

@Test
public void testMacrosDups() {
    WebApplication webapp = new WebApplication(true);
    webapp.registerMadvocComponents();
    ActionsManager actionsManager = webapp.getComponent(ActionsManager.class);
    MadvocConfig madvocConfig = webapp.getComponent(MadvocConfig.class);
    madvocConfig.getRootPackages().addRootPackageOf(this.getClass());
    madvocConfig.setPathMacroClass(RegExpPathMacros.class);
    actionsManager.register(ReAction.class, "duplo1");
    actionsManager.register(ReAction.class, "duplo2");
    ActionConfig cfg = actionsManager.lookup("/re/duplo/123", "GET");
    assertNotNull(cfg);
    ActionConfigSet set = cfg.getActionConfigSet();
    assertEquals(ReAction.class, cfg.actionClass);
    assertEquals("/re/duplo/${id:^[0-9]+}", cfg.actionPath);
    assertEquals(3, set.deep);
    assertEquals(1, set.actionPathMacros.getMacrosCount());
    assertEquals("id", set.actionPathMacros.getNames()[0]);
    cfg = actionsManager.lookup("/re/duplo/aaa", "GET");
    assertNotNull(cfg);
    set = cfg.getActionConfigSet();
    assertEquals(ReAction.class, cfg.actionClass);
    assertEquals("/re/duplo/${sid}", cfg.actionPath);
    assertEquals(3, set.deep);
    assertEquals(1, set.actionPathMacros.getMacrosCount());
    assertEquals("sid", set.actionPathMacros.getNames()[0]);
    assertEquals(2, actionsManager.getActionsCount());
}
Also used : ActionsManager(jodd.madvoc.component.ActionsManager) MadvocConfig(jodd.madvoc.component.MadvocConfig) Test(org.junit.Test)

Example 3 with MadvocConfig

use of jodd.madvoc.component.MadvocConfig in project jodd by oblac.

the class ActionMethodParserTest method testMethodWithPackage.

@Test
public void testMethodWithPackage() {
    WebApplication webapp = new WebApplication(true);
    webapp.registerMadvocComponents();
    ActionMethodParser actionMethodParser = webapp.getComponent(ActionMethodParser.class);
    MadvocConfig madvocConfig = webapp.getComponent(MadvocConfig.class);
    madvocConfig.getRootPackages().addRootPackageOf(this.getClass());
    ActionConfig cfg = parse(actionMethodParser, "tst.BooAction#foo");
    assertNotNull(cfg);
    assertEquals(BooAction.class, cfg.actionClass);
    assertEquals("/tst/boo.foo.html", cfg.actionPath);
    cfg = parse(actionMethodParser, "tst.BooAction#foo1");
    assertEquals("/tst/boo.xxx.html", cfg.actionPath);
    cfg = parse(actionMethodParser, "tst.BooAction#foo2");
    assertEquals("/tst/boo.foo2.xxx", cfg.actionPath);
    cfg = parse(actionMethodParser, "tst.BooAction#foo3");
    assertEquals("/tst/boo.html", cfg.actionPath);
    cfg = parse(actionMethodParser, "tst.BooAction#foo4");
    assertEquals("/xxx", cfg.actionPath);
    assertNull(cfg.actionMethod);
    cfg = parse(actionMethodParser, "tst.BooAction#foo41");
    assertEquals("/xxx", cfg.actionPath);
    assertEquals("DELETE", cfg.actionMethod);
    cfg = parse(actionMethodParser, "tst.BooAction#foo5");
    assertEquals("/xxx.html", cfg.actionPath);
    assertEquals("POST", cfg.actionMethod);
    cfg = parse(actionMethodParser, "tst.BooAction#foo6");
    assertEquals("/tst/boo.qfoo62.html", cfg.actionPath);
    cfg = parse(actionMethodParser, "tst.BooAction#foo7");
    assertEquals("/foo7.html", cfg.actionPath);
}
Also used : MadvocConfig(jodd.madvoc.component.MadvocConfig) ActionMethodParser(jodd.madvoc.component.ActionMethodParser) Test(org.junit.Test)

Example 4 with MadvocConfig

use of jodd.madvoc.component.MadvocConfig in project jodd by oblac.

the class ActionMethodParserTest method testEndSlashClassName.

@Test
public void testEndSlashClassName() {
    WebApplication webapp = new WebApplication(true);
    webapp.registerMadvocComponents();
    ActionMethodParser actionMethodParser = webapp.getComponent(ActionMethodParser.class);
    MadvocConfig madvocConfig = webapp.getComponent(MadvocConfig.class);
    madvocConfig.getRootPackages().addRootPackageOf(this.getClass());
    ActionConfig cfg = parse(actionMethodParser, "tst2.ReAction#hello");
    assertNotNull(cfg);
    assertEquals(ReAction.class, cfg.actionClass);
    assertEquals("/re/hello.html", cfg.actionPath);
    cfg = parse(actionMethodParser, "tst2.ReAction#macro");
    assertNotNull(cfg);
    assertEquals(ReAction.class, cfg.actionClass);
    assertEquals("/re/user/${id}/macro.html", cfg.actionPath);
}
Also used : MadvocConfig(jodd.madvoc.component.MadvocConfig) ActionMethodParser(jodd.madvoc.component.ActionMethodParser) Test(org.junit.Test)

Example 5 with MadvocConfig

use of jodd.madvoc.component.MadvocConfig in project jodd by oblac.

the class ActionMethodParserTest method testPackage.

@Test
public void testPackage() {
    WebApplication webapp = new WebApplication(true);
    webapp.registerMadvocComponents();
    ActionMethodParser actionMethodParser = webapp.getComponent(ActionMethodParser.class);
    MadvocConfig madvocConfig = webapp.getComponent(MadvocConfig.class);
    madvocConfig.getRootPackages().addRootPackageOf(this.getClass());
    ActionConfig cfg = parse(actionMethodParser, "tst2.Boo4Action#foo");
    assertNotNull(cfg);
    assertEquals(Boo4Action.class, cfg.actionClass);
    assertEquals("/ttt/www.foo.html", cfg.actionPath);
    cfg = parse(actionMethodParser, "tst2.Boo4Action#foo1");
    assertEquals("/ttt/www.xxx.html", cfg.actionPath);
    cfg = parse(actionMethodParser, "tst2.Boo4Action#foo2");
    assertEquals("/ttt/www.foo2.xxx", cfg.actionPath);
    cfg = parse(actionMethodParser, "tst2.Boo4Action#foo3");
    assertEquals("/ttt/www.html", cfg.actionPath);
}
Also used : MadvocConfig(jodd.madvoc.component.MadvocConfig) ActionMethodParser(jodd.madvoc.component.ActionMethodParser) Test(org.junit.Test)

Aggregations

MadvocConfig (jodd.madvoc.component.MadvocConfig)14 Test (org.junit.Test)13 ActionMethodParser (jodd.madvoc.component.ActionMethodParser)7 ActionsManager (jodd.madvoc.component.ActionsManager)5 WebApplication (jodd.madvoc.WebApplication)1 FiltersManager (jodd.madvoc.component.FiltersManager)1 InterceptorsManager (jodd.madvoc.component.InterceptorsManager)1 MadvocController (jodd.madvoc.component.MadvocController)1 ResultMapper (jodd.madvoc.component.ResultMapper)1 ResultsManager (jodd.madvoc.component.ResultsManager)1 AutomagicMadvocConfigurator (jodd.madvoc.config.AutomagicMadvocConfigurator)1 MadvocConfigurator (jodd.madvoc.config.MadvocConfigurator)1 PetiteContainer (jodd.petite.PetiteContainer)1 Props (jodd.props.Props)1