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.NotFound.*; 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.*; 030 031/** 032 * Exception representing an HTTP 404 (Not Found). 033 * 034 * <p> 035 * The requested resource could not be found but may be available in the future. 036 * <br>Subsequent requests by the client are permissible. 037 * 038 * <h5 class='section'>See Also:</h5><ul> 039 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauRestCommonBasics">juneau-rest-common Basics</a> 040 * </ul> 041 * 042 * @serial exclude 043 */ 044@Response 045@StatusCode(STATUS_CODE) 046@Schema(description = REASON_PHRASE) 047public class NotFound extends BasicHttpException { 048 private static final long serialVersionUID = 1L; 049 050 /** HTTP status code */ 051 public static final int STATUS_CODE = 404; 052 053 /** Reason phrase */ 054 public static final String REASON_PHRASE = "Not Found"; 055 056 /** Default status line */ 057 private static final BasicStatusLine STATUS_LINE = BasicStatusLine.create(STATUS_CODE, REASON_PHRASE); 058 059 /** Reusable unmodifiable instance */ 060 public static final NotFound INSTANCE = new NotFound().setUnmodifiable(); 061 062 /** 063 * Constructor. 064 */ 065 public NotFound() { 066 this((Throwable)null, REASON_PHRASE); 067 } 068 069 /** 070 * Constructor. 071 * 072 * <p> 073 * This is the constructor used when parsing an HTTP response. 074 * 075 * @param response The HTTP response to copy from. Must not be <jk>null</jk>. 076 * @throws AssertionError If HTTP response status code does not match what was expected. 077 */ 078 public NotFound(HttpResponse response) { 079 super(response); 080 assertStatusCode(response); 081 } 082 083 /** 084 * Constructor. 085 * 086 * @param msg The message. Can be <jk>null</jk>. 087 * @param args Optional {@link MessageFormat}-style arguments in the message. 088 */ 089 public NotFound(String msg, Object...args) { 090 this((Throwable)null, msg, args); 091 } 092 093 /** 094 * Constructor. 095 * 096 * @param cause The cause. Can be <jk>null</jk>. 097 */ 098 public NotFound(Throwable cause) { 099 this(cause, cause == null ? REASON_PHRASE : cause.getMessage()); 100 } 101 102 /** 103 * Constructor. 104 * 105 * @param cause The caused-by exception. Can be <jk>null</jk>. 106 * @param msg The message. Can be <jk>null</jk>. 107 * @param args The message arguments. 108 */ 109 public NotFound(Throwable cause, String msg, Object...args) { 110 super(STATUS_CODE, cause, msg, args); 111 setStatusLine(STATUS_LINE.copy()); 112 } 113 114 /** 115 * Copy constructor. 116 * 117 * @param copyFrom The bean to copy. 118 */ 119 protected NotFound(NotFound copyFrom) { 120 super(copyFrom); 121 } 122 123 /** 124 * Creates a modifiable copy of this bean. 125 * 126 * @return A new modifiable bean. 127 */ 128 public NotFound copy() { 129 return new NotFound(this); 130 } 131 132 @Override /* Overridden from BasicHttpException */ 133 public NotFound setContent(HttpEntity value) { 134 super.setContent(value); 135 return this; 136 } 137 138 @Override /* Overridden from BasicHttpException */ 139 public NotFound setContent(String value) { 140 super.setContent(value); 141 return this; 142 } 143 144 @Override /* Overridden from BasicHttpException */ 145 public NotFound setHeader2(String name, Object value) { 146 super.setHeader2(name, value); 147 return this; 148 } 149 150 @Override /* Overridden from BasicHttpException */ 151 public NotFound setHeaders(HeaderList value) { 152 super.setHeaders(value); 153 return this; 154 } 155 156 @Override /* Overridden from BasicHttpException */ 157 public NotFound setHeaders(List<Header> values) { 158 super.setHeaders(values); 159 return this; 160 } 161 162 @Override /* Overridden from BasicHttpException */ 163 public NotFound setHeaders2(Header...values) { 164 super.setHeaders2(values); 165 return this; 166 } 167 168 @Override /* Overridden from BasicHttpException */ 169 public NotFound setLocale2(Locale value) { 170 super.setLocale2(value); 171 return this; 172 } 173 174 @Override /* Overridden from BasicRuntimeException */ 175 public NotFound setMessage(String message, Object...args) { 176 super.setMessage(message, args); 177 return this; 178 } 179 180 @Override /* Overridden from BasicHttpException */ 181 public NotFound setProtocolVersion(ProtocolVersion value) { 182 super.setProtocolVersion(value); 183 return this; 184 } 185 186 @Override /* Overridden from BasicHttpException */ 187 public NotFound setReasonPhrase2(String value) { 188 super.setReasonPhrase2(value); 189 return this; 190 } 191 192 @Override /* Overridden from BasicHttpException */ 193 public NotFound setReasonPhraseCatalog(ReasonPhraseCatalog value) { 194 super.setReasonPhraseCatalog(value); 195 return this; 196 } 197 198 @Override /* Overridden from BasicHttpException */ 199 public NotFound setStatusCode2(int code) throws IllegalStateException { 200 super.setStatusCode2(code); 201 return this; 202 } 203 204 @Override /* Overridden from BasicHttpException */ 205 public NotFound setStatusLine(BasicStatusLine value) { 206 super.setStatusLine(value); 207 return this; 208 } 209 210 @Override /* Overridden from BasicRuntimeException */ 211 public NotFound setUnmodifiable() { 212 super.setUnmodifiable(); 213 return this; 214 } 215}