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.UseProxy.*; 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 305 Use Proxy</c> response. 029 * 030 * <p> 031 * The requested resource is available only through a proxy, the address for which is provided in the response. 032 * Many HTTP clients (such as Mozilla and Internet Explorer) do not correctly handle responses with this status code, primarily for security reasons. 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 UseProxy extends BasicHttpResponse<UseProxy> { 042 043 /** HTTP status code */ 044 public static final int STATUS_CODE = 305; 045 046 /** Reason phrase */ 047 public static final String REASON_PHRASE = "Use Proxy"; 048 049 private static final BasicStatusLine STATUS_LINE = BasicStatusLine.create(STATUS_CODE, REASON_PHRASE); 050 051 /** Default unmodifiable instance */ 052 public static final UseProxy INSTANCE = new UseProxy().unmodifiable(); 053 054 /** 055 * Constructor. 056 */ 057 public UseProxy() { 058 super(STATUS_LINE); 059 } 060 061 /** 062 * Constructor. 063 * 064 * <p> 065 * This is the constructor used when parsing an HTTP response. 066 * 067 * @param response The HTTP response to copy from. Must not be <jk>null</jk>. 068 * @throws IllegalArgumentException If HTTP response status code does not match what was expected. 069 */ 070 public UseProxy(HttpResponse response) { 071 super(requireStatus(response, STATUS_CODE)); 072 } 073 074 /** 075 * Copy constructor. 076 * 077 * @param copyFrom The bean to copy from. Must not be <jk>null</jk>. 078 */ 079 public UseProxy(UseProxy copyFrom) { 080 super(copyFrom); 081 } 082 083 /** 084 * Creates a builder for this class initialized with the contents of this bean. 085 * 086 * @return A new builder bean. 087 */ 088 public UseProxy copy() { 089 return new UseProxy(this); 090 } 091 092 @Override /* Overridden from BasicHttpResponse */ 093 public UseProxy unmodifiable() { 094 return this instanceof UnmodifiableBean ? this : new Unmodifiable(this); 095 } 096 097 /** 098 * Unmodifiable point-in-time snapshot of the enclosing {@link UseProxy} response. 099 * 100 * <p> 101 * Its only behavioral override is {@link #modify(Runnable)}, which throws — because all mutation is funneled through 102 * {@code modify(...)}, this single override freezes the entire mutation surface. 103 */ 104 public static class Unmodifiable extends UseProxy implements UnmodifiableBean { 105 106 /** 107 * Constructor. 108 * 109 * @param copyFrom The response to snapshot. Must not be <jk>null</jk>. 110 */ 111 @SuppressWarnings({ 112 "java:S1699" // Paradigm intentionally calls the overridable freeze() from the ctor to deep-freeze sub-beans. 113 }) 114 protected Unmodifiable(UseProxy copyFrom) { 115 super(copyFrom); 116 freeze(); 117 } 118 119 @Override /* Overridden from BasicHttpResponse */ 120 protected UseProxy modify(Runnable mutation) { 121 throw uoex("Bean is unmodifiable."); 122 } 123 } 124}