org.apache.wicket.protocol.http.PageExpiredException Java Examples

The following examples show how to use org.apache.wicket.protocol.http.PageExpiredException. 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: CoreModule.java    From onedev with MIT License 4 votes vote down vote up
private void configureWeb() {
	bind(WicketServlet.class).to(DefaultWicketServlet.class);
	bind(WicketFilter.class).to(DefaultWicketFilter.class);
	bind(WebSocketPolicy.class).toProvider(WebSocketPolicyProvider.class);
	bind(EditSupportRegistry.class).to(DefaultEditSupportRegistry.class);
	bind(WebSocketManager.class).to(DefaultWebSocketManager.class);

	bind(AttachmentUploadServlet.class);
	
	contributeFromPackage(EditSupport.class, EditSupport.class);
	
	bind(WebApplication.class).to(OneWebApplication.class);
	bind(Application.class).to(OneWebApplication.class);
	bind(AvatarManager.class).to(DefaultAvatarManager.class);
	bind(WebSocketManager.class).to(DefaultWebSocketManager.class);
	
	contributeFromPackage(EditSupport.class, EditSupportLocator.class);
	
	contribute(WebApplicationConfigurator.class, new WebApplicationConfigurator() {
		
		@Override
		public void configure(WebApplication application) {
			application.mount(new OnePageMapper("/test", TestPage.class));
		}
		
	});
	
	bind(CommitIndexedBroadcaster.class);
	
	contributeFromPackage(DiffRenderer.class, DiffRenderer.class);
	contributeFromPackage(BlobRendererContribution.class, BlobRendererContribution.class);

	contribute(Extension.class, new EmojiExtension());
	contribute(Extension.class, new SourcePositionTrackExtension());
	
	contributeFromPackage(MarkdownProcessor.class, MarkdownProcessor.class);

	contribute(ResourcePackScopeContribution.class, new ResourcePackScopeContribution() {
		
		@Override
		public Collection<Class<?>> getResourcePackScopes() {
			return Lists.newArrayList(OneWebApplication.class);
		}
		
	});
	contribute(ExpectedExceptionContribution.class, new ExpectedExceptionContribution() {
		
		@SuppressWarnings("unchecked")
		@Override
		public Collection<Class<? extends Exception>> getExpectedExceptionClasses() {
			return Sets.newHashSet(ConstraintViolationException.class, EntityNotFoundException.class, 
					ObjectNotFoundException.class, StaleStateException.class, UnauthorizedException.class, 
					OneException.class, PageExpiredException.class, StalePageException.class);
		}
		
	});

	bind(UrlManager.class).to(DefaultUrlManager.class);
	bind(CodeCommentEventBroadcaster.class);
	bind(PullRequestEventBroadcaster.class);
	bind(IssueEventBroadcaster.class);
	bind(BuildEventBroadcaster.class);
	
	bind(TaskButton.TaskFutureManager.class);
	
	bind(UICustomization.class).toInstance(new UICustomization() {
		
		@Override
		public Class<? extends BasePage> getHomePage() {
			return DashboardPage.class;
		}
		
		@Override
		public List<MainTab> getMainTabs() {
			return Lists.newArrayList(
					new ProjectListTab(), new IssueListTab(), 
					new PullRequestListTab(), new BuildListTab());
		}

	});
}
 
