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.classic.response;
018
019import static org.apache.juneau.commons.utils.Shorts.*;
020import static org.apache.juneau.http.classic.response.Accepted.*;
021
022import org.apache.http.*;
023import org.apache.juneau.commons.*;
024import org.apache.juneau.http.*;
025import org.apache.juneau.http.classic.*;
026
027/**
028 * Represents an <c>HTTP 202 Accepted</c> response.
029 *
030 * <p>
031 * The request has been accepted for processing, but the processing has not been completed.
032 * The request might or might not be eventually acted upon, and may be disallowed when processing occurs.
033 *
034 * <h5 class='section'>See Also:</h5><ul>
035 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauRestCommon">juneau-rest-common</a>
036 * </ul>
037 */
038@Response
039@StatusCode(STATUS_CODE)
040@Schema(description = REASON_PHRASE)
041public class Accepted extends BasicHttpResponse<Accepted> {
042
043   /** HTTP status code */
044   public static final int STATUS_CODE = 202;
045
046   /** Reason phrase */
047   public static final String REASON_PHRASE = "Accepted";
048
049   /** Default status line */
050   private static final BasicStatusLine STATUS_LINE = BasicStatusLine.create(STATUS_CODE, REASON_PHRASE);
051
052   /** Default unmodifiable instance */
053   public static final Accepted INSTANCE = new Accepted().unmodifiable();
054
055   /**
056    * Constructor.
057    */
058   public Accepted() {
059      super(STATUS_LINE);
060   }
061
062   /**
063    * Copy constructor.
064    *
065    * @param copyFrom The bean to copy from.  Must not be <jk>null</jk>.
066    */
067   public Accepted(Accepted copyFrom) {
068      super(copyFrom);
069   }
070
071   /**
072    * Constructor.
073    *
074    * <p>
075    * This is the constructor used when parsing an HTTP response.
076    *
077    * @param response The HTTP response to copy from.  Must not be <jk>null</jk>.
078    * @throws IllegalArgumentException If HTTP response status code does not match what was expected.
079    */
080   public Accepted(HttpResponse response) {
081      super(requireStatus(response, STATUS_CODE));
082   }
083
084   /**
085    * Creates a builder for this class initialized with the contents of this bean.
086    *
087    * @return A new builder bean.
088    */
089   public Accepted copy() {
090      return new Accepted(this);
091   }
092
093   @Override /* Overridden from BasicHttpResponse */
094   public Accepted unmodifiable() {
095      return this instanceof UnmodifiableBean ? this : new Unmodifiable(this);
096   }
097
098   /**
099    * Unmodifiable point-in-time snapshot of the enclosing {@link Accepted} response.
100    *
101    * <p>
102    * Its only behavioral override is {@link #modify(Runnable)}, which throws — because all mutation is funneled through
103    * {@code modify(...)}, this single override freezes the entire mutation surface.
104    */
105   public static class Unmodifiable extends Accepted implements UnmodifiableBean {
106
107      /**
108       * Constructor.
109       *
110       * @param copyFrom The response to snapshot.  Must not be <jk>null</jk>.
111       */
112      @SuppressWarnings({
113         "java:S1699" // Paradigm intentionally calls the overridable freeze() from the ctor to deep-freeze sub-beans.
114      })
115      protected Unmodifiable(Accepted copyFrom) {
116         super(copyFrom);
117         freeze();
118      }
119
120      @Override /* Overridden from BasicHttpResponse */
121      protected Accepted modify(Runnable mutation) {
122         throw uoex("Bean is unmodifiable.");
123      }
124   }
125}