Search in sources :

Example 1 with AbstractRequestCycleListener

use of org.apache.wicket.request.cycle.AbstractRequestCycleListener in project webanno by webanno.

the class CasStorageServiceImpl method getCache.

private Map<JCasCacheKey, JCasCacheEntry> getCache() {
    RequestCycle requestCycle = RequestCycle.get();
    Map<JCasCacheKey, JCasCacheEntry> cache = requestCycle.getMetaData(CACHE);
    if (cache == null) {
        cache = new HashMap<>();
        requestCycle.setMetaData(CACHE, cache);
        requestCycle.getListeners().add(new AbstractRequestCycleListener() {

            @Override
            public void onEndRequest(RequestCycle aCycle) {
                Map<JCasCacheKey, JCasCacheEntry> _cache = aCycle.getMetaData(CACHE);
                if (_cache != null) {
                    for (Entry<JCasCacheKey, JCasCacheEntry> entry : _cache.entrySet()) {
                        log.debug("{} - reads: {}  writes: {}", entry.getKey(), entry.getValue().reads, entry.getValue().writes);
                    }
                }
            }
        });
    }
    return cache;
}
Also used : Entry(java.util.Map.Entry) RequestCycle(org.apache.wicket.request.cycle.RequestCycle) AbstractRequestCycleListener(org.apache.wicket.request.cycle.AbstractRequestCycleListener) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with AbstractRequestCycleListener

use of org.apache.wicket.request.cycle.AbstractRequestCycleListener in project hale by halestudio.

the class BaseWebApplication method init.

@Override
public void init() {
    super.init();
    BootstrapSettings settings = new BootstrapSettings();
    final ThemeProvider themeProvider = new BootswatchThemeProvider() {

        {
            add(new MetroTheme());
            add(new GoogleTheme());
            add(new WicketTheme());
            add(new Bootstrap3Theme());
            defaultTheme("bootstrap-responsive");
        // defaultTheme("bootstrap");
        }
    };
    settings.setThemeProvider(themeProvider);
    Bootstrap.install(this, settings);
    BootstrapLess.install(this);
    configureResourceBundles();
    IPackageResourceGuard packageResourceGuard = getResourceSettings().getPackageResourceGuard();
    if (packageResourceGuard instanceof SecurePackageResourceGuard) {
        SecurePackageResourceGuard guard = (SecurePackageResourceGuard) packageResourceGuard;
        guard.addPattern("+org/apache/wicket/resource/jquery/*.map");
    }
    // enforce mounts so security interceptors based on URLs can't be fooled
    getSecuritySettings().setEnforceMounts(true);
    getSecuritySettings().setAuthorizationStrategy(new SimplePageAuthorizationStrategy(SecuredPage.class, getLoginPageClass()) {

        @Override
        protected boolean isAuthorized() {
            SecurityContext securityContext = SecurityContextHolder.getContext();
            if (securityContext != null) {
                Authentication authentication = securityContext.getAuthentication();
                if (authentication != null && authentication.isAuthenticated()) {
                    for (GrantedAuthority authority : authentication.getAuthorities()) {
                        if (authority.getAuthority().equals(UserConstants.ROLE_USER) || authority.getAuthority().equals(UserConstants.ROLE_ADMIN)) {
                            // allow access only for users/admins
                            return true;
                        }
                    }
                }
            }
            return false;
        }
    });
    getComponentInstantiationListeners().add(new SpringComponentInjector(this));
    getRequestCycleListeners().add(new AbstractRequestCycleListener() {

        @Override
        public IRequestHandler onException(RequestCycle cycle, Exception ex) {
            return new RenderPageRequestHandler(new PageProvider(new ExceptionPage(ex)));
        }
    });
    // add login page to every application based on this one (if enabled)
    Class<? extends BasePage> loginClass = getLoginPageClass();
    if (loginClass != null) {
        // login page
        mountPage("/login", loginClass);
        // user settings
        mountPage("/settings", UserSettingsPage.class);
        // about
        mountPage("/about", AboutPage.class);
        // contact
        mountPage("/contact", ContactPage.class);
        if (OpenIdLoginPage.class.equals(loginClass)) {
            // for OpenID auth also add page for new users
            mountPage("/new", NewUserPage.class);
        }
    }
}
Also used : WicketTheme(de.agilecoders.wicket.themes.markup.html.wicket.WicketTheme) IRequestHandler(org.apache.wicket.request.IRequestHandler) RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) GoogleTheme(de.agilecoders.wicket.themes.markup.html.google.GoogleTheme) RequestCycle(org.apache.wicket.request.cycle.RequestCycle) GrantedAuthority(org.springframework.security.core.GrantedAuthority) SimplePageAuthorizationStrategy(org.apache.wicket.authorization.strategies.page.SimplePageAuthorizationStrategy) MetroTheme(de.agilecoders.wicket.themes.markup.html.metro.MetroTheme) Bootstrap3Theme(de.agilecoders.wicket.themes.markup.html.bootstrap3.Bootstrap3Theme) BootstrapSettings(de.agilecoders.wicket.core.settings.BootstrapSettings) IPackageResourceGuard(org.apache.wicket.markup.html.IPackageResourceGuard) SecurePackageResourceGuard(org.apache.wicket.markup.html.SecurePackageResourceGuard) Authentication(org.springframework.security.core.Authentication) PageProvider(org.apache.wicket.core.request.handler.PageProvider) AbstractRequestCycleListener(org.apache.wicket.request.cycle.AbstractRequestCycleListener) SecurityContext(org.springframework.security.core.context.SecurityContext) ExceptionPage(eu.esdihumboldt.hale.server.webapp.pages.ExceptionPage) SecuredPage(eu.esdihumboldt.hale.server.webapp.pages.SecuredPage) BootswatchThemeProvider(de.agilecoders.wicket.themes.settings.BootswatchThemeProvider) SpringComponentInjector(org.apache.wicket.spring.injection.annot.SpringComponentInjector) BootswatchThemeProvider(de.agilecoders.wicket.themes.settings.BootswatchThemeProvider) ThemeProvider(de.agilecoders.wicket.core.settings.ThemeProvider)

