From: James Moger Date: Tue, 30 Sep 2014 12:01:39 +0000 (-0400) Subject: Bypass Wicket redirects after AJAX form submissions, they break Tomcat X-Git-Tag: v1.6.1~19^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2598bf3ff526f46259244d7c5f60dcc2241f3020;p=gitblit.git Bypass Wicket redirects after AJAX form submissions, they break Tomcat --- diff --git a/src/main/java/com/gitblit/wicket/pages/BasePage.java b/src/main/java/com/gitblit/wicket/pages/BasePage.java index b454b7a8..03d19184 100644 --- a/src/main/java/com/gitblit/wicket/pages/BasePage.java +++ b/src/main/java/com/gitblit/wicket/pages/BasePage.java @@ -45,6 +45,7 @@ import org.apache.wicket.markup.html.panel.FeedbackPanel; import org.apache.wicket.protocol.http.RequestUtils; import org.apache.wicket.protocol.http.WebResponse; import org.apache.wicket.protocol.http.servlet.ServletWebRequest; +import org.apache.wicket.request.target.basic.RedirectRequestTarget; import org.apache.wicket.util.time.Duration; import org.apache.wicket.util.time.Time; import org.slf4j.Logger; @@ -112,6 +113,15 @@ public abstract class BasePage extends SessionPage { return canonicalUrl; } + protected void manualRedirect(Class pageClass) { + redirect(pageClass, null); + } + + protected void redirect(Class pageClass, PageParameters parameters) { + String absoluteUrl = getCanonicalUrl(pageClass, parameters); + getRequestCycle().setRequestTarget(new RedirectRequestTarget(absoluteUrl)); + } + protected String getLanguageCode() { return GitBlitWebSession.get().getLocale().getLanguage(); } @@ -495,4 +505,5 @@ public abstract class BasePage extends SessionPage { } return sb.toString(); } + } diff --git a/src/main/java/com/gitblit/wicket/pages/EditMilestonePage.java b/src/main/java/com/gitblit/wicket/pages/EditMilestonePage.java index 4ed77d83..801631e8 100644 --- a/src/main/java/com/gitblit/wicket/pages/EditMilestonePage.java +++ b/src/main/java/com/gitblit/wicket/pages/EditMilestonePage.java @@ -143,7 +143,7 @@ public class EditMilestonePage extends RepositoryPage { } if (success && app().tickets().updateMilestone(getRepositoryModel(), tm, createdBy)) { - setResponsePage(TicketsPage.class, WicketUtils.newOpenTicketsParameter(repositoryName)); + redirect(TicketsPage.class, WicketUtils.newOpenTicketsParameter(repositoryName)); } else { // TODO error } diff --git a/src/main/java/com/gitblit/wicket/pages/EditTicketPage.java b/src/main/java/com/gitblit/wicket/pages/EditTicketPage.java index 074ffa60..b55ce9c3 100644 --- a/src/main/java/com/gitblit/wicket/pages/EditTicketPage.java +++ b/src/main/java/com/gitblit/wicket/pages/EditTicketPage.java @@ -331,13 +331,13 @@ public class EditTicketPage extends RepositoryPage { if (ticket != null) { TicketNotifier notifier = app().tickets().createNotifier(); notifier.sendMailing(ticket); - setResponsePage(TicketsPage.class, WicketUtils.newObjectParameter(getRepositoryModel().name, "" + ticket.number)); + redirect(TicketsPage.class, WicketUtils.newObjectParameter(getRepositoryModel().name, "" + ticket.number)); } else { // TODO error } } else { // nothing to change?! - setResponsePage(TicketsPage.class, WicketUtils.newObjectParameter(getRepositoryModel().name, "" + ticket.number)); + redirect(TicketsPage.class, WicketUtils.newObjectParameter(getRepositoryModel().name, "" + ticket.number)); } } }); diff --git a/src/main/java/com/gitblit/wicket/pages/NewMilestonePage.java b/src/main/java/com/gitblit/wicket/pages/NewMilestonePage.java index cc331903..24a43120 100644 --- a/src/main/java/com/gitblit/wicket/pages/NewMilestonePage.java +++ b/src/main/java/com/gitblit/wicket/pages/NewMilestonePage.java @@ -108,7 +108,7 @@ public class NewMilestonePage extends RepositoryPage { if (milestone != null) { milestone.due = due; app().tickets().updateMilestone(getRepositoryModel(), milestone, createdBy); - throw new RestartResponseException(TicketsPage.class, WicketUtils.newOpenTicketsParameter(repositoryName)); + redirect(TicketsPage.class, WicketUtils.newOpenTicketsParameter(repositoryName)); } else { // TODO error } diff --git a/src/main/java/com/gitblit/wicket/pages/NewTicketPage.java b/src/main/java/com/gitblit/wicket/pages/NewTicketPage.java index e6d9cb1e..f80a7d7e 100644 --- a/src/main/java/com/gitblit/wicket/pages/NewTicketPage.java +++ b/src/main/java/com/gitblit/wicket/pages/NewTicketPage.java @@ -222,7 +222,8 @@ public class NewTicketPage extends RepositoryPage { if (ticket != null) { TicketNotifier notifier = app().tickets().createNotifier(); notifier.sendMailing(ticket); - setResponsePage(TicketsPage.class, WicketUtils.newObjectParameter(getRepositoryModel().name, "" + ticket.number)); + + redirect(TicketsPage.class, WicketUtils.newObjectParameter(getRepositoryModel().name, "" + ticket.number)); } else { // TODO error } diff --git a/src/main/java/com/gitblit/wicket/pages/RootPage.java b/src/main/java/com/gitblit/wicket/pages/RootPage.java index 6a933b76..15e4304d 100644 --- a/src/main/java/com/gitblit/wicket/pages/RootPage.java +++ b/src/main/java/com/gitblit/wicket/pages/RootPage.java @@ -280,12 +280,12 @@ public abstract class RootPage extends BasePage { PageParameters params = getPageParameters(); if (params == null) { // redirect to this page - setResponsePage(getClass()); + manualRedirect(getClass()); } else { // Strip username and password and redirect to this page params.remove("username"); params.remove("password"); - setResponsePage(getClass(), params); + redirect(getClass(), params); } } }