1 /*
2 * Copyright 2012-2025 CodeLibs Project and the Others.
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,
13 * either express or implied. See the License for the specific language
14 * governing permissions and limitations under the License.
15 */
16 package org.codelibs.fess.api;
17
18 import jakarta.servlet.http.HttpServletRequest;
19 import jakarta.servlet.http.HttpServletRequestWrapper;
20
21 /**
22 * Wrapper for HTTP servlet requests in web API context.
23 * This class extends HttpServletRequestWrapper to provide custom servlet path handling
24 * for web API requests.
25 */
26 public class WebApiRequest extends HttpServletRequestWrapper {
27 /**
28 * The custom servlet path for this web API request.
29 */
30 protected String servletPath;
31
32 /**
33 * Constructs a WebApiRequest with the specified request and servlet path.
34 *
35 * @param request The original HTTP servlet request
36 * @param servletPath The custom servlet path for this web API request
37 */
38 public WebApiRequest(final HttpServletRequest request, final String servletPath) {
39 super(request);
40 this.servletPath = servletPath;
41 }
42
43 /**
44 * Gets the servlet path for this request.
45 * Returns the custom servlet path unless the query string contains SAStruts.method.
46 *
47 * @return The servlet path
48 */
49 @Override
50 public String getServletPath() {
51 if (getQueryString() != null && getQueryString().indexOf("SAStruts.method") != -1) {
52 return super.getServletPath();
53 }
54 return servletPath;
55 }
56
57 }