View Javadoc
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  
11  package org.eclipse.jgit.http.server.glue;
12  
13  import javax.servlet.http.HttpServletRequest;
14  import javax.servlet.http.HttpServletRequestWrapper;
15  
16  /**
17   * Overrides the path and path info.
18   */
19  public class WrappedRequest extends HttpServletRequestWrapper {
20  	private final String path;
21  
22  	private final String pathInfo;
23  
24  	/**
25  	 * Create a new request with different path and path info properties.
26  	 *
27  	 * @param originalRequest
28  	 *            the original HTTP request.
29  	 * @param path
30  	 *            new servlet path to report to callers.
31  	 * @param pathInfo
32  	 *            new path info to report to callers.
33  	 */
34  	public WrappedRequest(final HttpServletRequest originalRequest,
35  			final String path, final String pathInfo) {
36  		super(originalRequest);
37  		this.path = path;
38  		this.pathInfo = pathInfo;
39  	}
40  
41  	/** {@inheritDoc} */
42  	@Override
43  	public String getPathTranslated() {
44  		final String p = getPathInfo();
45  		return p != null ? getSession().getServletContext().getRealPath(p) : null;
46  	}
47  
48  	/** {@inheritDoc} */
49  	@Override
50  	public String getPathInfo() {
51  		return pathInfo;
52  	}
53  
54  	/** {@inheritDoc} */
55  	@Override
56  	public String getServletPath() {
57  		return path;
58  	}
59  }