View Javadoc
1   /*
2    * SPDX-License-Identifier: MIT
3    * See LICENSE file for details.
4    *
5    * Copyright 2010-2026 The Waffle Project Contributors: https://github.com/Waffle/waffle/graphs/contributors
6    */
7   package waffle.mock.http;
8   
9   import jakarta.servlet.RequestDispatcher;
10  import jakarta.servlet.ServletException;
11  import jakarta.servlet.ServletRequest;
12  import jakarta.servlet.ServletResponse;
13  import jakarta.servlet.http.HttpServletResponse;
14  
15  import java.io.IOException;
16  
17  /**
18   * The Class SimpleRequestDispatcher.
19   */
20  public class SimpleRequestDispatcher implements RequestDispatcher {
21  
22      /** The url. */
23      private final String url;
24  
25      /**
26       * Instantiates a new simple request dispatcher.
27       *
28       * @param newUrl
29       *            the new url
30       */
31      public SimpleRequestDispatcher(final String newUrl) {
32          this.url = newUrl;
33      }
34  
35      @Override
36      public void forward(final ServletRequest request, final ServletResponse response)
37              throws ServletException, IOException {
38          final HttpServletResponse httpResponse = (HttpServletResponse) response;
39          httpResponse.setStatus(304);
40          httpResponse.addHeader("Location", this.url);
41      }
42  
43      @Override
44      public void include(final ServletRequest request, final ServletResponse response)
45              throws ServletException, IOException {
46          // Do Nothing
47      }
48  
49  }