001/* 002 * Copyright 2012-2018 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.boot.actuate.endpoint.web; 018 019import org.springframework.boot.actuate.endpoint.web.annotation.EndpointWebExtension; 020 021/** 022 * A {@code WebEndpointResponse} can be returned by an operation on a 023 * {@link EndpointWebExtension} to provide additional, web-specific information such as 024 * the HTTP status code. 025 * 026 * @param <T> the type of the response body 027 * @author Stephane Nicoll 028 * @author Andy Wilkinson 029 * @author Vedran Pavic 030 * @since 2.0.0 031 */ 032public final class WebEndpointResponse<T> { 033 034 /** 035 * {@code 200 OK}. 036 */ 037 public static final int STATUS_OK = 200; 038 039 /** 040 * {@code 204 No Content}. 041 */ 042 public static final int STATUS_NO_CONTENT = 204; 043 044 /** 045 * {@code 400 Bad Request}. 046 */ 047 public static final int STATUS_BAD_REQUEST = 400; 048 049 /** 050 * {@code 404 Not Found}. 051 */ 052 public static final int STATUS_NOT_FOUND = 404; 053 054 /** 055 * {@code 429 Too Many Requests}. 056 */ 057 public static final int STATUS_TOO_MANY_REQUESTS = 429; 058 059 /** 060 * {@code 500 Internal Server Error}. 061 */ 062 public static final int STATUS_INTERNAL_SERVER_ERROR = 500; 063 064 /** 065 * {@code 503 Service Unavailable}. 066 */ 067 public static final int STATUS_SERVICE_UNAVAILABLE = 503; 068 069 private final T body; 070 071 private final int status; 072 073 /** 074 * Creates a new {@code WebEndpointResponse} with no body and a 200 (OK) status. 075 */ 076 public WebEndpointResponse() { 077 this(null); 078 } 079 080 /** 081 * Creates a new {@code WebEndpointResponse} with no body and the given 082 * {@code status}. 083 * @param status the HTTP status 084 */ 085 public WebEndpointResponse(int status) { 086 this(null, status); 087 } 088 089 /** 090 * Creates a new {@code WebEndpointResponse} with then given body and a 200 (OK) 091 * status. 092 * @param body the body 093 */ 094 public WebEndpointResponse(T body) { 095 this(body, STATUS_OK); 096 } 097 098 /** 099 * Creates a new {@code WebEndpointResponse} with then given body and status. 100 * @param body the body 101 * @param status the HTTP status 102 */ 103 public WebEndpointResponse(T body, int status) { 104 this.body = body; 105 this.status = status; 106 } 107 108 /** 109 * Returns the body for the response. 110 * @return the body 111 */ 112 public T getBody() { 113 return this.body; 114 } 115 116 /** 117 * Returns the status for the response. 118 * @return the status 119 */ 120 public int getStatus() { 121 return this.status; 122 } 123 124}