View Javadoc
1   /*
2    * Copyright (C) 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 java.io.IOException;
14  
15  import javax.servlet.ServletException;
16  import javax.servlet.http.HttpServlet;
17  import javax.servlet.http.HttpServletRequest;
18  import javax.servlet.http.HttpServletResponse;
19  
20  /**
21   * Send a fixed status code to the client.
22   */
23  public class ErrorServlet extends HttpServlet {
24  	private static final long serialVersionUID = 1L;
25  
26  	private final int status;
27  
28  	/**
29  	 * Sends a specific status code.
30  	 *
31  	 * @param status
32  	 *            the HTTP status code to always send.
33  	 */
34  	public ErrorServlet(int status) {
35  		this.status = status;
36  	}
37  
38  	/** {@inheritDoc} */
39  	@Override
40  	protected void doGet(HttpServletRequest req, HttpServletResponse rsp)
41  			throws ServletException, IOException {
42  		rsp.sendError(status);
43  	}
44  }