Example 3 with AbstractRequestCycleListener

use of org.apache.wicket.request.cycle.AbstractRequestCycleListener in project qi4j-sdk by Qi4j.

the class WicketQi4jApplication method handleUnitOfWork.

private void handleUnitOfWork() {
    getRequestCycleListeners().add(new AbstractRequestCycleListener() {

        @Override
        public void onBeginRequest(final RequestCycle requestCycle) {
            super.onBeginRequest(requestCycle);
            logger.debug("================================");
            logger.debug("REQUEST start");
            logger.debug(requestCycle.getRequest().toString());
            logger.debug(requestCycle.getRequest().getRequestParameters().toString());
            UnitOfWork uow = uowf.newUnitOfWork(UsecaseBuilder.newUsecase("REQUEST"));
            logger.debug("  ### NEW " + uow + "   ### MODULE: " + qi4jModule);
        }

        @Override
        public void onEndRequest(final RequestCycle requestCycle) {
            UnitOfWork uow = uowf.currentUnitOfWork();
            if (uow != null) {
                try {
                    if ("POST".equals(((HttpServletRequest) requestCycle.getRequest().getContainerRequest()).getMethod())) {
                        // "Save"
                        logger.debug("  ### COMPLETE " + uow + "   ### MODULE: " + qi4jModule);
                        uow.complete();
                    } else {
                        // GET requests
                        logger.debug("  ### DISCARD " + uow + "   ### MODULE: " + qi4jModule);
                        uow.discard();
                    }
                } catch (ConcurrentEntityModificationException e) {
                    logger.error("  ### DISCARD " + uow + "   ### MODULE: " + qi4jModule);
                    uow.discard();
                    e.printStackTrace();
                } catch (UnitOfWorkCompletionException e) {
                    logger.error("  ### DISCARD " + uow + "   ### MODULE: " + qi4jModule);
                    uow.discard();
                    e.printStackTrace();
                }
            }
            logger.debug("REQUEST end");
            logger.debug("------------------------------------");
        }
    });
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) ConcurrentEntityModificationException(org.qi4j.api.unitofwork.ConcurrentEntityModificationException) UnitOfWorkCompletionException(org.qi4j.api.unitofwork.UnitOfWorkCompletionException) RequestCycle(org.apache.wicket.request.cycle.RequestCycle) AbstractRequestCycleListener(org.apache.wicket.request.cycle.AbstractRequestCycleListener)

