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;
}
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);
}
}
}
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("------------------------------------");
}
});
}
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("------------------------------------");
}
});
}
Aggregations