org.apache.wicket.core.request.handler.PageProvider Java Examples

The following examples show how to use org.apache.wicket.core.request.handler.PageProvider. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NextServerApplication.java    From nextreports-server with Apache License 2.0 6 votes vote down vote up
@Override
public IRequestHandler onException(RequestCycle cycle, Exception e) {
	if (e instanceof PageExpiredException) {
		LOG.error("Page expired", e); // !?
		return null; // see
						// getApplicationSettings().setPageExpiredErrorPage
	}

	if (e instanceof MaintenanceException) {
		return new RenderPageRequestHandler(new PageProvider(MaintenancePage.class));
	}

	if (e instanceof StalePageException) {
		return null;
	}

	String errorCode = String.valueOf(System.currentTimeMillis());
	LOG.error("Error with code " + errorCode, e);

	PageParameters parameters = new PageParameters();
	parameters.add("errorCode", errorCode);
	parameters.add("errorMessage", UrlEncoder.QUERY_INSTANCE.encode(e.getMessage(), HTTP.ISO_8859_1));
	return new RenderPageRequestHandler(new PageProvider(ErrorPage.class, parameters));
}
 
Example #2
Source File: RestartResponseAtInterceptPageException.java    From onedev with MIT License 5 votes vote down vote up
/**
 * Redirects to the specified {@code interceptPage}.
 * 
 * @param interceptPage
 */
public RestartResponseAtInterceptPageException(Page interceptPage)
{
	super(new RenderPageRequestHandler(new PageProvider(interceptPage),
		RedirectPolicy.AUTO_REDIRECT));
	InterceptData.set();
}
 
Example #3
Source File: RestartResponseAtInterceptPageException.java    From onedev with MIT License 5 votes vote down vote up
/**
 * Redirects to the specified intercept page, this will result in a bookmarkable redirect.
 * 
 * @param interceptPageClass
 * @param parameters
 */
public RestartResponseAtInterceptPageException(Class<? extends Page> interceptPageClass,
	PageParameters parameters)
{
	super(new RenderPageRequestHandler(new PageProvider(interceptPageClass, parameters),
		RedirectPolicy.ALWAYS_REDIRECT));
	InterceptData.set();
}
 
Example #4
Source File: OneWebApplication.java    From onedev with MIT License 5 votes vote down vote up
@Override
public final IProvider<IExceptionMapper> getExceptionMapperProvider() {
	return new IProvider<IExceptionMapper>() {

		@Override
		public IExceptionMapper get() {
			return new DefaultExceptionMapper() {

				@Override
				protected IRequestHandler mapExpectedExceptions(Exception e, Application application) {
					RequestCycle requestCycle = RequestCycle.get();
					boolean isAjax = ((WebRequest)requestCycle.getRequest()).isAjax();
					if (isAjax && (e instanceof ListenerInvocationNotAllowedException || e instanceof ComponentNotFoundException))
						return EmptyAjaxRequestHandler.getInstance();
					
					IRequestMapper mapper = Application.get().getRootRequestMapper();
					if (mapper.mapRequest(requestCycle.getRequest()) instanceof ResourceReferenceRequestHandler)
						return new ResourceErrorRequestHandler(e);
					
					HttpServletResponse response = (HttpServletResponse) requestCycle.getResponse().getContainerResponse();
					if (!response.isCommitted()) {
						InUseException inUseException = ExceptionUtils.find(e, InUseException.class);
						if (inUseException != null)
							return createPageRequestHandler(new PageProvider(new InUseErrorPage(inUseException)));
						else
							return createPageRequestHandler(new PageProvider(new GeneralErrorPage(e)));
					} else {
						return super.mapExpectedExceptions(e, application);
					}
				}
				
			};
		}
		
	};
}
 
Example #5
Source File: OrientDefaultExceptionsHandlingListener.java    From wicket-orientdb with Apache License 2.0 5 votes vote down vote up
@Override
public IRequestHandler onException(RequestCycle cycle, Exception ex) {
	try {
		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) {
				if(th instanceof OSecurityException) 
					OrientDbWebApplication.get().restartResponseAtSignInPage(); //Will throw exception
				return 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;
		}
	} catch (ReplaceHandlerException e) {
		return e.getReplacementRequestHandler();
	}
}
 
Example #6
Source File: ConsoleNotificationIndexPage.java    From artifact-listener with Apache License 2.0 5 votes vote down vote up
public ConsoleNotificationIndexPage(PageParameters parameters) {
	super(parameters);
	
	addHeadPageTitleKey("console.notifications");
	
	add(new ListView<PageProvider>("notifications", getNotificationPages()) {
		private static final long serialVersionUID = 1L;

		@SuppressWarnings("unchecked")
		@Override
		protected void populateItem(ListItem<PageProvider> item) {
			Class<? extends Page> pageClass = (Class<? extends Page>) item.getModelObject().getPageClass();
			Link<Void> link = new BookmarkablePageLink<Void>("link", pageClass);
			link.add(new Label("label", new ResourceModel("console.notifications." + pageClass.getSimpleName(), pageClass.getSimpleName())));
			item.add(link);
		}
	});
	
	add(new WebMarkupContainer("emptyList") {
		private static final long serialVersionUID = 6700720373087584498L;

		@Override
		public boolean isVisible() {
			return getNotificationPages().isEmpty();
		}
	});
}
 
