View Javadoc
1   /**
2    * Waffle (https://github.com/dblock/waffle)
3    *
4    * Copyright (c) 2010 - 2015 Application Security, Inc.
5    *
6    * All rights reserved. This program and the accompanying materials
7    * are made available under the terms of the Eclipse Public License v1.0
8    * which accompanies this distribution, and is available at
9    * http://www.eclipse.org/legal/epl-v10.html
10   *
11   * Contributors:
12   *     Application Security, Inc.
13   */
14  package waffle.mock.http;
15  
16  import java.io.IOException;
17  
18  import javax.servlet.RequestDispatcher;
19  import javax.servlet.ServletException;
20  import javax.servlet.ServletRequest;
21  import javax.servlet.ServletResponse;
22  import javax.servlet.http.HttpServletResponse;
23  
24  /**
25   * The Class SimpleRequestDispatcher.
26   *
27   * @author dblock[at]dblock[dot]org
28   */
29  public class SimpleRequestDispatcher implements RequestDispatcher {
30  
31      /** The url. */
32      private final String url;
33  
34      /**
35       * Instantiates a new simple request dispatcher.
36       *
37       * @param newUrl
38       *            the new url
39       */
40      public SimpleRequestDispatcher(final String newUrl) {
41          this.url = newUrl;
42      }
43  
44      /* (non-Javadoc)
45       * @see javax.servlet.RequestDispatcher#forward(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
46       */
47      @Override
48      public void forward(final ServletRequest request, final ServletResponse response) throws ServletException,
49              IOException {
50          final HttpServletResponse httpResponse = (HttpServletResponse) response;
51          httpResponse.setStatus(304);
52          httpResponse.addHeader("Location", this.url);
53      }
54  
55      /* (non-Javadoc)
56       * @see javax.servlet.RequestDispatcher#include(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
57       */
58      @Override
59      public void include(final ServletRequest request, final ServletResponse response) throws ServletException,
60              IOException {
61          // Do Nothing
62      }
63  }