1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
| public class ResponseEntity<T> extends HttpEntity<T> {
private final Object statusCode;
public ResponseEntity(HttpStatus status) {
this((Object)null, (MultiValueMap)null, (HttpStatus)status);
}
public ResponseEntity(T body, HttpStatus status) {
this(body, (MultiValueMap)null, (HttpStatus)status);
}
public ResponseEntity(MultiValueMap<String, String> headers, HttpStatus status) {
this((Object)null, headers, (HttpStatus)status);
}
public ResponseEntity(T body, MultiValueMap<String, String> headers, HttpStatus status) {
super(body, headers);
Assert.notNull(status, "HttpStatus must not be null");
this.statusCode = status;
}
private ResponseEntity(T body, MultiValueMap<String, String> headers, Object statusCode) {
super(body, headers);
this.statusCode = statusCode;
}
public HttpStatus getStatusCode() {
return this.statusCode instanceof HttpStatus ? (HttpStatus)this.statusCode : HttpStatus.valueOf(((Integer)this.statusCode).intValue());
}
public int getStatusCodeValue() {
return this.statusCode instanceof HttpStatus ? ((HttpStatus)this.statusCode).value() : ((Integer)this.statusCode).intValue();
}
public boolean equals(Object other) {
if (this == other) {
return true;
} else if (!super.equals(other)) {
return false;
} else {
ResponseEntity<?> otherEntity = (ResponseEntity)other;
return ObjectUtils.nullSafeEquals(this.statusCode, otherEntity.statusCode);
}
}
public int hashCode() {
return super.hashCode() * 29 + ObjectUtils.nullSafeHashCode(this.statusCode);
}
public String toString() {
StringBuilder builder = new StringBuilder("<");
builder.append(this.statusCode.toString());
if (this.statusCode instanceof HttpStatus) {
builder.append(' ');
builder.append(((HttpStatus)this.statusCode).getReasonPhrase());
}
builder.append(',');
T body = this.getBody();
HttpHeaders headers = this.getHeaders();
if (body != null) {
builder.append(body);
if (headers != null) {
builder.append(',');
}
}
if (headers != null) {
builder.append(headers);
}
builder.append('>');
return builder.toString();
}
public static ResponseEntity.BodyBuilder status(HttpStatus status) {
Assert.notNull(status, "HttpStatus must not be null");
return new ResponseEntity.DefaultBuilder(status);
}
public static ResponseEntity.BodyBuilder status(int status) {
return new ResponseEntity.DefaultBuilder(status);
}
public static ResponseEntity.BodyBuilder ok() {
return status(HttpStatus.OK);
}
public static <T> ResponseEntity<T> ok(T body) {
ResponseEntity.BodyBuilder builder = ok();
return builder.body(body);
}
public static ResponseEntity.BodyBuilder created(URI location) {
ResponseEntity.BodyBuilder builder = status(HttpStatus.CREATED);
return (ResponseEntity.BodyBuilder)builder.location(location);
}
public static ResponseEntity.BodyBuilder accepted() {
return status(HttpStatus.ACCEPTED);
}
public static ResponseEntity.HeadersBuilder<?> noContent() {
return status(HttpStatus.NO_CONTENT);
}
public static ResponseEntity.BodyBuilder badRequest() {
return status(HttpStatus.BAD_REQUEST);
}
public static ResponseEntity.HeadersBuilder<?> notFound() {
return status(HttpStatus.NOT_FOUND);
}
public static ResponseEntity.BodyBuilder unprocessableEntity() {
return status(HttpStatus.UNPROCESSABLE_ENTITY);
}
private static class DefaultBuilder implements ResponseEntity.BodyBuilder {
private final Object statusCode;
private final HttpHeaders headers = new HttpHeaders();
public DefaultBuilder(Object statusCode) {
this.statusCode = statusCode;
}
public ResponseEntity.BodyBuilder header(String headerName, String... headerValues) {
String[] var3 = headerValues;
int var4 = headerValues.length;
for(int var5 = 0; var5 < var4; ++var5) {
String headerValue = var3[var5];
this.headers.add(headerName, headerValue);
}
return this;
}
public ResponseEntity.BodyBuilder headers(HttpHeaders headers) {
if (headers != null) {
this.headers.putAll(headers);
}
return this;
}
public ResponseEntity.BodyBuilder allow(HttpMethod... allowedMethods) {
this.headers.setAllow(new LinkedHashSet(Arrays.asList(allowedMethods)));
return this;
}
public ResponseEntity.BodyBuilder contentLength(long contentLength) {
this.headers.setContentLength(contentLength);
return this;
}
public ResponseEntity.BodyBuilder contentType(MediaType contentType) {
this.headers.setContentType(contentType);
return this;
}
public ResponseEntity.BodyBuilder eTag(String eTag) {
if (eTag != null) {
if (!eTag.startsWith("\"") && !eTag.startsWith("W/\"")) {
eTag = "\"" + eTag;
}
if (!eTag.endsWith("\"")) {
eTag = eTag + "\"";
}
}
this.headers.setETag(eTag);
return this;
}
public ResponseEntity.BodyBuilder lastModified(long date) {
this.headers.setLastModified(date);
return this;
}
public ResponseEntity.BodyBuilder location(URI location) {
this.headers.setLocation(location);
return this;
}
public ResponseEntity.BodyBuilder cacheControl(CacheControl cacheControl) {
String ccValue = cacheControl.getHeaderValue();
if (ccValue != null) {
this.headers.setCacheControl(cacheControl.getHeaderValue());
}
return this;
}
public ResponseEntity.BodyBuilder varyBy(String... requestHeaders) {
this.headers.setVary(Arrays.asList(requestHeaders));
return this;
}
public <T> ResponseEntity<T> build() {
return this.body((Object)null);
}
public <T> ResponseEntity<T> body(T body) {
return new ResponseEntity(body, this.headers, this.statusCode);
}
}
public interface BodyBuilder extends ResponseEntity.HeadersBuilder<ResponseEntity.BodyBuilder> {
ResponseEntity.BodyBuilder contentLength(long var1);
ResponseEntity.BodyBuilder contentType(MediaType var1);
<T> ResponseEntity<T> body(T var1);
}
public interface HeadersBuilder<B extends ResponseEntity.HeadersBuilder<B>> {
B header(String var1, String... var2);
B headers(HttpHeaders var1);
B allow(HttpMethod... var1);
B eTag(String var1);
B lastModified(long var1);
B location(URI var1);
B cacheControl(CacheControl var1);
B varyBy(String... var1);
<T> ResponseEntity<T> build();
}
} |