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.Ok.*; 020 021import java.net.*; 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 * Represents an <c>HTTP 200 OK</c> response. 034 * 035 * <p> 036 * Standard response for successful HTTP requests. The actual response will depend on the request method used. 037 * In a GET request, the response will contain an entity corresponding to the requested resource. 038 * In a POST request, the response will contain an entity describing or containing the result of the action. 039 * 040 * <h5 class='section'>See Also:</h5><ul> 041 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauRestCommonBasics">juneau-rest-common Basics</a> 042 * </ul> 043 */ 044@Response 045@StatusCode(STATUS_CODE) 046@Schema(description=REASON_PHRASE) 047public class Ok extends BasicHttpResponse { 048 049 /** HTTP status code */ 050 public static final int STATUS_CODE = 200; 051 052 /** Reason phrase */ 053 public static final String REASON_PHRASE = "OK"; 054 055 /** Default status line */ 056 private static final BasicStatusLine STATUS_LINE = BasicStatusLine.create(STATUS_CODE, REASON_PHRASE); 057 058 /** Default unmodifiable instance */ 059 public static final Ok INSTANCE = new Ok().setUnmodifiable(); 060 061 /** Reusable unmodifiable instance */ 062 public static final Ok OK = INSTANCE; 063 064 /** 065 * Constructor. 066 */ 067 public Ok() { 068 super(STATUS_LINE); 069 } 070 071 /** 072 * Copy constructor. 073 * 074 * @param copyFrom The bean to copy from. 075 */ 076 public Ok(Ok copyFrom) { 077 super(copyFrom); 078 } 079 080 /** 081 * Constructor. 082 * 083 * <p> 084 * This is the constructor used when parsing an HTTP response. 085 * 086 * @param response The HTTP response to copy from. Must not be <jk>null</jk>. 087 * @throws AssertionError If HTTP response status code does not match what was expected. 088 */ 089 public Ok(HttpResponse response) { 090 super(response); 091 assertStatusCode(response); 092 } 093 094 /** 095 * Creates a builder for this class initialized with the contents of this bean. 096 * 097 * @return A new builder bean. 098 */ 099 public Ok copy() { 100 return new Ok(this); 101 } 102 @Override /* Overridden from BasicHttpResponse */ 103 public Ok setContent(String value) { 104 super.setContent(value); 105 return this; 106 } 107 108 @Override /* Overridden from BasicHttpResponse */ 109 public Ok setContent(HttpEntity value) { 110 super.setContent(value); 111 return this; 112 } 113 114 @Override /* Overridden from BasicHttpResponse */ 115 public Ok setHeader2(Header value) { 116 super.setHeader2(value); 117 return this; 118 } 119 120 @Override /* Overridden from BasicHttpResponse */ 121 public Ok setHeader2(String name, String value) { 122 super.setHeader2(name, value); 123 return this; 124 } 125 126 @Override /* Overridden from BasicHttpResponse */ 127 public Ok setHeaders(List<Header> values) { 128 super.setHeaders(values); 129 return this; 130 } 131 132 @Override /* Overridden from BasicHttpResponse */ 133 public Ok setHeaders(HeaderList value) { 134 super.setHeaders(value); 135 return this; 136 } 137 138 @Override /* Overridden from BasicHttpResponse */ 139 public Ok setHeaders2(Header...values) { 140 super.setHeaders2(values); 141 return this; 142 } 143 144 @Override /* Overridden from BasicHttpResponse */ 145 public Ok setLocale2(Locale value) { 146 super.setLocale2(value); 147 return this; 148 } 149 150 @Override /* Overridden from BasicHttpResponse */ 151 public Ok setLocation(String value) { 152 super.setLocation(value); 153 return this; 154 } 155 156 @Override /* Overridden from BasicHttpResponse */ 157 public Ok setLocation(URI value) { 158 super.setLocation(value); 159 return this; 160 } 161 162 @Override /* Overridden from BasicHttpResponse */ 163 public Ok setProtocolVersion(ProtocolVersion value) { 164 super.setProtocolVersion(value); 165 return this; 166 } 167 168 @Override /* Overridden from BasicHttpResponse */ 169 public Ok setReasonPhrase2(String value) { 170 super.setReasonPhrase2(value); 171 return this; 172 } 173 174 @Override /* Overridden from BasicHttpResponse */ 175 public Ok setReasonPhraseCatalog(ReasonPhraseCatalog value) { 176 super.setReasonPhraseCatalog(value); 177 return this; 178 } 179 180 @Override /* Overridden from BasicHttpResponse */ 181 public Ok setStatusCode2(int value) { 182 super.setStatusCode2(value); 183 return this; 184 } 185 186 @Override /* Overridden from BasicHttpResponse */ 187 public Ok setStatusLine(BasicStatusLine value) { 188 super.setStatusLine(value); 189 return this; 190 } 191 192 @Override /* Overridden from BasicHttpResponse */ 193 public Ok setUnmodifiable() { 194 super.setUnmodifiable(); 195 return this; 196 } 197}