Class JKAbstractRestController

java.lang.Object
com.jk.services.server.JKAbstractRestController
Direct Known Subclasses:
JKCacheService, JKConfigService, JKHeadersService, JKHiService, JKInfoService, JKLogCrossCuttingService, JKLogService, JKPingService

@Consumes("application/json") @Produces("application/json") public class JKAbstractRestController extends Object
This class is a base class for REST controllers that provides common functionality and utility methods.

This class includes methods for handling HTTP requests, accessing request headers, and returning HTTP responses with appropriate status codes.

Version:
1.0
Author:
Dr. Jalal H. Kiswani
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected JKLogger
    Represents the class logger.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected jakarta.ws.rs.core.Response
    This method generates an HTTP response with an accepted status code and includes the provided model as the response entity.
    protected jakarta.ws.rs.core.Response
    This method generates an HTTP response with a bad request status code (HTTP 400 Bad Request) and includes the provided entity as the response entity.
    protected jakarta.ws.rs.core.Response
    forbidden(Object entity)
    This method generates an HTTP response with a forbidden status code (HTTP 403 Forbidden) and includes the provided entity as the response entity.
    This method gets the header.
    This method retrieves the remote IP address of the client making the request.
    This method retrieves the remote role associated with the request.
    This method retrieves the remote user associated with the request.
    This method gets the tenant identifier (ID).
    protected jakarta.ws.rs.core.Response
    This method generates an HTTP response with an internal server error status code (HTTP 500 Internal Server Error) and includes the provided entity as the response entity.
    protected jakarta.ws.rs.core.Response
    notFound(Object entity)
    This method generates an HTTP response with a not found status code (HTTP 404 Not Found) and includes the provided entity as the response entity.
    protected jakarta.ws.rs.core.Response
    ok(Object model)
    This method generates an HTTP response with a status code and includes the provided model as the response entity.
    protected jakarta.ws.rs.core.Response
    status(jakarta.ws.rs.core.Response.Status status, Object entity)
    This method generates an HTTP response with the specified HTTP status code and includes the provided entity as the response entity.
    protected jakarta.ws.rs.core.Response
    This method generates an HTTP response with an unauthorized status code (HTTP 401 Unauthorized) and includes the provided entity as the response entity.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • logger

      protected JKLogger logger
      Represents the class logger.
  • Constructor Details

    • JKAbstractRestController

      public JKAbstractRestController()
  • Method Details

    • getRemoteIp

      public String getRemoteIp()
      This method retrieves the remote IP address of the client making the request.
      Returns:
      the remote IP address as a string.
    • getRemoteUser

      public String getRemoteUser()
      This method retrieves the remote user associated with the request.
      Returns:
      the remote user.
    • getRemoteRole

      public String getRemoteRole()
      This method retrieves the remote role associated with the request.
      Returns:
      the remote role.
    • ok

      protected jakarta.ws.rs.core.Response ok(Object model)
      This method generates an HTTP response with a status code and includes the provided model as the response entity.
      Parameters:
      model - Specifies the representation entity data.
      Returns:
      the response with a status code and the provided model as the entity.
    • accepted

      protected jakarta.ws.rs.core.Response accepted(Object model)
      This method generates an HTTP response with an accepted status code and includes the provided model as the response entity.
      Parameters:
      model - Specifies the representation entity data.
      Returns:
      the response with an accepted status code and the provided model as the entity.
    • notFound

      protected jakarta.ws.rs.core.Response notFound(Object entity)
      This method generates an HTTP response with a not found status code (HTTP 404 Not Found) and includes the provided entity as the response entity.
      Parameters:
      entity - Specifies the representation entity data.
      Returns:
      the response with a status code and the provided entity.
    • badRequest

      protected jakarta.ws.rs.core.Response badRequest(Object entity)
      This method generates an HTTP response with a bad request status code (HTTP 400 Bad Request) and includes the provided entity as the response entity.
      Parameters:
      entity - Specifies the representation entity data.
      Returns:
      the response with a status code and the provided entity.
    • unauthorized

      protected jakarta.ws.rs.core.Response unauthorized(Object entity)
      This method generates an HTTP response with an unauthorized status code (HTTP 401 Unauthorized) and includes the provided entity as the response entity.
      Parameters:
      entity - Specifies the representation entity data.
      Returns:
      the response with a status code and the provided entity.
    • forbidden

      protected jakarta.ws.rs.core.Response forbidden(Object entity)
      This method generates an HTTP response with a forbidden status code (HTTP 403 Forbidden) and includes the provided entity as the response entity.
      Parameters:
      entity - Specifies the representation entity data.
      Returns:
      the response with a status code and the provided entity.
    • interalServerError

      protected jakarta.ws.rs.core.Response interalServerError(Object entity)
      This method generates an HTTP response with an internal server error status code (HTTP 500 Internal Server Error) and includes the provided entity as the response entity.
      Parameters:
      entity - Specifies the representation entity data.
      Returns:
      the response with a status code and the provided entity.
    • status

      protected jakarta.ws.rs.core.Response status(jakarta.ws.rs.core.Response.Status status, Object entity)
      This method generates an HTTP response with the specified HTTP status code and includes the provided entity as the response entity.
      Parameters:
      status - Specifies the HTTP status code to set for the response.
      entity - Specifies the representation entity data.
      Returns:
      the response with the provided status code and entity.
    • getHeader

      public String getHeader(String name)
      This method gets the header.
      Parameters:
      name - Specifies the name.
      Returns:
      the header.
    • getTenantId

      public String getTenantId()
      This method gets the tenant identifier (ID).
      Returns:
      the tenant identifier (ID).