View Javadoc
1   /*
2    * Copyright (C) 2011-2012, 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.transport;
12  
13  import java.io.IOException;
14  
15  import org.eclipse.jgit.internal.JGitText;
16  
17  /**
18   * Indicates a transport service may not continue execution.
19   *
20   * @since 2.0
21   */
22  public class ServiceMayNotContinueException extends IOException {
23  	private static final int FORBIDDEN = 403;
24  	private static final long serialVersionUID = 1L;
25  
26  	private final int statusCode;
27  	private boolean output;
28  
29  	/**
30  	 * Initialize with no message.
31  	 */
32  	public ServiceMayNotContinueException() {
33  		// Do not set a message.
34  		statusCode = FORBIDDEN;
35  	}
36  
37  	/**
38  	 * <p>Constructor for ServiceMayNotContinueException.</p>
39  	 *
40  	 * @param msg
41  	 *            a message explaining why it cannot continue. This message may
42  	 *            be shown to an end-user.
43  	 */
44  	public ServiceMayNotContinueException(String msg) {
45  		super(msg);
46  		statusCode = FORBIDDEN;
47  	}
48  
49  	/**
50  	 * <p>Constructor for ServiceMayNotContinueException.</p>
51  	 *
52  	 * @param msg
53  	 *            a message explaining why it cannot continue. This message may
54  	 *            be shown to an end-user.
55  	 * @param statusCode
56  	 *            the HTTP status code.
57  	 * @since 4.5
58  	 */
59  	public ServiceMayNotContinueException(String msg, int statusCode) {
60  		super(msg);
61  		this.statusCode = statusCode;
62  	}
63  
64  	/**
65  	 * <p>Constructor for ServiceMayNotContinueException.</p>
66  	 *
67  	 * @param msg
68  	 *            a message explaining why it cannot continue. This message may
69  	 *            be shown to an end-user.
70  	 * @param cause
71  	 *            the cause of the exception.
72  	 * @since 3.2
73  	 */
74  	public ServiceMayNotContinueException(String msg, Throwable cause) {
75  		super(msg, cause);
76  		statusCode = FORBIDDEN;
77  	}
78  
79  	/**
80  	 * <p>Constructor for ServiceMayNotContinueException.</p>
81  	 *
82  	 * @param msg
83  	 *            a message explaining why it cannot continue. This message may
84  	 *            be shown to an end-user.
85  	 * @param cause
86  	 *            the cause of the exception.
87  	 * @param statusCode
88  	 *            the HTTP status code.
89  	 * @since 4.5
90  	 */
91  	public ServiceMayNotContinueException(
92  			String msg, Throwable cause, int statusCode) {
93  		super(msg, cause);
94  		this.statusCode = statusCode;
95  	}
96  
97  	/**
98  	 * Initialize with an "internal server error" message and a cause.
99  	 *
100 	 * @param cause
101 	 *            the cause of the exception.
102 	 * @since 3.2
103 	 */
104 	public ServiceMayNotContinueException(Throwable cause) {
105 		this(JGitText.get().internalServerError, cause);
106 	}
107 
108 	/**
109 	 * Whether the message was already output to the client.
110 	 *
111 	 * @return {@code true} if the message was already output to the client.
112 	 */
113 	public boolean isOutput() {
114 		return output;
115 	}
116 
117 	/**
118 	 * Mark this message has being sent to the client.
119 	 */
120 	public void setOutput() {
121 		output = true;
122 	}
123 
124 	/**
125 	 * Get status code
126 	 *
127 	 * @return true if the message was already output to the client.
128 	 * @since 4.5
129 	 */
130 	public int getStatusCode() {
131 		return statusCode;
132 	}
133 }