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