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.*; 030 031/** 032 * Represents an <c>HTTP 200 OK</c> response. 033 * 034 * <p> 035 * Standard response for successful HTTP requests. The actual response will depend on the request method used. 036 * In a GET request, the response will contain an entity corresponding to the requested resource. 037 * In a POST request, the response will contain an entity describing or containing the result of the action. 038 * 039 * <h5 class='section'>See Also:</h5><ul> 040 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauRestCommonBasics">juneau-rest-common Basics</a> 041 * </ul> 042 */ 043@Response 044@StatusCode(STATUS_CODE) 045@Schema(description = REASON_PHRASE) 046public class Ok extends BasicHttpResponse { 047 048 /** HTTP status code */ 049 public static final int STATUS_CODE = 200; 050 051 /** Reason phrase */ 052 public static final String REASON_PHRASE = "OK"; 053 054 /** Default status line */ 055 private static final BasicStatusLine STATUS_LINE = BasicStatusLine.create(STATUS_CODE, REASON_PHRASE); 056 057 /** Default unmodifiable instance */ 058 public static final Ok INSTANCE = new Ok().setUnmodifiable(); 059 060 /** Reusable unmodifiable instance */ 061 public static final Ok OK = INSTANCE; 062 063 /** 064 * Constructor. 065 */ 066 public Ok() { 067 super(STATUS_LINE); 068 } 069 070 /** 071 * Constructor. 072 * 073 * <p> 074 * This is the constructor used when parsing an HTTP response. 075 * 076 * @param response The HTTP response to copy from. Must not be <jk>null</jk>. 077 * @throws AssertionError If HTTP response status code does not match what was expected. 078 */ 079 public Ok(HttpResponse response) { 080 super(response); 081 assertStatusCode(response); 082 } 083 084 /** 085 * Copy constructor. 086 * 087 * @param copyFrom The bean to copy from. 088 */ 089 public Ok(Ok copyFrom) { 090 super(copyFrom); 091 } 092 093 /** 094 * Creates a builder for this class initialized with the contents of this bean. 095 * 096 * @return A new builder bean. 097 */ 098 public Ok copy() { 099 return new Ok(this); 100 } 101 102 @Override /* Overridden from BasicHttpResponse */ 103 public Ok setContent(HttpEntity value) { 104 super.setContent(value); 105 return this; 106 } 107 108 @Override /* Overridden from BasicHttpResponse */ 109 public Ok setContent(String 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(HeaderList value) { 128 super.setHeaders(value); 129 return this; 130 } 131 132 @Override /* Overridden from BasicHttpResponse */ 133 public Ok setHeaders(List<Header> values) { 134 super.setHeaders(values); 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}