Example usage for org.apache.wicket.protocol.http WebApplication setServletContext

List of usage examples for org.apache.wicket.protocol.http WebApplication setServletContext

Introduction

In this page you can find the example usage for org.apache.wicket.protocol.http WebApplication setServletContext.

Prototype

public void setServletContext(ServletContext servletContext) 

Source Link

Document

Sets servlet context this application runs after.

Usage

From source file:com.mastfrog.acteur.wicket.WicketApplicationInitializer.java

License:Open Source License

protected void init(Application application) throws NoSuchFieldException, IllegalArgumentException,
        IllegalAccessException, NoSuchMethodException, InvocationTargetException {
    WebApplication wa = (WebApplication) application;
    wa.setWicketFilter(filter);//from   w  w  w. j  a v  a 2  s  . co  m
    wa.setServletContext(ctx);
    wa.setSessionStoreProvider(this);
    ThreadContext.setApplication(application);
    application.setName(application.getClass().getName());
    application.initApplication();
    wa.setSessionStoreProvider(this);
    Field field = Application.class.getDeclaredField("pageFactory");
    field.setAccessible(true);
    field.set(application, factory);
    Method logStarted = WebApplication.class.getDeclaredMethod("logStarted");
    logStarted.setAccessible(true);
    logStarted.invoke(application);
}

From source file:org.apache.openmeetings.db.util.ApplicationHelper.java

License:Apache License

public static IApplication ensureApplication(Long langId) {
    IApplication a = null;/*from   www. j av  a2 s.com*/
    if (Application.exists()) {
        a = (IApplication) Application.get();
    } else {
        WebApplication app = (WebApplication) Application.get(wicketApplicationName);
        LabelDao.initLanguageMap();
        if (app == null) {
            try {
                app = (WebApplication) LabelDao.getAppClass().newInstance();
            } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
                log.error("Failed to create Application");
                return null;
            }
            app.setServletContext(new MockServletContext(app, null));
            app.setName(wicketApplicationName);
            ServletContext sc = app.getServletContext();
            OMContextListener omcl = new OMContextListener();
            omcl.contextInitialized(new ServletContextEvent(sc));
            XmlWebApplicationContext xmlContext = new XmlWebApplicationContext();
            xmlContext.setConfigLocation("classpath:openmeetings-applicationContext.xml");
            xmlContext.setServletContext(sc);
            xmlContext.refresh();
            sc.setAttribute(ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, xmlContext);
            app.setConfigurationType(RuntimeConfigurationType.DEPLOYMENT);
            ThreadContext.setApplication(app);
            app.initApplication();
        } else {
            ThreadContext.setApplication(app);
        }
        a = (IApplication) Application.get(wicketApplicationName);
    }
    if (ThreadContext.getRequestCycle() == null) {
        ServletWebRequest req = new ServletWebRequest(new MockHttpServletRequest((Application) a,
                new MockHttpSession(a.getServletContext()), a.getServletContext()), "");
        RequestCycleContext rctx = new RequestCycleContext(req, new MockWebResponse(), a.getRootRequestMapper(),
                a.getExceptionMapperProvider().get());
        ThreadContext.setRequestCycle(new RequestCycle(rctx));
    }
    if (ThreadContext.getSession() == null) {
        WebSession s = WebSession.get();
        if (langId > 0) {
            ((IWebSession) s).setLanguage(langId);
        }
    }
    return a;
}