Search in sources :

Example 1 with ActionsManager

use of jodd.madvoc.component.ActionsManager 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 ActionsManager

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

the class ManualRegistrationTest method testManualAction.

@Test
public void testManualAction() {
    Madvoc madvoc = new Madvoc();
    madvoc.setMadvocConfiguratorClass(ManualRegistration.class);
    madvoc.startNewWebApplication(null);
    ActionsManager actionsManager = madvoc.getWebApplication().getComponent(ActionsManager.class);
    assertEquals(2, actionsManager.getActionsCount());
    ActionConfig actionConfig = actionsManager.lookup("/hello", "GET");
    assertNotNull(actionConfig);
    assertEquals(BooAction.class, actionConfig.getActionClass());
    assertEquals("foo1", actionConfig.actionClassMethod.getName());
    actionConfig = actionsManager.lookup("/world", "GET");
    assertNotNull(actionConfig);
    assertEquals(BooAction.class, actionConfig.getActionClass());
    assertEquals("foo2", actionConfig.actionClassMethod.getName());
}
Also used : ActionsManager(jodd.madvoc.component.ActionsManager) Test(org.junit.Test)

Example 3 with ActionsManager

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

the class ActionMethodParserTest method testMacrosDups.

@Test
void testMacrosDups() {
    WebApp webapp = new WebApp();
    webapp.start();
    ActionsManager actionsManager = webapp.madvocContainer().lookupComponent(ActionsManager.class);
    webapp.madvocContainer().lookupComponent(RootPackages.class).addRootPackageOf(this.getClass());
    actionsManager.setPathMacroClass(RegExpPathMacros.class);
    actionsManager.registerAction(ReAction.class, "duplo2", null);
    actionsManager.registerAction(ReAction.class, "duplo1", null);
    ActionRuntime cfg = actionsManager.lookup("GET", MadvocUtil.splitPathToChunks("/re/duplo/123"));
    assertNotNull(cfg);
    assertEquals(ReAction.class, cfg.getActionClass());
    assertEquals("/re/duplo/{id:^[0-9]+}", cfg.getActionPath());
    RouteChunk chunk = cfg.getRouteChunk();
    assertEquals(1, chunk.pathMacros().macrosCount());
    assertEquals("id", chunk.pathMacros().names()[0]);
    cfg = actionsManager.lookup("GET", MadvocUtil.splitPathToChunks("/re/duplo/aaa"));
    assertNotNull(cfg);
    assertEquals(ReAction.class, cfg.getActionClass());
    assertEquals("/re/duplo/{sid}", cfg.getActionPath());
    chunk = cfg.getRouteChunk();
    assertEquals(1, chunk.pathMacros().macrosCount());
    assertEquals("sid", chunk.pathMacros().names()[0]);
    assertEquals(2, actionsManager.getActionsCount());
}
Also used : ActionsManager(jodd.madvoc.component.ActionsManager) RootPackages(jodd.madvoc.component.RootPackages) ActionRuntime(jodd.madvoc.config.ActionRuntime) RouteChunk(jodd.madvoc.config.RouteChunk) Test(org.junit.jupiter.api.Test)

Example 4 with ActionsManager

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

the class ActionMethodParserTest method testZqq.

@Test
void testZqq() {
    WebApp webapp = new WebApp();
    webapp.start();
    ActionsManager actionsManager = webapp.madvocContainer().lookupComponent(ActionsManager.class);
    RootPackages rootPackages = webapp.madvocContainer().lookupComponent(RootPackages.class);
    rootPackages.addRootPackageOf(this.getClass());
    actionsManager.registerAction(ReAction.class, "zqq1", null);
    actionsManager.registerAction(ReAction.class, "zqq2", null);
    ActionRuntime cfg = actionsManager.lookup("GET", MadvocUtil.splitPathToChunks("/config/dba.delete_multi.do"));
    assertNotNull(cfg);
    assertEquals("/{entityName}/dba.delete_multi.do", cfg.getActionPath());
}
Also used : ActionsManager(jodd.madvoc.component.ActionsManager) RootPackages(jodd.madvoc.component.RootPackages) ActionRuntime(jodd.madvoc.config.ActionRuntime) Test(org.junit.jupiter.api.Test)

Example 5 with ActionsManager

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

the class ActionResultTest method testAlias.

@Test
void testAlias() {
    WebApp webapp = new WebApp();
    webapp.start();
    ActionsManager actionsManager = webapp.madvocContainer().lookupComponent(ActionsManager.class);
    actionsManager.registerAction(BooAction.class, "foo5", null);
    actionsManager.registerPathAlias("ok", "xxx.jsp");
    actionsManager.registerPathAlias("sok", "zzz");
    ResultMapper resultMapper = webapp.madvocContainer().lookupComponent(ResultMapper.class);
    String path = "/boo.foo.html";
    ResultPath resultPath = resultMapper.resolveResultPath(path, "/<ok>?foo=1");
    assertEquals("/xxx.jsp?foo=1", resultPath.pathValue());
    resultPath = resultMapper.resolveResultPath(path, "<sok>");
    assertEquals("/boo.foo.html.zzz", resultPath.pathValue());
    resultPath = resultMapper.resolveResultPath(path, "#<sok>");
    assertEquals("/boo.foo.zzz", resultPath.pathValue());
    resultPath = resultMapper.resolveResultPath(path, "<dude>?foo=1");
    assertEquals("/xxx.html?foo=1", resultPath.pathValue());
}
Also used : ActionsManager(jodd.madvoc.component.ActionsManager) ResultMapper(jodd.madvoc.component.ResultMapper) ResultPath(jodd.madvoc.config.ResultPath) Test(org.junit.jupiter.api.Test)

Aggregations

ActionsManager (jodd.madvoc.component.ActionsManager)13 Test (org.junit.jupiter.api.Test)10 ActionRuntime (jodd.madvoc.config.ActionRuntime)9 RootPackages (jodd.madvoc.component.RootPackages)4 RouteChunk (jodd.madvoc.config.RouteChunk)3 ActionMethodParser (jodd.madvoc.component.ActionMethodParser)2 ResultMapper (jodd.madvoc.component.ResultMapper)2 Map (java.util.Map)1 FiltersManager (jodd.madvoc.component.FiltersManager)1 InterceptorsManager (jodd.madvoc.component.InterceptorsManager)1 MadvocConfig (jodd.madvoc.component.MadvocConfig)1 MadvocController (jodd.madvoc.component.MadvocController)1 ResultsManager (jodd.madvoc.component.ResultsManager)1 AutomagicMadvocConfigurator (jodd.madvoc.config.AutomagicMadvocConfigurator)1 MadvocConfigurator (jodd.madvoc.config.MadvocConfigurator)1 ResultPath (jodd.madvoc.config.ResultPath)1 BooAction (jodd.madvoc.fixtures.tst.BooAction)1 EchoInterceptor (jodd.madvoc.interceptor.EchoInterceptor)1 ProxettaAwareActionsManager (jodd.madvoc.proxetta.ProxettaAwareActionsManager)1 Props (jodd.props.Props)1