Example 4 with AbstractRequestCycleListener

use of org.apache.wicket.request.cycle.AbstractRequestCycleListener in project qi4j-sdk by Qi4j.

the class WicketQi4jApplication method handleUnitOfWork.

private void handleUnitOfWork() {
    getRequestCycleListeners().add(new AbstractRequestCycleListener() {

        @Override
        public void onBeginRequest(final RequestCycle requestCycle) {
            super.onBeginRequest(requestCycle);
            logger.debug("================================");
            logger.debug("REQUEST start");
            logger.debug(requestCycle.getRequest().toString());
            logger.debug(requestCycle.getRequest().getRequestParameters().toString());
            UnitOfWork uow = uowf.newUnitOfWork(UsecaseBuilder.newUsecase("REQUEST"));
            logger.debug("  ### NEW " + uow + "   ### MODULE: " + qi4jModule);
        }

        @Override
        public void onEndRequest(final RequestCycle requestCycle) {
            UnitOfWork uow = uowf.currentUnitOfWork();
            if (uow != null) {
                try {
                    if ("POST".equals(((HttpServletRequest) requestCycle.getRequest().getContainerRequest()).getMethod())) {
                        // "Save"
                        logger.debug("  ### COMPLETE " + uow + "   ### MODULE: " + qi4jModule);
                        uow.complete();
                    } else {
                        // GET requests
                        logger.debug("  ### DISCARD " + uow + "   ### MODULE: " + qi4jModule);
                        uow.discard();
                    }
                } catch (ConcurrentEntityModificationException e) {
                    logger.error("  ### DISCARD " + uow + "   ### MODULE: " + qi4jModule);
                    uow.discard();
                    e.printStackTrace();
                } catch (UnitOfWorkCompletionException e) {
                    logger.error("  ### DISCARD " + uow + "   ### MODULE: " + qi4jModule);
                    uow.discard();
                    e.printStackTrace();
                }
            }
            logger.debug("REQUEST end");
            logger.debug("------------------------------------");
        }
    });
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) ConcurrentEntityModificationException(org.qi4j.api.unitofwork.ConcurrentEntityModificationException) UnitOfWorkCompletionException(org.qi4j.api.unitofwork.UnitOfWorkCompletionException) RequestCycle(org.apache.wicket.request.cycle.RequestCycle) AbstractRequestCycleListener(org.apache.wicket.request.cycle.AbstractRequestCycleListener)

Aggregations

AbstractRequestCycleListener (org.apache.wicket.request.cycle.AbstractRequestCycleListener)4 RequestCycle (org.apache.wicket.request.cycle.RequestCycle)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 ConcurrentEntityModificationException (org.qi4j.api.unitofwork.ConcurrentEntityModificationException)2 UnitOfWork (org.qi4j.api.unitofwork.UnitOfWork)2 UnitOfWorkCompletionException (org.qi4j.api.unitofwork.UnitOfWorkCompletionException)2 BootstrapSettings (de.agilecoders.wicket.core.settings.BootstrapSettings)1 ThemeProvider (de.agilecoders.wicket.core.settings.ThemeProvider)1 Bootstrap3Theme (de.agilecoders.wicket.themes.markup.html.bootstrap3.Bootstrap3Theme)1 GoogleTheme (de.agilecoders.wicket.themes.markup.html.google.GoogleTheme)1 MetroTheme (de.agilecoders.wicket.themes.markup.html.metro.MetroTheme)1 WicketTheme (de.agilecoders.wicket.themes.markup.html.wicket.WicketTheme)1 BootswatchThemeProvider (de.agilecoders.wicket.themes.settings.BootswatchThemeProvider)1 ExceptionPage (eu.esdihumboldt.hale.server.webapp.pages.ExceptionPage)1 SecuredPage (eu.esdihumboldt.hale.server.webapp.pages.SecuredPage)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 SimplePageAuthorizationStrategy (org.apache.wicket.authorization.strategies.page.SimplePageAuthorizationStrategy)1 PageProvider (org.apache.wicket.core.request.handler.PageProvider)1