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.

WrappedRequest.java 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright (C) 2009-2010, Google Inc. and others
  3. *
  4. * This program and the accompanying materials are made available under the
  5. * terms of the Eclipse Distribution License v. 1.0 which is available at
  6. * https://www.eclipse.org/org/documents/edl-v10.php.
  7. *
  8. * SPDX-License-Identifier: BSD-3-Clause
  9. */
  10. package org.eclipse.jgit.http.server.glue;
  11. import javax.servlet.http.HttpServletRequest;
  12. import javax.servlet.http.HttpServletRequestWrapper;
  13. /**
  14. * Overrides the path and path info.
  15. */
  16. public class WrappedRequest extends HttpServletRequestWrapper {
  17. private final String path;
  18. private final String pathInfo;
  19. /**
  20. * Create a new request with different path and path info properties.
  21. *
  22. * @param originalRequest
  23. * the original HTTP request.
  24. * @param path
  25. * new servlet path to report to callers.
  26. * @param pathInfo
  27. * new path info to report to callers.
  28. */
  29. public WrappedRequest(final HttpServletRequest originalRequest,
  30. final String path, final String pathInfo) {
  31. super(originalRequest);
  32. this.path = path;
  33. this.pathInfo = pathInfo;
  34. }
  35. /** {@inheritDoc} */
  36. @Override
  37. public String getPathTranslated() {
  38. final String p = getPathInfo();
  39. return p != null ? getSession().getServletContext().getRealPath(p) : null;
  40. }
  41. /** {@inheritDoc} */
  42. @Override
  43. public String getPathInfo() {
  44. return pathInfo;
  45. }
  46. /** {@inheritDoc} */
  47. @Override
  48. public String getServletPath() {
  49. return path;
  50. }
  51. }