Class JsonRouteHttpService
public class JsonRouteHttpService extends JsonNamedBeanHttpService<Route>
Route
s.-
Field Summary
-
Constructor Summary
Constructors Constructor Description JsonRouteHttpService(com.fasterxml.jackson.databind.ObjectMapper mapper)
-
Method Summary
Modifier and Type Method Description com.fasterxml.jackson.databind.node.ObjectNode
doGet(Route route, String name, String type, JsonRequest request)
Respond to an HTTP GET request for the requested name.com.fasterxml.jackson.databind.node.ObjectNode
doPost(Route route, String name, String type, com.fasterxml.jackson.databind.JsonNode data, JsonRequest request)
Respond to an HTTP POST request for the requested route.com.fasterxml.jackson.databind.JsonNode
doPut(String type, String name, com.fasterxml.jackson.databind.JsonNode data, JsonRequest request)
Respond to an HTTP PUT request for the requested name.com.fasterxml.jackson.databind.JsonNode
doSchema(String type, boolean server, JsonRequest request)
Get the JSON Schema for thedata
property of the requested type of JSON object.protected ProvidingManager<Route>
getManager()
Get the expected manager for the supported JSON type.protected String
getType()
Get the JSON type supported by this service.Methods inherited from class jmri.server.json.JsonNamedBeanHttpService
deleteBean, deleteBean, doDelete, doDelete, doDelete, doGet, doGetList, doPost, doPost, getNamedBean
Methods inherited from class jmri.server.json.JsonNonProvidedNamedBeanHttpService
doGet, doGetList, doGetList, getNamedBean, getNamedBean, postNamedBean, postNamedBean
Methods inherited from class jmri.server.json.JsonHttpService
acceptForceDeleteToken, doDelete, doGet, doGetList, doPost, doPut, doSchema, doSchema, doSchema, getObjectMapper, message, message, message, message, message, throwDeleteConflictException, throwDeleteConflictException
-
Constructor Details
-
Method Details
-
doGet
public com.fasterxml.jackson.databind.node.ObjectNode doGet(Route route, String name, String type, JsonRequest request) throws JsonExceptionDescription copied from class:JsonNamedBeanHttpService
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.
- Specified by:
doGet
in classJsonNamedBeanHttpService<Route>
- Parameters:
route
- 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
-
doPost
public com.fasterxml.jackson.databind.node.ObjectNode doPost(Route route, String name, String type, com.fasterxml.jackson.databind.JsonNode data, JsonRequest request) throws JsonExceptionRespond to an HTTP POST request for the requested route.This method throws a 404 Not Found error if the named route does not exist.
Note: attempting to set a state of
JSON.INACTIVE
orJSON.UNKNOWN
has no effect. Setting a state ofJSON.TOGGLE
has the same effect as setting a state ofJSON.ACTIVE
. Any other states throw a 400 Invalid Request error.- Specified by:
doPost
in classJsonNamedBeanHttpService<Route>
- Parameters:
type
- one ofJsonRouteServiceFactory.ROUTE
orJsonRouteServiceFactory.ROUTES
name
- the name of the requested routedata
- JSON data set of attributes of the requested route to be updatedrequest
- the JSON requestroute
- the requested object- Returns:
- a JSON description of the requested route. Since a route changes state on a separate thread, this may return a route in the state prior to this call, the target state, or an intermediate state.
- Throws:
JsonException
- if an error occurs
-
doPut
public com.fasterxml.jackson.databind.JsonNode doPut(String type, String name, com.fasterxml.jackson.databind.JsonNode data, JsonRequest request) throws JsonExceptionDescription copied from class:JsonNamedBeanHttpService
Respond to an HTTP PUT request for the requested name.Throw an HTTP 405 Method Not Allowed exception if new objects of the type are not intended to be addable. Override if the implementing class needs to prevent PUT methods from functioning or need to perform additional validation prior to creating the NamedBean.
- Overrides:
doPut
in classJsonNamedBeanHttpService<Route>
- Parameters:
type
- the type of the requested objectname
- the system name of the requested objectdata
- JSON data set of attributes of the requested object to be created or updatedrequest
- the JSON request- Returns:
- a JSON description of the requested object
- Throws:
JsonException
- if the method is not allowed or other error occurs
-
doSchema
public com.fasterxml.jackson.databind.JsonNode doSchema(String type, boolean server, JsonRequest request) throws JsonExceptionDescription copied from class:JsonHttpService
Get the JSON Schema for thedata
property of the requested type of JSON object. It is a invalid for implementations to not return a valid schema that clients can use to validate a request to or response from the JSON services.Note that a schema must be contained in a standard object as:
{"type":"schema", "data":{"schema":<em>schema</em>, "server":boolean}}
If using
JsonHttpService.doSchema(String, boolean, String, String, int)
, an implementation can be as simple as:return doSchema(type, server, "path/to/client/schema.json", "path/to/server/schema.json", id);
- Specified by:
doSchema
in classJsonHttpService
- Parameters:
type
- the type for which a schema is requestedserver
- true if the schema is for a message from the server; false if the schema is for a message from the clientrequest
- the JSON request- Returns:
- a JSON Schema valid for the type
- Throws:
JsonException
- if an error occurs preparing schema; if type is is not a type handled by this service, this must be thrown with an error code of 500 and the localized message ERROR_UNKNOWN_TYPE
-
getType
Description copied from class:JsonNamedBeanHttpService
Get the JSON type supported by this service.- Specified by:
getType
in classJsonNamedBeanHttpService<Route>
- Returns:
- the JSON type
-
getManager
Description copied from class:JsonNamedBeanHttpService
Get the expected manager for the supported JSON type. This should normally be the default manager.- Specified by:
getManager
in classJsonNamedBeanHttpService<Route>
- Returns:
- the manager
-