Example #7
Source File: ConsoleNotificationIndexPage.java    From artifact-listener with Apache License 2.0 5 votes vote down vote up
private List<PageProvider> getNotificationPages() {
	return Lists.newArrayList(
			new PageProvider(ConfirmRegistrationHtmlNotificationDemoPage.class),
			new PageProvider(ResetPasswordHtmlNotificationDemoPage.class),
			new PageProvider(ConfirmEmailHtmlNotificationDemoPage.class),
			new PageProvider(DeleteEmailHtmlNotificationDemoPage.class),
			new PageProvider(NewVersionsHtmlNotificationDemoPage.class),
			new PageProvider(NewVersionsAdditionalEmailHtmlNotificationDemoPage.class)
	);
}
 
Example #8
Source File: GradebookNgApplication.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
@Override
public void init() {
	super.init();

	// page mounting for bookmarkable URLs
	mountPage("/grades", GradebookPage.class);
	mountPage("/settings", SettingsPage.class);
	mountPage("/importexport", ImportExportPage.class);
	mountPage("/permissions", PermissionsPage.class);
	mountPage("/gradebook", StudentPage.class);
	mountPage("/accessdenied", AccessDeniedPage.class);
	mountPage("/error", ErrorPage.class);

	// remove the version number from the URL so that browser refreshes re-render the page
	getRequestCycleSettings().setRenderStrategy(RenderStrategy.ONE_PASS_RENDER);

	// Configure for Spring injection
	getComponentInstantiationListeners().add(new SpringComponentInjector(this));

	// Add ResourceLoader that integrates with Sakai's Resource Loader
	getResourceSettings().getStringResourceLoaders().add(0, new GradebookNgStringResourceLoader());

	// Don't throw an exception if we are missing a property, just fallback
	getResourceSettings().setThrowExceptionOnMissingResource(false);

	// Remove the wicket specific tags from the generated markup
	getMarkupSettings().setStripWicketTags(true);

	// Don't add any extra tags around a disabled link (default is <em></em>)
	getMarkupSettings().setDefaultBeforeDisabledLink(null);
	getMarkupSettings().setDefaultAfterDisabledLink(null);

	// On Wicket session timeout, redirect to main page
	// getApplicationSettings().setPageExpiredErrorPage(getHomePage());

	// Intercept any unexpected error stacktrace and take to our page
	getRequestCycleListeners().add(new AbstractRequestCycleListener() {
		@Override
		public IRequestHandler onException(final RequestCycle cycle, final Exception e) {
			return new RenderPageRequestHandler(new PageProvider(new ErrorPage(e)));
		}
	});

	// Disable Wicket's loading of jQuery - we load Sakai's preferred version in BasePage.java
	getJavaScriptLibrarySettings().setJQueryReference(new PackageResourceReference(GradebookNgApplication.class, "empty.js"));

	// cleanup the HTML
	getMarkupSettings().setStripWicketTags(true);
	getMarkupSettings().setStripComments(true);
	getMarkupSettings().setCompressWhitespace(true);
}
 
Example #9
Source File: SyncopeUIRequestCycleListener.java    From syncope with Apache License 2.0 4 votes vote down vote up
@Override
public IRequestHandler onException(final RequestCycle cycle, final Exception e) {
    LOG.error("Exception found", e);

    PageParameters errorParameters = new PageParameters();

    IRequestablePage errorPage;
    if (instanceOf(e, UnauthorizedInstantiationException.class) != null) {
        errorParameters.add("errorMessage", BaseSession.Error.AUTHORIZATION.fallback());
        errorPage = getErrorPage(errorParameters);
    } else if (instanceOf(e, AccessControlException.class) != null) {
        if (StringUtils.containsIgnoreCase(instanceOf(e, AccessControlException.class).getMessage(), "expired")) {
            errorParameters.add("errorMessage", BaseSession.Error.SESSION_EXPIRED.fallback());
        } else {
            errorParameters.add("errorMessage", BaseSession.Error.AUTHORIZATION.fallback());
        }
        errorPage = getErrorPage(errorParameters);
    } else if (instanceOf(e, PageExpiredException.class) != null || !isSignedIn()) {
        errorParameters.add("errorMessage", BaseSession.Error.SESSION_EXPIRED.fallback());
        errorPage = getErrorPage(errorParameters);
    } else if (instanceOf(e, BadRequestException.class) != null
            || instanceOf(e, WebServiceException.class) != null
            || instanceOf(e, SyncopeClientException.class) != null) {

        errorParameters.add("errorMessage", BaseSession.Error.REST.fallback());
        errorPage = getErrorPage(errorParameters);
    } else {
        Throwable cause = instanceOf(e, ForbiddenException.class);
        if (cause == null) {
            // redirect to default Wicket error page
            errorPage = new ExceptionErrorPage(e, null);
        } else {
            errorParameters.add("errorMessage", cause.getMessage());
            errorPage = getErrorPage(errorParameters);
        }
    }

    if (errorPage instanceof BaseLogin) {
        try {
            invalidateSession();
        } catch (Throwable t) {
            // ignore
            LOG.debug("Unexpected error while forcing logout after error", t);
        }
    }

    return new RenderPageRequestHandler(new PageProvider(errorPage));
}
 
