use of org.apache.wicket.core.request.handler.PageProvider in project wicket by apache.
the class PageProviderTest method pageProviderDontDeserializeOnePageTwice.
/**
* <a href="https://issues.apache.org/jira/browse/WICKET-4046">WICKET-4046</a>
*/
@Test
public void pageProviderDontDeserializeOnePageTwice() {
int oldState = 0;
int newState = 1;
StatefullMockPage testPage = new StatefullMockPage();
testPage.state = oldState;
// storing test page
TestMapperContext mapperContext = new TestMapperContext();
mapperContext.getPageManager().touchPage(testPage);
mapperContext.getPageManager().commitRequest();
// by cleaning session cache we make sure of not being testing the same in-memory instance
mapperContext.cleanSessionCache();
PageProvider pageProvider = mapperContext.new TestPageProvider(testPage.getPageId(), 0);
// simulation an test call to isNewPageInstance
boolean isNewPageInstance = pageProvider.isNewPageInstance();
assertFalse("test page is already stored", isNewPageInstance);
// changing some sate
StatefullMockPage providedPage = (StatefullMockPage) pageProvider.getPageInstance();
providedPage.state = newState;
mapperContext.getPageManager().touchPage(providedPage);
mapperContext.getPageManager().commitRequest();
mapperContext.cleanSessionCache();
StatefullMockPage restauredPageAfterStateChage = (StatefullMockPage) mapperContext.getPageInstance(testPage.getPageId());
// OK, if the correct page got touched/stores its change will be visible now
assertEquals(newState, restauredPageAfterStateChage.state);
}
use of org.apache.wicket.core.request.handler.PageProvider in project wicket by apache.
the class PageProviderTest method testPageProperties_provided.
@Test
public void testPageProperties_provided() {
PageProvider provider = new PageProvider(new StatelessPageTest());
assertTrue(provider.hasPageInstance());
assertFalse(provider.doesProvideNewPage());
}
use of org.apache.wicket.core.request.handler.PageProvider in project wicket-orientdb by OrienteerBAP.
the class OrientDefaultExceptionsHandlingListener method onException.
@Override
public IRequestHandler onException(RequestCycle cycle, Exception ex) {
Throwable th = null;
if ((th = Exceptions.findCause(ex, OSecurityException.class)) != null || (th = Exceptions.findCause(ex, OValidationException.class)) != null || (th = Exceptions.findCause(ex, OSchemaException.class)) != null || (th = Exceptions.findCause(ex, IllegalStateException.class)) != null && Exceptions.findCause(ex, WicketRuntimeException.class) == null) {
Page page = extractCurrentPage(false);
if (page == null) {
return th instanceof OSecurityException ? new UnauthorizedInstantiationHandler(extractCurrentPage(true)) : null;
}
OrientDbWebSession.get().error(th.getMessage());
return new RenderPageRequestHandler(new PageProvider(page), RenderPageRequestHandler.RedirectPolicy.ALWAYS_REDIRECT);
} else if ((th = Exceptions.findCause(ex, UnauthorizedActionException.class)) != null) {
final UnauthorizedActionException unauthorizedActionException = (UnauthorizedActionException) th;
return new UnauthorizedInstantiationHandler(unauthorizedActionException.getComponent());
} else {
return null;
}
}
use of org.apache.wicket.core.request.handler.PageProvider in project wicket by apache.
the class PageInstanceMapper method mapRequest.
/**
* @see org.apache.wicket.request.IRequestMapper#mapRequest(org.apache.wicket.request.Request)
*/
@Override
public IRequestHandler mapRequest(Request request) {
if (matches(request)) {
Url url = request.getUrl();
PageComponentInfo info = getPageComponentInfo(url);
if (info != null && info.getPageInfo().getPageId() != null) {
Integer renderCount = info.getComponentInfo() != null ? info.getComponentInfo().getRenderCount() : null;
if (info.getComponentInfo() == null) {
PageProvider provider = new PageProvider(info.getPageInfo().getPageId(), renderCount);
provider.setPageSource(getContext());
// render page
return new RenderPageRequestHandler(provider);
} else {
ComponentInfo componentInfo = info.getComponentInfo();
PageAndComponentProvider provider = new PageAndComponentProvider(info.getPageInfo().getPageId(), renderCount, componentInfo.getComponentPath());
provider.setPageSource(getContext());
return new ListenerRequestHandler(provider, componentInfo.getBehaviorId());
}
}
}
return null;
}
use of org.apache.wicket.core.request.handler.PageProvider 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);
}
}
}
Aggregations