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.PayloadTooLarge.*; 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 413 (Payload Too Large). 034 * 035 * <p> 036 * The request is larger than the server is willing or able to process. 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 PayloadTooLarge extends BasicHttpException { 048 private static final long serialVersionUID = 1L; 049 050 /** HTTP status code */ 051 public static final int STATUS_CODE = 413; 052 053 /** Reason phrase */ 054 public static final String REASON_PHRASE = "Payload Too Large"; 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 PayloadTooLarge INSTANCE = new PayloadTooLarge().setUnmodifiable(); 061 062 /** 063 * Constructor. 064 * 065 * @param cause The caused-by exception. Can be <jk>null</jk>. 066 * @param msg The message. Can be <jk>null</jk>. 067 * @param args The message arguments. 068 */ 069 public PayloadTooLarge(Throwable cause, String msg, Object...args) { 070 super(STATUS_CODE, cause, msg, args); 071 setStatusLine(STATUS_LINE.copy()); 072 } 073 074 /** 075 * Constructor. 076 */ 077 public PayloadTooLarge() { 078 this((Throwable)null, REASON_PHRASE); 079 } 080 081 /** 082 * Constructor. 083 * 084 * @param msg The message. Can be <jk>null</jk>. 085 * @param args Optional {@link MessageFormat}-style arguments in the message. 086 */ 087 public PayloadTooLarge(String msg, Object...args) { 088 this((Throwable)null, msg, args); 089 } 090 091 /** 092 * Constructor. 093 * 094 * @param cause The cause. Can be <jk>null</jk>. 095 */ 096 public PayloadTooLarge(Throwable cause) { 097 this(cause, cause == null ? REASON_PHRASE : cause.getMessage()); 098 } 099 100 /** 101 * Constructor. 102 * 103 * <p> 104 * This is the constructor used when parsing an HTTP response. 105 * 106 * @param response The HTTP response to copy from. Must not be <jk>null</jk>. 107 * @throws AssertionError If HTTP response status code does not match what was expected. 108 */ 109 public PayloadTooLarge(HttpResponse response) { 110 super(response); 111 assertStatusCode(response); 112 } 113 114 /** 115 * Copy constructor. 116 * 117 * @param copyFrom The bean to copy. 118 */ 119 protected PayloadTooLarge(PayloadTooLarge 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 PayloadTooLarge copy() { 129 return new PayloadTooLarge(this); 130 } 131 @Override /* Overridden from BasicRuntimeException */ 132 public PayloadTooLarge setMessage(String message, Object...args) { 133 super.setMessage(message, args); 134 return this; 135 } 136 137 @Override /* Overridden from BasicRuntimeException */ 138 public PayloadTooLarge setUnmodifiable() { 139 super.setUnmodifiable(); 140 return this; 141 } 142 143 @Override /* Overridden from BasicHttpException */ 144 public PayloadTooLarge setHeader2(String name, Object value) { 145 super.setHeader2(name, value); 146 return this; 147 } 148 149 @Override /* Overridden from BasicHttpException */ 150 public PayloadTooLarge setHeaders(HeaderList value) { 151 super.setHeaders(value); 152 return this; 153 } 154 155 @Override /* Overridden from BasicHttpException */ 156 public PayloadTooLarge setHeaders2(Header...values) { 157 super.setHeaders2(values); 158 return this; 159 } 160 161 @Override /* Overridden from BasicHttpException */ 162 public PayloadTooLarge setLocale2(Locale value) { 163 super.setLocale2(value); 164 return this; 165 } 166 167 @Override /* Overridden from BasicHttpException */ 168 public PayloadTooLarge setProtocolVersion(ProtocolVersion value) { 169 super.setProtocolVersion(value); 170 return this; 171 } 172 173 @Override /* Overridden from BasicHttpException */ 174 public PayloadTooLarge setReasonPhrase2(String value) { 175 super.setReasonPhrase2(value); 176 return this; 177 } 178 179 @Override /* Overridden from BasicHttpException */ 180 public PayloadTooLarge setReasonPhraseCatalog(ReasonPhraseCatalog value) { 181 super.setReasonPhraseCatalog(value); 182 return this; 183 } 184 185 @Override /* Overridden from BasicHttpException */ 186 public PayloadTooLarge setStatusCode2(int code) throws IllegalStateException{ 187 super.setStatusCode2(code); 188 return this; 189 } 190 191 @Override /* Overridden from BasicHttpException */ 192 public PayloadTooLarge setStatusLine(BasicStatusLine value) { 193 super.setStatusLine(value); 194 return this; 195 } 196}