Package com.acumenvelocity.ath.common
Class Response
- java.lang.Object
-
- com.acumenvelocity.ath.common.Response
-
public class Response extends Object
Utility class for creating standardized HTTP responses in a REST API context. Provides methods for creating success and error responses with consistent formatting and content types.All responses are returned as JSON with UTF-8 encoding and include appropriate HTTP status codes and logging.
- Since:
- 1.0
- Version:
- 1.0
- Author:
- Acumen Velocity
- See Also:
ResponseContext,ResponseCodeMessage
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classResponse.BuilderBuilder class for creating ResponseContext instances with a fluent API.
-
Field Summary
Fields Modifier and Type Field Description static StringAPPLICATION_JSONstatic javax.ws.rs.core.MediaTypeAPPLICATION_JSON_MEDIA_TYPEstatic StringAPPLICATION_JSON_UTF8static javax.ws.rs.core.MediaTypeAPPLICATION_JSON_UTF8_MEDIA_TYPE
-
Constructor Summary
Constructors Constructor Description Response()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Response.Builderbuilder()Creates a builder for constructing a ResponseContext with chained method calls.static io.swagger.oas.inflector.models.ResponseContexterror(int code, String message)Creates an error response with the specified status code and message.static io.swagger.oas.inflector.models.ResponseContexterror(int code, String format, Object... arguments)Creates an error response with formatted message.static io.swagger.oas.inflector.models.ResponseContexterror(int code, Throwable cause, String message)Creates an error response with exception details.static io.swagger.oas.inflector.models.ResponseContexterror(int code, Throwable cause, String format, Object... arguments)Creates an error response with exception details and formatted message.static StringgetMessage(io.swagger.oas.inflector.models.ResponseContext res)static io.swagger.oas.inflector.models.ResponseContextmakeResponse(javax.ws.rs.core.Response.Status status, Object obj, String headerKey, String headerValue)static io.swagger.oas.inflector.models.ResponseContextsuccess(int code)Creates a simple success response with default "Success" message.static io.swagger.oas.inflector.models.ResponseContextsuccess(int code, Object obj)Creates a success response with an object as the response body.static io.swagger.oas.inflector.models.ResponseContextsuccess(int code, Object obj, boolean forceObjectIdAsObjects)Creates a success response with an object as the response body.static io.swagger.oas.inflector.models.ResponseContextsuccess(int code, String format, Object... arguments)Creates a success response with formatted message.static StringunwindCause(Throwable t)
-
-
-
Field Detail
-
APPLICATION_JSON_MEDIA_TYPE
public static final javax.ws.rs.core.MediaType APPLICATION_JSON_MEDIA_TYPE
-
APPLICATION_JSON
public static final String APPLICATION_JSON
-
APPLICATION_JSON_UTF8_MEDIA_TYPE
public static final javax.ws.rs.core.MediaType APPLICATION_JSON_UTF8_MEDIA_TYPE
-
APPLICATION_JSON_UTF8
public static final String APPLICATION_JSON_UTF8
-
-
Method Detail
-
error
public static io.swagger.oas.inflector.models.ResponseContext error(int code, String message)Creates an error response with the specified status code and message.- Parameters:
code- the HTTP error status code (e.g., 400, 404, 500)message- the error message text- Returns:
- ResponseContext for the error response
-
error
public static io.swagger.oas.inflector.models.ResponseContext error(int code, String format, Object... arguments)Creates an error response with formatted message.- Parameters:
code- the HTTP error status codeformat- the message format string with placeholdersarguments- the values for the placeholders- Returns:
- ResponseContext for the error response
-
error
public static io.swagger.oas.inflector.models.ResponseContext error(int code, Throwable cause, String message)Creates an error response with exception details.- Parameters:
code- the HTTP error status codecause- the exception that caused the errormessage- the error message text- Returns:
- ResponseContext for the error response
-
error
public static io.swagger.oas.inflector.models.ResponseContext error(int code, Throwable cause, String format, Object... arguments)Creates an error response with exception details and formatted message.- Parameters:
code- the HTTP error status codecause- the exception that caused the errorformat- the message format string with placeholdersarguments- the values for the placeholders- Returns:
- ResponseContext for the error response
-
success
public static io.swagger.oas.inflector.models.ResponseContext success(int code, String format, Object... arguments)Creates a success response with formatted message.- Parameters:
code- the HTTP success status code (e.g., 200, 201)format- the message format string with placeholdersarguments- the values for the placeholders- Returns:
- ResponseContext for the success response
-
success
public static io.swagger.oas.inflector.models.ResponseContext success(int code, Object obj)Creates a success response with an object as the response body. The object will be serialized to JSON.- Parameters:
code- the HTTP success status codeobj- the object to include in the response body- Returns:
- ResponseContext for the success response
-
success
public static io.swagger.oas.inflector.models.ResponseContext success(int code, Object obj, boolean forceObjectIdAsObjects)Creates a success response with an object as the response body. Provides control over ObjectId serialization format.- Parameters:
code- the HTTP success status codeobj- the object to include in the response bodyforceObjectIdAsObjects- if true, ObjectIds are serialized as objects; if false, they are serialized as strings- Returns:
- ResponseContext for the success response
-
success
public static io.swagger.oas.inflector.models.ResponseContext success(int code)
Creates a simple success response with default "Success" message.- Parameters:
code- the HTTP success status code- Returns:
- ResponseContext for the success response
-
makeResponse
public static io.swagger.oas.inflector.models.ResponseContext makeResponse(javax.ws.rs.core.Response.Status status, Object obj, String headerKey, String headerValue)
-
builder
public static Response.Builder builder()
Creates a builder for constructing a ResponseContext with chained method calls.- Returns:
- a new Builder instance
-
getMessage
public static String getMessage(io.swagger.oas.inflector.models.ResponseContext res)
-
-