Class 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 class  Response.Builder
      Builder class for creating ResponseContext instances with a fluent API.
    • Constructor Summary

      Constructors 
      Constructor Description
      Response()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static Response.Builder builder()
      Creates a builder for constructing a ResponseContext with chained method calls.
      static io.swagger.oas.inflector.models.ResponseContext error​(int code, String message)
      Creates an error response with the specified status code and message.
      static io.swagger.oas.inflector.models.ResponseContext error​(int code, String format, Object... arguments)
      Creates an error response with formatted message.
      static io.swagger.oas.inflector.models.ResponseContext error​(int code, Throwable cause, String message)
      Creates an error response with exception details.
      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.
      static String getMessage​(io.swagger.oas.inflector.models.ResponseContext res)  
      static io.swagger.oas.inflector.models.ResponseContext makeResponse​(javax.ws.rs.core.Response.Status status, Object obj, String headerKey, String headerValue)  
      static io.swagger.oas.inflector.models.ResponseContext success​(int code)
      Creates a simple success response with default "Success" message.
      static io.swagger.oas.inflector.models.ResponseContext success​(int code, Object obj)
      Creates a success response with an object as the response body.
      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.
      static io.swagger.oas.inflector.models.ResponseContext success​(int code, String format, Object... arguments)
      Creates a success response with formatted message.
      static String unwindCause​(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
    • Constructor Detail

      • Response

        public Response()
    • 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 code
        format - the message format string with placeholders
        arguments - 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 code
        cause - the exception that caused the error
        message - 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 code
        cause - the exception that caused the error
        format - the message format string with placeholders
        arguments - 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 placeholders
        arguments - 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 code
        obj - 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 code
        obj - the object to include in the response body
        forceObjectIdAsObjects - 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)