Search in sources :

Example 1 with MadvocController

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

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

the class ServletDispatcherResultTest method createActionRequest.

protected ActionRequest createActionRequest(String actionPath) {
    HttpServletRequest servletRequest = mock(HttpServletRequest.class);
    HttpServletResponse servletResponse = mock(HttpServletResponse.class);
    HttpSession httpSession = mock(HttpSession.class);
    ServletContext servletContext = mock(ServletContext.class);
    when(servletRequest.getSession()).thenReturn(httpSession);
    when(httpSession.getServletContext()).thenReturn(servletContext);
    MadvocController madvocController = new MadvocController();
    Object action = new Object();
    ActionRuntime actionRuntime = new ActionRuntime(null, Action.class, ClassUtil.findMethod(Action.class, "view"), null, null, new ActionDefinition(actionPath, "GET"), ServletDispatcherActionResult.class, null, false, false, null, null);
    return new ActionRequest(madvocController, actionRuntime.getActionPath(), MadvocUtil.splitPathToChunks(actionRuntime.getActionPath()), actionRuntime, action, servletRequest, servletResponse);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MadvocController(jodd.madvoc.component.MadvocController) ActionRequest(jodd.madvoc.ActionRequest) HttpSession(javax.servlet.http.HttpSession) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletContext(javax.servlet.ServletContext) ActionRuntime(jodd.madvoc.config.ActionRuntime) ActionDefinition(jodd.madvoc.config.ActionDefinition)

Example 3 with MadvocController

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

the class MadvocServletFilter method init.

/**
 * Filter initialization.
 */
@Override
public void init(final FilterConfig filterConfig) throws ServletException {
    final ServletContext servletContext = filterConfig.getServletContext();
    madvoc = Madvoc.get(servletContext);
    if (madvoc != null) {
        log = LoggerFactory.getLogger(this.getClass());
        madvocController = madvoc.webapp().madvocContainer().requestComponent(MadvocController.class);
        return;
    }
    final WebApp webApp = WebApp.get(servletContext);
    if (webApp != null) {
        log = LoggerFactory.getLogger(this.getClass());
        madvocController = webApp.madvocContainer().requestComponent(MadvocController.class);
        return;
    }
    throw new ServletException("Neither Madvoc or WebApp found! Use MadvocContextListener to create Madvoc or " + "WebApp#withServletContext() to make it available.");
}
Also used : ServletException(javax.servlet.ServletException) MadvocController(jodd.madvoc.component.MadvocController) ServletContext(javax.servlet.ServletContext)

Aggregations

MadvocController (jodd.madvoc.component.MadvocController)3 ServletContext (javax.servlet.ServletContext)2 ServletException (javax.servlet.ServletException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 HttpSession (javax.servlet.http.HttpSession)1 ActionRequest (jodd.madvoc.ActionRequest)1 ActionsManager (jodd.madvoc.component.ActionsManager)1 FiltersManager (jodd.madvoc.component.FiltersManager)1 InterceptorsManager (jodd.madvoc.component.InterceptorsManager)1 MadvocConfig (jodd.madvoc.component.MadvocConfig)1 ResultsManager (jodd.madvoc.component.ResultsManager)1 ActionDefinition (jodd.madvoc.config.ActionDefinition)1 ActionRuntime (jodd.madvoc.config.ActionRuntime)1 AutomagicMadvocConfigurator (jodd.madvoc.config.AutomagicMadvocConfigurator)1 MadvocConfigurator (jodd.madvoc.config.MadvocConfigurator)1 Props (jodd.props.Props)1