001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.http.response; 018 019import static org.apache.juneau.http.response.ServiceUnavailable.*; 020 021import java.text.*; 022import java.util.*; 023 024import org.apache.http.*; 025import org.apache.http.Header; 026import org.apache.juneau.annotation.*; 027import org.apache.juneau.http.*; 028import org.apache.juneau.http.annotation.*; 029import org.apache.juneau.http.header.*; 030import org.apache.juneau.internal.*; 031 032/** 033 * Exception representing an HTTP 503 (Service Unavailable). 034 * 035 * <p> 036 * The server is currently unavailable (because it is overloaded or down for maintenance). 037 * <br>Generally, this is a temporary state. 038 * 039 * <h5 class='section'>See Also:</h5><ul> 040 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauRestCommonBasics">juneau-rest-common Basics</a> 041 * </ul> 042 * 043 * @serial exclude 044 */ 045@Response 046@StatusCode(STATUS_CODE) 047@Schema(description=REASON_PHRASE) 048public class ServiceUnavailable extends BasicHttpException { 049 private static final long serialVersionUID = 1L; 050 051 /** HTTP status code */ 052 public static final int STATUS_CODE = 503; 053 054 /** Reason phrase */ 055 public static final String REASON_PHRASE = "Service Unavailable"; 056 057 /** Default status line */ 058 private static final BasicStatusLine STATUS_LINE = BasicStatusLine.create(STATUS_CODE, REASON_PHRASE); 059 060 /** Reusable unmodifiable instance */ 061 public static final ServiceUnavailable INSTANCE = new ServiceUnavailable().setUnmodifiable(); 062 063 /** 064 * Constructor. 065 * 066 * @param cause The caused-by exception. Can be <jk>null</jk>. 067 * @param msg The message. Can be <jk>null</jk>. 068 * @param args The message arguments. 069 */ 070 public ServiceUnavailable(Throwable cause, String msg, Object...args) { 071 super(STATUS_CODE, cause, msg, args); 072 setStatusLine(STATUS_LINE.copy()); 073 } 074 075 /** 076 * Constructor. 077 */ 078 public ServiceUnavailable() { 079 this((Throwable)null, REASON_PHRASE); 080 } 081 082 /** 083 * Constructor. 084 * 085 * @param msg The message. Can be <jk>null</jk>. 086 * @param args Optional {@link MessageFormat}-style arguments in the message. 087 */ 088 public ServiceUnavailable(String msg, Object...args) { 089 this((Throwable)null, msg, args); 090 } 091 092 /** 093 * Constructor. 094 * 095 * @param cause The cause. Can be <jk>null</jk>. 096 */ 097 public ServiceUnavailable(Throwable cause) { 098 this(cause, cause == null ? REASON_PHRASE : cause.getMessage()); 099 } 100 101 /** 102 * Constructor. 103 * 104 * <p> 105 * This is the constructor used when parsing an HTTP response. 106 * 107 * @param response The HTTP response to copy from. Must not be <jk>null</jk>. 108 * @throws AssertionError If HTTP response status code does not match what was expected. 109 */ 110 public ServiceUnavailable(HttpResponse response) { 111 super(response); 112 assertStatusCode(response); 113 } 114 115 /** 116 * Copy constructor. 117 * 118 * @param copyFrom The bean to copy. 119 */ 120 protected ServiceUnavailable(ServiceUnavailable copyFrom) { 121 super(copyFrom); 122 } 123 124 /** 125 * Creates a modifiable copy of this bean. 126 * 127 * @return A new modifiable bean. 128 */ 129 public ServiceUnavailable copy() { 130 return new ServiceUnavailable(this); 131 } 132 @Override /* Overridden from BasicRuntimeException */ 133 public ServiceUnavailable setMessage(String message, Object...args) { 134 super.setMessage(message, args); 135 return this; 136 } 137 138 @Override /* Overridden from BasicRuntimeException */ 139 public ServiceUnavailable setUnmodifiable() { 140 super.setUnmodifiable(); 141 return this; 142 } 143 144 @Override /* Overridden from BasicHttpException */ 145 public ServiceUnavailable setHeader2(String name, Object value) { 146 super.setHeader2(name, value); 147 return this; 148 } 149 150 @Override /* Overridden from BasicHttpException */ 151 public ServiceUnavailable setHeaders(HeaderList value) { 152 super.setHeaders(value); 153 return this; 154 } 155 156 @Override /* Overridden from BasicHttpException */ 157 public ServiceUnavailable setHeaders2(Header...values) { 158 super.setHeaders2(values); 159 return this; 160 } 161 162 @Override /* Overridden from BasicHttpException */ 163 public ServiceUnavailable setLocale2(Locale value) { 164 super.setLocale2(value); 165 return this; 166 } 167 168 @Override /* Overridden from BasicHttpException */ 169 public ServiceUnavailable setProtocolVersion(ProtocolVersion value) { 170 super.setProtocolVersion(value); 171 return this; 172 } 173 174 @Override /* Overridden from BasicHttpException */ 175 public ServiceUnavailable setReasonPhrase2(String value) { 176 super.setReasonPhrase2(value); 177 return this; 178 } 179 180 @Override /* Overridden from BasicHttpException */ 181 public ServiceUnavailable setReasonPhraseCatalog(ReasonPhraseCatalog value) { 182 super.setReasonPhraseCatalog(value); 183 return this; 184 } 185 186 @Override /* Overridden from BasicHttpException */ 187 public ServiceUnavailable setStatusCode2(int code) throws IllegalStateException{ 188 super.setStatusCode2(code); 189 return this; 190 } 191 192 @Override /* Overridden from BasicHttpException */ 193 public ServiceUnavailable setStatusLine(BasicStatusLine value) { 194 super.setStatusLine(value); 195 return this; 196 } 197}