Class JsonNonProvidedNamedBeanHttpService<T extends NamedBean>

java.lang.Object
jmri.server.json.JsonHttpService
jmri.server.json.JsonNonProvidedNamedBeanHttpService<T>
Type Parameters:
T - the type supported by this service
Direct Known Subclasses:
JsonLayoutBlockHttpService, JsonNamedBeanHttpService, JsonSignalHeadHttpService

public abstract class JsonNonProvidedNamedBeanHttpService<T extends NamedBean>
extends JsonHttpService
Abstract implementation of JsonHttpService with specific support for NamedBean objects.

Note: if the extending class meets the requirements of JsonNamedBeanHttpService, it is recommended to extend that class instead.

  • Constructor Details

  • Method Details

    • doGetList

      @Nonnull protected final com.fasterxml.jackson.databind.JsonNode doGetList​(Manager<T> manager, String type, com.fasterxml.jackson.databind.JsonNode data, JsonRequest request) throws JsonException
      Respond to an HTTP GET request for a list of items of type.

      This is called by the JsonServlet to handle get requests for a type, but no name. Services that do not have named objects, such as the JsonTimeHttpService should respond to this with a list containing a single JSON object. Services that can't return a list may throw a 400 Bad Request JsonException in this case.

      Parameters:
      manager - the manager for the requested type
      type - the type of the requested list
      data - JSON object possibly containing filters to limit the list to
      request - the JSON request
      Returns:
      a JSON list
      Throws:
      JsonException - may be thrown by concrete implementations
    • doGetList

      @Nonnull protected final com.fasterxml.jackson.databind.JsonNode doGetList​(Manager<T> manager, String type, com.fasterxml.jackson.databind.JsonNode data, Locale locale, int id) throws JsonException
      Respond to an HTTP GET request for a list of items of type.

      This is called by the JsonServlet to handle get requests for a type, but no name. Services that do not have named objects, such as the JsonTimeHttpService should respond to this with a list containing a single JSON object. Services that can't return a list may throw a 400 Bad Request JsonException in this case.

      Parameters:
      manager - the manager for the requested type
      type - the type of the requested list
      data - JSON object possibly containing filters to limit the list to
      locale - the requesting client's Locale
      id - the message id set by the client
      Returns:
      a JSON list
      Throws:
      JsonException - may be thrown by concrete implementations
    • doGet

      @Nonnull protected abstract com.fasterxml.jackson.databind.node.ObjectNode doGet​(T bean, @Nonnull String name, @Nonnull String type, @Nonnull JsonRequest request) throws JsonException
      Respond to an HTTP GET request for the requested name.

      If name is null, return a list of all objects for the given type, if appropriate.

      This method should throw a 500 Internal Server Error if type is not recognized.

      Parameters:
      bean - the requested object
      name - the name of the requested object
      type - the type of the requested object
      request - the JSON request
      Returns:
      a JSON description of the requested object
      Throws:
      JsonException - if the named object does not exist or other error occurs
    • doGet

      @Deprecated @Nonnull protected com.fasterxml.jackson.databind.node.ObjectNode doGet​(T bean, @Nonnull String name, @Nonnull String type, @Nonnull Locale locale, int id) throws JsonException
      Deprecated.
      Respond to an HTTP GET request for the requested name.

      If name is null, return a list of all objects for the given type, if appropriate.

      This method should throw a 500 Internal Server Error if type is not recognized.

      Parameters:
      bean - the requested object
      name - the name of the requested object
      type - the type of the requested object
      locale - the requesting client's Locale
      id - the message id set by the client
      Returns:
      a JSON description of the requested object
      Throws:
      JsonException - if the named object does not exist or other error occurs
    • getNamedBean

      @CheckForNull protected abstract T getNamedBean​(@Nonnull String type, @Nonnull String name, @Nonnull com.fasterxml.jackson.databind.JsonNode data, @Nonnull JsonRequest request) throws JsonException
      Get the NamedBean matching name and type. If the request has a method other than GET, this may modify or create the NamedBean requested. Note that name or data may be null, but it is an error to have both be null.
      Parameters:
      name - the name of the requested object
      type - the type of the requested object
      data - the JsonNode containing the JSON representation of the bean to get
      request - the JSON request
      Returns:
      the matching NamedBean or null if there is no match
      Throws:
      JsonException - if the name is invalid for the type
      IllegalArgumentException - if both name is null and data is empty
    • getNamedBean

      @Nonnull public com.fasterxml.jackson.databind.node.ObjectNode getNamedBean​(T bean, @Nonnull String name, @Nonnull String type, @Nonnull JsonRequest request) throws JsonException
      Create the JsonNode for a NamedBean object.
      Parameters:
      bean - the bean to create the node for
      name - the name of the bean; used only if the bean is null
      type - the JSON type of the bean
      request - the JSON request
      Returns:
      a JSON node
      Throws:
      JsonException - if the bean is null
    • getNamedBean

      @Deprecated @Nonnull protected com.fasterxml.jackson.databind.node.ObjectNode getNamedBean​(T bean, @Nonnull String name, @Nonnull String type, @Nonnull Locale locale, int id) throws JsonException
      Deprecated.
      Create the JsonNode for a NamedBean object.
      Parameters:
      bean - the bean to create the node for
      name - the name of the bean; used only if the bean is null
      type - the JSON type of the bean
      locale - the locale used for any error messages
      id - the message id set by the client
      Returns:
      a JSON node
      Throws:
      JsonException - if the bean is null
    • postNamedBean

      @Nonnull protected T postNamedBean​(T bean, @Nonnull com.fasterxml.jackson.databind.JsonNode data, @Nonnull String name, @Nonnull String type, @Nonnull JsonRequest request) throws JsonException
      Handle the common elements of a NamedBean that can be changed in an POST message.

      Note: the system name of a NamedBean cannot be changed using this method.

      Parameters:
      bean - the bean to modify
      data - the JsonNode containing the JSON representation of bean
      name - the system name of the bean
      type - the JSON type of the bean
      request - the JSON request
      Returns:
      the bean so that this can be used in a method chain
      Throws:
      JsonException - if the bean is null
    • postNamedBean

      @Deprecated @Nonnull protected T postNamedBean​(T bean, @Nonnull com.fasterxml.jackson.databind.JsonNode data, @Nonnull String name, @Nonnull String type, @Nonnull Locale locale, int id) throws JsonException
      Handle the common elements of a NamedBean that can be changed in an POST message.

      Note: the system name of a NamedBean cannot be changed using this method.

      Parameters:
      bean - the bean to modify
      data - the JsonNode containing the JSON representation of bean
      name - the system name of the bean
      type - the JSON type of the bean
      locale - the locale used for any error messages
      id - the message id set by the client
      Returns:
      the bean so that this can be used in a method chain
      Throws:
      JsonException - if the bean is null