You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GitblitRedirectException.java 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Copyright 2012 gitblit.com.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.gitblit.wicket;
  17. import org.apache.wicket.AbstractRestartResponseException;
  18. import org.apache.wicket.Page;
  19. import org.apache.wicket.PageParameters;
  20. import org.apache.wicket.RequestCycle;
  21. import org.apache.wicket.protocol.http.RequestUtils;
  22. import org.apache.wicket.request.target.basic.RedirectRequestTarget;
  23. /**
  24. * This exception bypasses the servlet container rewriting relative redirect
  25. * urls. The container can and does decode the carefully crafted %2F path
  26. * separators on a redirect. :( Bad, bad servlet container.
  27. *
  28. * org.eclipse.jetty.server.Response#L447: String path=uri.getDecodedPath();
  29. *
  30. * @author James Moger
  31. */
  32. public class GitblitRedirectException extends AbstractRestartResponseException {
  33. private static final long serialVersionUID = 1L;
  34. public <C extends Page> GitblitRedirectException(Class<C> pageClass) {
  35. this(pageClass, null);
  36. }
  37. public <C extends Page> GitblitRedirectException(Class<C> pageClass, PageParameters params) {
  38. RequestCycle cycle = RequestCycle.get();
  39. String relativeUrl = cycle.urlFor(pageClass, params).toString();
  40. String absoluteUrl = RequestUtils.toAbsolutePath(relativeUrl);
  41. cycle.setRequestTarget(new RedirectRequestTarget(absoluteUrl));
  42. cycle.setRedirect(true);
  43. }
  44. }