You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ServiceMayNotContinueException.java 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * Copyright (C) 2011-2012, Google Inc.
  3. * and other copyright owners as documented in the project's IP log.
  4. *
  5. * This program and the accompanying materials are made available
  6. * under the terms of the Eclipse Distribution License v1.0 which
  7. * accompanies this distribution, is reproduced below, and is
  8. * available at http://www.eclipse.org/org/documents/edl-v10.php
  9. *
  10. * All rights reserved.
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials provided
  22. * with the distribution.
  23. *
  24. * - Neither the name of the Eclipse Foundation, Inc. nor the
  25. * names of its contributors may be used to endorse or promote
  26. * products derived from this software without specific prior
  27. * written permission.
  28. *
  29. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  30. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  31. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  32. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  33. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  34. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  35. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  36. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  37. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  38. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  40. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  41. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  42. */
  43. package org.eclipse.jgit.transport;
  44. import java.io.IOException;
  45. import javax.servlet.http.HttpServletResponse;
  46. import org.eclipse.jgit.internal.JGitText;
  47. /**
  48. * Indicates a transport service may not continue execution.
  49. *
  50. * @since 2.0
  51. */
  52. public class ServiceMayNotContinueException extends IOException {
  53. private static final long serialVersionUID = 1L;
  54. private final int statusCode;
  55. private boolean output;
  56. /** Initialize with no message. */
  57. public ServiceMayNotContinueException() {
  58. // Do not set a message.
  59. statusCode = HttpServletResponse.SC_FORBIDDEN;
  60. }
  61. /**
  62. * @param msg
  63. * a message explaining why it cannot continue. This message may
  64. * be shown to an end-user.
  65. */
  66. public ServiceMayNotContinueException(String msg) {
  67. super(msg);
  68. statusCode = HttpServletResponse.SC_FORBIDDEN;
  69. }
  70. /**
  71. * @param msg
  72. * a message explaining why it cannot continue. This message may
  73. * be shown to an end-user.
  74. * @param statusCode
  75. * the HTTP status code.
  76. * @since 4.5
  77. */
  78. public ServiceMayNotContinueException(String msg, int statusCode) {
  79. super(msg);
  80. this.statusCode = statusCode;
  81. }
  82. /**
  83. * @param msg
  84. * a message explaining why it cannot continue. This message may
  85. * be shown to an end-user.
  86. * @param cause
  87. * the cause of the exception.
  88. * @since 3.2
  89. */
  90. public ServiceMayNotContinueException(String msg, Throwable cause) {
  91. super(msg, cause);
  92. statusCode = HttpServletResponse.SC_FORBIDDEN;
  93. }
  94. /**
  95. * @param msg
  96. * a message explaining why it cannot continue. This message may
  97. * be shown to an end-user.
  98. * @param cause
  99. * the cause of the exception.
  100. * @param statusCode
  101. * the HTTP status code.
  102. * @since 4.5
  103. */
  104. public ServiceMayNotContinueException(
  105. String msg, Throwable cause, int statusCode) {
  106. super(msg, cause);
  107. this.statusCode = statusCode;
  108. }
  109. /**
  110. * Initialize with an "internal server error" message and a cause.
  111. *
  112. * @param cause
  113. * the cause of the exception.
  114. * @since 3.2
  115. */
  116. public ServiceMayNotContinueException(Throwable cause) {
  117. this(JGitText.get().internalServerError, cause);
  118. }
  119. /** @return true if the message was already output to the client. */
  120. public boolean isOutput() {
  121. return output;
  122. }
  123. /** Mark this message has being sent to the client. */
  124. public void setOutput() {
  125. output = true;
  126. }
  127. /**
  128. * @return true if the message was already output to the client.
  129. * @since 4.5
  130. */
  131. public int getStatusCode() {
  132. return statusCode;
  133. }
  134. }