diff options
author | Martin Spielmann <martin.spielmann@pingunaut.com> | 2016-07-30 10:45:27 +0200 |
---|---|---|
committer | Martin Spielmann <martin.spielmann@pingunaut.com> | 2016-07-30 10:45:27 +0200 |
commit | f5bb095875d9062e9b121d86782baaa655709a49 (patch) | |
tree | 1e03be6a04e53d6561085ca5bbb5c9c8552cab60 /src | |
parent | 0c59f89e4f551575a8720510c4f8609e7b1facf5 (diff) | |
download | gitblit-f5bb095875d9062e9b121d86782baaa655709a49.tar.gz gitblit-f5bb095875d9062e9b121d86782baaa655709a49.zip |
replaced RequestUtils.toAbsolutePath() and RedirectRequestTarget
Diffstat (limited to 'src')
12 files changed, 52 insertions, 53 deletions
diff --git a/src/main/java/com/gitblit/utils/GitBlitRequestUtils.java b/src/main/java/com/gitblit/utils/GitBlitRequestUtils.java index 9a359310..7a7e5290 100644 --- a/src/main/java/com/gitblit/utils/GitBlitRequestUtils.java +++ b/src/main/java/com/gitblit/utils/GitBlitRequestUtils.java @@ -3,7 +3,10 @@ package com.gitblit.utils; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.apache.wicket.Page; +import org.apache.wicket.request.Url; import org.apache.wicket.request.cycle.RequestCycle; +import org.apache.wicket.request.mapper.parameter.PageParameters; public class GitBlitRequestUtils { public static HttpServletRequest getServletRequest(){ @@ -13,5 +16,10 @@ public class GitBlitRequestUtils { public static HttpServletResponse getServletResponse(){ return (HttpServletResponse)RequestCycle.get().getResponse().getContainerResponse(); } - + + public static String toAbsoluteUrl(Class<? extends Page> pageClass, PageParameters params){ + String relativeUrl = RequestCycle.get().urlFor(pageClass, params).toString(); + return RequestCycle.get().getUrlRenderer().renderFullUrl(Url.parse(relativeUrl)); + } } + diff --git a/src/main/java/com/gitblit/wicket/GitBlitWebSession.java b/src/main/java/com/gitblit/wicket/GitBlitWebSession.java index 8aa92d2f..0e53f315 100644 --- a/src/main/java/com/gitblit/wicket/GitBlitWebSession.java +++ b/src/main/java/com/gitblit/wicket/GitBlitWebSession.java @@ -34,6 +34,7 @@ import org.apache.wicket.protocol.http.request.WebClientInfo; import com.gitblit.GitBlitServer.Params;
import com.gitblit.models.UserModel;
+import com.gitblit.utils.GitBlitRequestUtils;
public final class GitBlitWebSession extends WebSession {
@@ -73,10 +74,8 @@ public final class GitBlitWebSession extends WebSession { params.getParameterNames().forEach(name->{
pageParams.add(name, params.getParameterValue(name));
});
- String relativeUrl = RequestCycle.get().urlFor(pageClass, pageParams).toString();
- requestUrl = RequestUtils.toAbsolutePath(relativeUrl);
-// String relativeUrl = RequestCycle.get().urlFor(pageClass, pageParams).toString();
-// requestUrl = RequestCycle.get().getUrlRenderer().renderFullUrl(Url.parse(relativeUrl));
+ requestUrl = GitBlitRequestUtils.toAbsoluteUrl(pageClass, pageParams);
+
if (isTemporary())
{
diff --git a/src/main/java/com/gitblit/wicket/GitblitRedirectException.java b/src/main/java/com/gitblit/wicket/GitblitRedirectException.java index 9eb76bfd..13e246a3 100644 --- a/src/main/java/com/gitblit/wicket/GitblitRedirectException.java +++ b/src/main/java/com/gitblit/wicket/GitblitRedirectException.java @@ -15,13 +15,13 @@ */ package com.gitblit.wicket; -//import org.apache.wicket.AbstractRestartResponseException; import org.apache.wicket.Page; import org.apache.wicket.RestartResponseException; -//import org.apache.wicket.request.cycle.RequestCycle; +import org.apache.wicket.request.cycle.RequestCycle; +import org.apache.wicket.request.http.handler.RedirectRequestHandler; import org.apache.wicket.request.mapper.parameter.PageParameters; -//import org.apache.wicket.protocol.http.RequestUtils; -//import org.apache.wicket.request.target.basic.RedirectRequestTarget; + +import com.gitblit.utils.GitBlitRequestUtils; /** * This exception bypasses the servlet container rewriting relative redirect @@ -42,10 +42,8 @@ public class GitblitRedirectException extends RestartResponseException { public <C extends Page> GitblitRedirectException(Class<C> pageClass, PageParameters params) { super(pageClass, params); -// RequestCycle cycle = RequestCycle.get(); -// String relativeUrl = cycle.urlFor(pageClass, params).toString(); -// String absoluteUrl = RequestUtils.toAbsolutePath(relativeUrl); -// cycle.setRequestTarget(new RedirectRequestTarget(absoluteUrl)); -// cycle.setRedirect(true); + RequestCycle cycle = RequestCycle.get(); + String absoluteUrl = GitBlitRequestUtils.toAbsoluteUrl(pageClass,params); + cycle.scheduleRequestHandlerAfterCurrent(new RedirectRequestHandler(absoluteUrl)); } } diff --git a/src/main/java/com/gitblit/wicket/GitblitWicketFilter.java b/src/main/java/com/gitblit/wicket/GitblitWicketFilter.java index 9ada7dc6..8286acfc 100644 --- a/src/main/java/com/gitblit/wicket/GitblitWicketFilter.java +++ b/src/main/java/com/gitblit/wicket/GitblitWicketFilter.java @@ -129,7 +129,7 @@ public class GitblitWicketFilter extends WicketFilter { repo = repo.replace("%2f", "/").replace("%2F", "/").replace(settings.getChar(Keys.web.forwardSlashCharacter, '/'), '/');
- GitBlitWebApp app = (GitBlitWebApp) getWebApplication();
+ GitBlitWebApp app = (GitBlitWebApp) getApplication();
int expires = settings.getInteger(Keys.web.pageCacheExpires, 0);
if (!StringUtils.isEmpty(page) && app.isCacheablePage(page) && expires > 0) {
// page can be cached by the browser
diff --git a/src/main/java/com/gitblit/wicket/SessionlessForm.java b/src/main/java/com/gitblit/wicket/SessionlessForm.java index 0d66ebe8..93a8d0fe 100644 --- a/src/main/java/com/gitblit/wicket/SessionlessForm.java +++ b/src/main/java/com/gitblit/wicket/SessionlessForm.java @@ -30,6 +30,7 @@ import org.apache.wicket.util.string.Strings; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.gitblit.utils.GitBlitRequestUtils; import com.gitblit.wicket.pages.BasePage; /** @@ -152,8 +153,6 @@ public class SessionlessForm<T> extends StatelessForm<T> { } protected String getAbsoluteUrl(Class<? extends BasePage> pageClass, PageParameters pageParameters) { - String relativeUrl = urlFor(pageClass, pageParameters).toString(); - String absoluteUrl = RequestUtils.toAbsolutePath(relativeUrl); - return absoluteUrl; + return GitBlitRequestUtils.toAbsoluteUrl(pageClass, pageParameters); } } diff --git a/src/main/java/com/gitblit/wicket/pages/BasePage.java b/src/main/java/com/gitblit/wicket/pages/BasePage.java index e858d5e1..1b44e875 100644 --- a/src/main/java/com/gitblit/wicket/pages/BasePage.java +++ b/src/main/java/com/gitblit/wicket/pages/BasePage.java @@ -38,6 +38,7 @@ import org.apache.wicket.Application; import org.apache.wicket.Page;
import org.apache.wicket.request.flow.RedirectToUrlException;
import org.apache.wicket.request.http.WebResponse;
+import org.apache.wicket.request.http.handler.RedirectRequestHandler;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.request.resource.CssPackageResource;
import org.apache.wicket.request.resource.JavaScriptResourceReference;
@@ -49,7 +50,6 @@ import org.apache.wicket.markup.html.resources.JavascriptResourceReference; import org.apache.wicket.markup.repeater.RepeatingView;
import org.apache.wicket.protocol.http.RequestUtils;
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;
@@ -113,9 +113,7 @@ public abstract class BasePage extends SessionPage { }
protected String getCanonicalUrl(Class<? extends BasePage> clazz, PageParameters params) {
- String relativeUrl = urlFor(clazz, params).toString();
- String canonicalUrl = RequestUtils.toAbsolutePath(relativeUrl);
- return canonicalUrl;
+ return GitBlitRequestUtils.toAbsoluteUrl(clazz, params);
}
protected void redirectTo(Class<? extends BasePage> pageClass) {
@@ -124,7 +122,7 @@ public abstract class BasePage extends SessionPage { protected void redirectTo(Class<? extends BasePage> pageClass, PageParameters parameters) {
String absoluteUrl = getCanonicalUrl(pageClass, parameters);
- getRequestCycle().setRequestTarget(new RedirectRequestTarget(absoluteUrl));
+ getRequestCycle().scheduleRequestHandlerAfterCurrent(new RedirectRequestHandler(absoluteUrl));
}
protected String getLanguageCode() {
@@ -230,7 +228,7 @@ public abstract class BasePage extends SessionPage { int expires = app().settings().getInteger(Keys.web.pageCacheExpires, 0);
WebResponse response = (WebResponse) getResponse();
response.setLastModifiedTime(Time.valueOf(when));
- response.setDateHeader("Expires", System.currentTimeMillis() + Duration.minutes(expires).getMilliseconds());
+ response.addHeader("Expires", String.valueOf(System.currentTimeMillis() + Duration.minutes(expires).getMilliseconds()));
}
protected String getPageTitle(String repositoryName) {
@@ -469,8 +467,7 @@ public abstract class BasePage extends SessionPage { }
if (toPage != null) {
GitBlitWebSession.get().cacheErrorMessage(message);
- String relativeUrl = urlFor(toPage, params).toString();
- String absoluteUrl = RequestUtils.toAbsolutePath(relativeUrl);
+ String absoluteUrl = GitBlitRequestUtils.toAbsoluteUrl(toPage, params);
throw new RedirectToUrlException(absoluteUrl);
} else {
super.error(message);
@@ -478,7 +475,7 @@ public abstract class BasePage extends SessionPage { }
public void authenticationError(String message) {
- logger().error(getRequest().getURL() + " for " + GitBlitWebSession.get().getUsername());
+ logger().error(getRequest().getUrl() + " for " + GitBlitWebSession.get().getUsername());
if (!GitBlitWebSession.get().isLoggedIn()) {
// cache the request if we have not authenticated.
// the request will continue after authentication.
diff --git a/src/main/java/com/gitblit/wicket/pages/ComparePage.java b/src/main/java/com/gitblit/wicket/pages/ComparePage.java index 2d1be64f..bbf866c0 100644 --- a/src/main/java/com/gitblit/wicket/pages/ComparePage.java +++ b/src/main/java/com/gitblit/wicket/pages/ComparePage.java @@ -19,6 +19,7 @@ import java.text.MessageFormat; import java.util.ArrayList; import java.util.List; +import org.apache.wicket.request.http.handler.RedirectRequestHandler; import org.apache.wicket.request.mapper.parameter.PageParameters; import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.html.form.CheckBox; @@ -33,7 +34,6 @@ import org.apache.wicket.markup.repeater.data.ListDataProvider; import org.apache.wicket.model.IModel; import org.apache.wicket.model.Model; import org.apache.wicket.protocol.http.RequestUtils; -//import org.apache.wicket.request.target.basic.RedirectRequestTarget; import org.eclipse.jgit.diff.DiffEntry.ChangeType; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.revwalk.RevCommit; @@ -45,6 +45,7 @@ import com.gitblit.models.RepositoryModel; import com.gitblit.models.SubmoduleModel; import com.gitblit.servlet.RawServlet; import com.gitblit.utils.DiffUtils; +import com.gitblit.utils.GitBlitRequestUtils; import com.gitblit.utils.DiffUtils.DiffComparator; import com.gitblit.utils.DiffUtils.DiffOutput; import com.gitblit.utils.DiffUtils.DiffOutputType; @@ -236,12 +237,11 @@ public class ComparePage extends RepositoryPage { PageParameters params = WicketUtils.newRangeParameter(repositoryName, from, to); if (ignoreWS) { - params.put("w", 1); + params.add("w", 1); } - String relativeUrl = urlFor(ComparePage.class, params).toString(); - String absoluteUrl = RequestUtils.toAbsolutePath(relativeUrl); - getRequestCycle().setRequestTarget(new RedirectRequestTarget(absoluteUrl)); + String absoluteUrl = GitBlitRequestUtils.toAbsoluteUrl(ComparePage.class, params); + getRequestCycle().scheduleRequestHandlerAfterCurrent(new RedirectRequestHandler(absoluteUrl)); } }; @@ -278,11 +278,10 @@ public class ComparePage extends RepositoryPage { PageParameters params = WicketUtils.newRangeParameter(repositoryName, from, to); if (ignoreWS) { - params.put("w", 1); + params.add("w", 1); } - String relativeUrl = urlFor(ComparePage.class, params).toString(); - String absoluteUrl = RequestUtils.toAbsolutePath(relativeUrl); - getRequestCycle().setRequestTarget(new RedirectRequestTarget(absoluteUrl)); + String absoluteUrl = GitBlitRequestUtils.toAbsoluteUrl(ComparePage.class, params); + getRequestCycle().scheduleRequestHandlerAfterCurrent(new RedirectRequestHandler(absoluteUrl)); } }; diff --git a/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java b/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java index d351bc70..dd8df4a3 100644 --- a/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java +++ b/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java @@ -28,6 +28,7 @@ import java.util.Set; import org.apache.wicket.AttributeModifier;
import org.apache.wicket.Component;
+import org.apache.wicket.request.http.handler.RedirectRequestHandler;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.RestartResponseException;
import org.apache.wicket.markup.html.basic.Label;
@@ -37,7 +38,6 @@ import org.apache.wicket.markup.html.link.ExternalLink; import org.apache.wicket.markup.html.panel.Fragment;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
-//import org.apache.wicket.request.target.basic.RedirectRequestTarget;
import org.eclipse.jgit.diff.DiffEntry.ChangeType;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.Repository;
@@ -63,6 +63,7 @@ import com.gitblit.servlet.SyndicationServlet; import com.gitblit.utils.ArrayUtils;
import com.gitblit.utils.BugtraqProcessor;
import com.gitblit.utils.DeepCopier;
+import com.gitblit.utils.GitBlitRequestUtils;
import com.gitblit.utils.JGitUtils;
import com.gitblit.utils.ModelUtils;
import com.gitblit.utils.RefLogUtils;
@@ -763,7 +764,7 @@ public abstract class RepositoryPage extends RootPage { if (StringUtils.isEmpty(searchString)) {
// redirect to self to avoid wicket page update bug
String absoluteUrl = getCanonicalUrl();
- getRequestCycle().setRequestTarget(new RedirectRequestTarget(absoluteUrl));
+ getRequestCycle().scheduleRequestHandlerAfterCurrent(new RedirectRequestHandler(absoluteUrl));
return;
}
for (Constants.SearchType type : Constants.SearchType.values()) {
@@ -785,7 +786,7 @@ public abstract class RepositoryPage extends RootPage { // mounted url parameters (issue-111)
PageParameters params = WicketUtils.newSearchParameter(repositoryName, null, searchString, searchType);
String absoluteUrl = getCanonicalUrl(searchPageClass, params);
- getRequestCycle().setRequestTarget(new RedirectRequestTarget(absoluteUrl));
+ getRequestCycle().scheduleRequestHandlerAfterCurrent(new RedirectRequestHandler(absoluteUrl));
}
}
}
diff --git a/src/main/java/com/gitblit/wicket/pages/TicketPage.java b/src/main/java/com/gitblit/wicket/pages/TicketPage.java index 53671b73..3ce5484e 100644 --- a/src/main/java/com/gitblit/wicket/pages/TicketPage.java +++ b/src/main/java/com/gitblit/wicket/pages/TicketPage.java @@ -1722,8 +1722,7 @@ public class TicketPage extends RepositoryPage { }
//Force reload of the page to rebuild ticket change cache
- String relativeUrl = urlFor(TicketsPage.class, getPageParameters()).toString();
- String absoluteUrl = RequestUtils.toAbsolutePath(relativeUrl);
+ String absoluteUrl = GitBlitRequestUtils.toAbsoluteUrl(TicketsPage.class, getPageParameters());
setResponsePage(new RedirectPage(absoluteUrl));
}
};
diff --git a/src/main/java/com/gitblit/wicket/panels/BranchesPanel.java b/src/main/java/com/gitblit/wicket/panels/BranchesPanel.java index 93dd1493..bc5cd8df 100644 --- a/src/main/java/com/gitblit/wicket/panels/BranchesPanel.java +++ b/src/main/java/com/gitblit/wicket/panels/BranchesPanel.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.Collections;
import java.util.List;
+import org.apache.wicket.request.http.handler.RedirectRequestHandler;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
@@ -32,7 +33,6 @@ import org.apache.wicket.markup.repeater.data.DataView; import org.apache.wicket.markup.repeater.data.ListDataProvider;
import org.apache.wicket.model.StringResourceModel;
import org.apache.wicket.protocol.http.RequestUtils;
-//import org.apache.wicket.request.target.basic.RedirectRequestTarget;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
@@ -43,6 +43,7 @@ import com.gitblit.models.UserModel; import com.gitblit.servlet.RawServlet;
import com.gitblit.servlet.SyndicationServlet;
import com.gitblit.utils.CommitCache;
+import com.gitblit.utils.GitBlitRequestUtils;
import com.gitblit.utils.JGitUtils;
import com.gitblit.utils.RefLogUtils;
import com.gitblit.utils.StringUtils;
@@ -231,9 +232,8 @@ public class BranchesPanel extends BasePanel { // redirect to the owning page
PageParameters params = WicketUtils.newRepositoryParameter(repositoryModel.name);
- String relativeUrl = urlFor(getPage().getClass(), params).toString();
- String absoluteUrl = RequestUtils.toAbsolutePath(relativeUrl);
- getRequestCycle().setRequestTarget(new RedirectRequestTarget(absoluteUrl));
+ String absoluteUrl = GitBlitRequestUtils.toAbsoluteUrl(getPage().getClass(), params);
+ getRequestCycle().scheduleRequestHandlerAfterCurrent(new RedirectRequestHandler(absoluteUrl));
}
};
diff --git a/src/main/java/com/gitblit/wicket/panels/CommentPanel.java b/src/main/java/com/gitblit/wicket/panels/CommentPanel.java index 93d2b840..3de07346 100644 --- a/src/main/java/com/gitblit/wicket/panels/CommentPanel.java +++ b/src/main/java/com/gitblit/wicket/panels/CommentPanel.java @@ -15,6 +15,7 @@ */ package com.gitblit.wicket.panels; +import org.apache.wicket.request.http.handler.RedirectRequestHandler; import org.apache.wicket.request.mapper.parameter.PageParameters; import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.ajax.markup.html.form.AjaxButton; @@ -22,12 +23,11 @@ import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.html.form.Form; import org.apache.wicket.model.IModel; import org.apache.wicket.model.Model; -import org.apache.wicket.protocol.http.RequestUtils; -//import org.apache.wicket.request.target.basic.RedirectRequestTarget; import com.gitblit.models.RepositoryModel; import com.gitblit.models.TicketModel; import com.gitblit.models.TicketModel.Change; +import com.gitblit.utils.GitBlitRequestUtils; import com.gitblit.models.UserModel; import com.gitblit.wicket.WicketUtils; import com.gitblit.wicket.pages.BasePage; @@ -103,9 +103,8 @@ public class CommentPanel extends BasePanel { */ private void redirectTo(Class<? extends BasePage> pageClass, PageParameters parameters) { - String relativeUrl = urlFor(pageClass, parameters).toString(); - String canonicalUrl = RequestUtils.toAbsolutePath(relativeUrl); - getRequestCycle().setRequestTarget(new RedirectRequestTarget(canonicalUrl)); + String absoluteUrl = GitBlitRequestUtils.toAbsoluteUrl(pageClass, parameters); + getRequestCycle().scheduleRequestHandlerAfterCurrent(new RedirectRequestHandler(absoluteUrl)); } }.setVisible(ticket != null && ticket.number > 0)); diff --git a/src/main/java/com/gitblit/wicket/panels/TicketSearchForm.java b/src/main/java/com/gitblit/wicket/panels/TicketSearchForm.java index 32f133d1..75a12dc5 100644 --- a/src/main/java/com/gitblit/wicket/panels/TicketSearchForm.java +++ b/src/main/java/com/gitblit/wicket/panels/TicketSearchForm.java @@ -18,11 +18,11 @@ package com.gitblit.wicket.panels; import java.io.Serializable; import java.text.MessageFormat; +import org.apache.wicket.request.http.handler.RedirectRequestHandler; import org.apache.wicket.request.mapper.parameter.PageParameters; import org.apache.wicket.markup.html.form.TextField; import org.apache.wicket.model.IModel; import org.apache.wicket.model.Model; -//import org.apache.wicket.request.target.basic.RedirectRequestTarget; import com.gitblit.utils.StringUtils; import com.gitblit.wicket.SessionlessForm; @@ -64,7 +64,7 @@ public class TicketSearchForm extends SessionlessForm<Void> implements Serializa if (StringUtils.isEmpty(searchString)) { // redirect to self to avoid wicket page update bug String absoluteUrl = getAbsoluteUrl(); - getRequestCycle().setRequestTarget(new RedirectRequestTarget(absoluteUrl)); + getRequestCycle().scheduleRequestHandlerAfterCurrent(new RedirectRequestHandler(absoluteUrl)); return; } @@ -73,6 +73,6 @@ public class TicketSearchForm extends SessionlessForm<Void> implements Serializa PageParameters params = WicketUtils.newRepositoryParameter(repositoryName); params.add("s", searchString); String absoluteUrl = getAbsoluteUrl(pageClass, params); - getRequestCycle().setRequestTarget(new RedirectRequestTarget(absoluteUrl)); + getRequestCycle().scheduleRequestHandlerAfterCurrent(new RedirectRequestHandler(absoluteUrl)); } } |