Example #10
Source File: GradebookNgApplication.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
@Override
public void init() {
	super.init();

	// page mounting for bookmarkable URLs
	mountPage("/grades", GradebookPage.class);
	mountPage("/settings", SettingsPage.class);
	mountPage("/importexport", ImportExportPage.class);
	mountPage("/permissions", PermissionsPage.class);
	mountPage("/gradebook", StudentPage.class);
	mountPage("/accessdenied", AccessDeniedPage.class);
	mountPage("/error", ErrorPage.class);

	// remove the version number from the URL so that browser refreshes re-render the page
	getRequestCycleSettings().setRenderStrategy(RenderStrategy.ONE_PASS_RENDER);

	// Configure for Spring injection
	getComponentInstantiationListeners().add(new SpringComponentInjector(this));

	// Add ResourceLoader that integrates with Sakai's Resource Loader
	getResourceSettings().getStringResourceLoaders().add(0, new GradebookNgStringResourceLoader());

	// Don't throw an exception if we are missing a property, just fallback
	getResourceSettings().setThrowExceptionOnMissingResource(false);

	// Remove the wicket specific tags from the generated markup
	getMarkupSettings().setStripWicketTags(true);

	// Don't add any extra tags around a disabled link (default is <em></em>)
	getMarkupSettings().setDefaultBeforeDisabledLink(null);
	getMarkupSettings().setDefaultAfterDisabledLink(null);

	// On Wicket session timeout, redirect to main page
	// getApplicationSettings().setPageExpiredErrorPage(getHomePage());

	// Intercept any unexpected error stacktrace and take to our page
	getRequestCycleListeners().add(new AbstractRequestCycleListener() {
		@Override
		public IRequestHandler onException(final RequestCycle cycle, final Exception e) {
			return new RenderPageRequestHandler(new PageProvider(new ErrorPage(e)));
		}
	});

	// Disable Wicket's loading of jQuery - we load Sakai's preferred version in BasePage.java
	getJavaScriptLibrarySettings().setJQueryReference(new PackageResourceReference(GradebookNgApplication.class, "empty.js"));

	// cleanup the HTML
	getMarkupSettings().setStripWicketTags(true);
	getMarkupSettings().setStripComments(true);
	getMarkupSettings().setCompressWhitespace(true);
}
 
Example #11
Source File: PageParameterAwareMountedMapper.java    From projectforge-webapp with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected IRequestHandler processHybrid(PageInfo pageInfo, Class< ? extends IRequestablePage> pageClass, PageParameters pageParameters,
    Integer renderCount)
{
  IRequestHandler handler = null;
  try {
    handler = super.processHybrid(pageInfo, pageClass, pageParameters, renderCount);
  } catch (PageExpiredException e) {
    // in case of pageExpiredException at this point, we just redirect to previous bookmarkable resource
    return processBookmarkable(pageClass, pageParameters);
  }
  if (handler != null && handler instanceof RenderPageRequestHandler) {
    // in the current implementation (wicket 1.5.6) super.processHybrid
    // returns a RenderPageRequestHandler
    RenderPageRequestHandler renderPageHandler = (RenderPageRequestHandler) handler;
    if (renderPageHandler.getPageProvider() instanceof PageProvider) {
      PageProvider provider = (PageProvider) renderPageHandler.getPageProvider();
      // This check is necessary to prevent a RestartResponseAtInterceptPageException at the wrong time in request cycle
      if (provider.hasPageInstance()) {
        // get page classes
        Class< ? extends IRequestablePage> oldPageClass = renderPageHandler.getPageClass();
        Class< ? extends IRequestablePage> newPageClass = renderPageHandler.getPageProvider().getPageClass();

        // get page parameters
        PageParameters newPageParameters = renderPageHandler.getPageParameters();
        PageParameters oldPageParameters = renderPageHandler.getPageProvider().getPageInstance().getPageParameters();

        if (oldPageClass != null && oldPageClass.equals(newPageClass) == false) {
          return processBookmarkable(newPageClass, newPageParameters);
        }

        // if we recognize a change between the page parameter of the loaded
        // page and the page parameter of the current request, we redirect
        // to a fresh bookmarkable instance of that page.
        if (!PageParameters.equals(oldPageParameters, newPageParameters)) {
          return processBookmarkable(newPageClass, newPageParameters);
        }
      }
    }
  }
  return handler;
}