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 forNamedBeanobjects.Note: if the extending class meets the requirements of
JsonNamedBeanHttpService, it is recommended to extend that class instead.
-
-
Field Summary
-
Fields inherited from class jmri.server.json.JsonHttpService
mapper
-
-
Constructor Summary
Constructors Constructor Description JsonNonProvidedNamedBeanHttpService(com.fasterxml.jackson.databind.ObjectMapper mapper)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract com.fasterxml.jackson.databind.node.ObjectNodedoGet(T bean, java.lang.String name, java.lang.String type, JsonRequest request)Respond to an HTTP GET request for the requested name.protected com.fasterxml.jackson.databind.JsonNodedoGetList(Manager<T> manager, java.lang.String type, com.fasterxml.jackson.databind.JsonNode data, java.util.Locale locale, int id)Respond to an HTTP GET request for a list of items of type.protected com.fasterxml.jackson.databind.JsonNodedoGetList(Manager<T> manager, java.lang.String type, com.fasterxml.jackson.databind.JsonNode data, JsonRequest request)Respond to an HTTP GET request for a list of items of type.protected abstract TgetNamedBean(java.lang.String type, java.lang.String name, com.fasterxml.jackson.databind.JsonNode data, JsonRequest request)Get the NamedBean matching name and type.com.fasterxml.jackson.databind.node.ObjectNodegetNamedBean(T bean, java.lang.String name, java.lang.String type, JsonRequest request)Create the JsonNode for aNamedBeanobject.protected TpostNamedBean(T bean, com.fasterxml.jackson.databind.JsonNode data, java.lang.String name, java.lang.String type, JsonRequest request)Handle the common elements of a NamedBean that can be changed in an POST message.-
Methods inherited from class jmri.server.json.JsonHttpService
acceptForceDeleteToken, doDelete, doGet, doGetList, doPost, doPut, doSchema, doSchema, doSchema, getObjectMapper, message, message, message, message, message, throwDeleteConflictException
-
-
-
-
Constructor Detail
-
JsonNonProvidedNamedBeanHttpService
public JsonNonProvidedNamedBeanHttpService(com.fasterxml.jackson.databind.ObjectMapper mapper)
-
-
Method Detail
-
doGetList
@Nonnull protected final com.fasterxml.jackson.databind.JsonNode doGetList(Manager<T> manager, java.lang.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
JsonServletto handle get requests for a type, but no name. Services that do not have named objects, such as theJsonTimeHttpServiceshould 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 typetype- the type of the requested listdata- JSON object possibly containing filters to limit the list torequest- 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, java.lang.String type, com.fasterxml.jackson.databind.JsonNode data, java.util.Locale locale, int id) throws JsonException
Respond to an HTTP GET request for a list of items of type.This is called by the
JsonServletto handle get requests for a type, but no name. Services that do not have named objects, such as theJsonTimeHttpServiceshould 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 typetype- the type of the requested listdata- JSON object possibly containing filters to limit the list tolocale- the requesting client's Localeid- 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 java.lang.String name, @Nonnull java.lang.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 objectname- the name of the requested objecttype- the type of the requested objectrequest- the JSON request- 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 java.lang.String type, @Nonnull java.lang.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 objecttype- the type of the requested objectdata- the JsonNode containing the JSON representation of the bean to getrequest- the JSON request- Returns:
- the matching NamedBean or null if there is no match
- Throws:
JsonException- if the name is invalid for the typejava.lang.IllegalArgumentException- if both name is null and data is empty
-
getNamedBean
@Nonnull public com.fasterxml.jackson.databind.node.ObjectNode getNamedBean(T bean, @Nonnull java.lang.String name, @Nonnull java.lang.String type, @Nonnull JsonRequest request) throws JsonException
Create the JsonNode for aNamedBeanobject.- Parameters:
bean- the bean to create the node forname- the name of the bean; used only if the bean is nulltype- the JSON type of the beanrequest- the JSON request- 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 java.lang.String name, @Nonnull java.lang.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 modifydata- the JsonNode containing the JSON representation of beanname- the system name of the beantype- the JSON type of the beanrequest- the JSON request- Returns:
- the bean so that this can be used in a method chain
- Throws:
JsonException- if the bean is null
-
-