Example #3
Source File: OntopolyRequestCycle.java    From ontopia with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public Page onRuntimeException(Page page, RuntimeException e) {
  
  Map<String,TopicMap> tms = topicmaps.get();
  if (tms != null && !tms.isEmpty()) {
    Iterator<TopicMap> iter = tms.values().iterator();
    while (iter.hasNext()) {
      TopicMap topicmap = iter.next();
      TopicMapIF tm = topicmap.getTopicMapIF();
      TopicMapStoreIF store = tm.getStore();
      try {
        store.abort();
      } catch (Exception ex) {
        log.error("Problems occured while aborting transaction", ex);
      } finally {
        store.close();
      }
    }
  }
  if (tms != null) {
    tms.clear();
  }
  
  Throwable cause = e;
  if (cause instanceof WicketRuntimeException) 
  cause = cause.getCause(); 
  if (cause instanceof InvocationTargetException) 
  cause = cause.getCause();
  if (e instanceof PageExpiredException) {

    String referer = ((WebRequest)this.getRequest()).getHttpServletRequest().getHeader("Referer");
    if (referer != null) {
      Pattern pattern = Pattern.compile("ontopoly.pages.\\w*");
      Matcher matcher = pattern.matcher(referer);
      String pageName = "";
      if (matcher.find())
        pageName = matcher.group();
      
      pattern = Pattern.compile("&([^&]*)=([^&]*)");
      matcher = pattern.matcher(referer);
      
      Map<String,String> pageParametersMap = new HashMap<String,String>();
      while (matcher.find())
        pageParametersMap.put(matcher.group(1), matcher.group(2));
      
      Class<? extends Page> classObjectForPage = null;
      try {
        classObjectForPage = (Class<? extends Page>)Class.forName(pageName);
      }
      catch(ClassNotFoundException cnfe) {
        //! System.out.println("Couldn't find a class with the name: "+pageName);
      }        
      return new PageExpiredErrorPage(classObjectForPage, new PageParameters(pageParametersMap));
    }
  }
  if (cause instanceof Exception) {
    return new InternalErrorPageWithException(page, e);
  }
  return super.onRuntimeException(page, e);
}
 
Example #4
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 #5
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;
}
 
Example #6
Source File: ErrorPage.java    From projectforge-webapp with GNU General Public License v3.0 4 votes vote down vote up
public ErrorPage(final Throwable throwable)
{
  super(null);
  errorMessage = getString("errorpage.unknownError");
  messageNumber = null;
  Throwable rootCause = null;
  showFeedback = true;
  if (throwable != null) {
    rootCause = ExceptionHelper.getRootCause(throwable);
    if (rootCause instanceof ProjectForgeException) {
      errorMessage = getExceptionMessage(this, (ProjectForgeException) rootCause, true);
    } else if (throwable instanceof ServletException) {
      messageNumber = String.valueOf(System.currentTimeMillis());
      log.error("Message #" + messageNumber + ": " + throwable.getMessage(), throwable);
      if (rootCause != null) {
        log.error("Message #" + messageNumber + " rootCause: " + rootCause.getMessage(), rootCause);
      }
      errorMessage = getLocalizedMessage(UserException.I18N_KEY_PLEASE_CONTACT_DEVELOPER_TEAM, messageNumber);
    } else if (throwable instanceof PageExpiredException) {
      log.info("Page expired (session time out).");
      showFeedback = false;
      errorMessage = getString("message.wicket.pageExpired");
      title = getString("message.title");
    } else {
      messageNumber = String.valueOf(System.currentTimeMillis());
      log.error("Message #" + messageNumber + ": " + throwable.getMessage(), throwable);
      errorMessage = getLocalizedMessage(UserException.I18N_KEY_PLEASE_CONTACT_DEVELOPER_TEAM, messageNumber);
    }
  }
  form = new ErrorForm(this);
  final String receiver = Configuration.getInstance().getStringValue(ConfigurationParam.FEEDBACK_E_MAIL);
  form.data.setReceiver(receiver);
  form.data.setMessageNumber(messageNumber);
  form.data.setMessage(throwable != null ? throwable.getMessage() : "");
  form.data.setStackTrace(throwable != null ? ExceptionHelper.printStackTrace(throwable) : "");
  form.data.setSender(PFUserContext.getUser().getFullname());
  final String subject = "ProjectForge-Error #" + form.data.getMessageNumber() + " from " + form.data.getSender();
  form.data.setSubject(subject);
  if (rootCause != null) {
    form.data.setRootCause(rootCause.getMessage());
    form.data.setRootCauseStackTrace(ExceptionHelper.printStackTrace(rootCause));
  }
  final boolean visible = showFeedback == true && messageNumber != null && StringUtils.isNotBlank(receiver);
  body.add(form);
  if (visible == true) {
    form.init();
  }
  form.setVisible(visible);
  final Label errorMessageLabel = new Label("errorMessage", errorMessage);
  body.add(errorMessageLabel.setVisible(errorMessage != null));
  final FeedbackPanel feedbackPanel = new FeedbackPanel("feedback");
  feedbackPanel.setOutputMarkupId(true);
  body.add(feedbackPanel);
}