Class JsonUtilHttpService
- java.lang.Object
-
- jmri.server.json.JsonHttpService
-
- jmri.server.json.util.JsonUtilHttpService
-
public class JsonUtilHttpService extends JsonHttpService
-
-
Field Summary
-
Fields inherited from class jmri.server.json.JsonHttpService
mapper
-
-
Constructor Summary
Constructors Constructor Description JsonUtilHttpService(com.fasterxml.jackson.databind.ObjectMapper mapper)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static DccLocoAddress
addressForString(java.lang.String address)
com.fasterxml.jackson.databind.JsonNode
doGet(java.lang.String type, java.lang.String name, com.fasterxml.jackson.databind.JsonNode data, JsonRequest request)
Respond to an HTTP GET request for the requested name.com.fasterxml.jackson.databind.node.ArrayNode
doGetList(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.com.fasterxml.jackson.databind.JsonNode
doPost(java.lang.String type, java.lang.String name, com.fasterxml.jackson.databind.JsonNode data, JsonRequest request)
Respond to an HTTP POST request for the requested name.com.fasterxml.jackson.databind.JsonNode
doSchema(java.lang.String type, boolean server, JsonRequest request)
Get the JSON Schema for thedata
property of the requested type of JSON object.com.fasterxml.jackson.databind.JsonNode
getConfigProfile(java.lang.String name, JsonRequest request)
Get the named configuration profile.com.fasterxml.jackson.databind.node.ArrayNode
getConfigProfiles(JsonRequest request)
Get a JSON array of all configuration profiles.com.fasterxml.jackson.databind.JsonNode
getHello(int heartbeat, JsonRequest request)
Send a JSONJSON.HELLO
message.com.fasterxml.jackson.databind.JsonNode
getMetadata(java.lang.String name, JsonRequest request)
Get a JSON message with a metadata element fromMetadata
.com.fasterxml.jackson.databind.JsonNode
getMetadata(java.util.Locale locale, java.lang.String name, int id)
Get a JSON message with a metadata element fromMetadata
.com.fasterxml.jackson.databind.node.ArrayNode
getMetadata(JsonRequest request)
Get a JSON array of metadata elements as listed byMetadata.getSystemNameList()
.com.fasterxml.jackson.databind.JsonNode
getNetworkService(java.lang.String name, JsonRequest request)
Get a runningZeroConfService
using the protocol as the name of the service.com.fasterxml.jackson.databind.node.ArrayNode
getNetworkServices(java.util.Locale locale, int id)
com.fasterxml.jackson.databind.node.ArrayNode
getNetworkServices(JsonRequest request)
com.fasterxml.jackson.databind.JsonNode
getNode(JsonRequest request)
Send a JSONJSON.NODE
message containing the JMRI node identity and former identities.com.fasterxml.jackson.databind.JsonNode
getPanel(java.util.Locale locale, java.lang.String name, int id)
return a JSONJSON.NODE
message containing the requested panel detailscom.fasterxml.jackson.databind.node.ObjectNode
getPanel(Editor editor, java.lang.String format, int id)
com.fasterxml.jackson.databind.node.ArrayNode
getPanels(int id)
com.fasterxml.jackson.databind.node.ArrayNode
getPanels(java.lang.String format, int id)
com.fasterxml.jackson.databind.JsonNode
getRailroad(JsonRequest request)
return a JSONJSON.NODE
message containing the Railroad from the Railroad Name preferences.com.fasterxml.jackson.databind.JsonNode
getSystemConnection(java.lang.String name, JsonRequest request)
return a JSONJSON.NODE
message containing the requested systemConnection detailscom.fasterxml.jackson.databind.node.ArrayNode
getSystemConnections(JsonRequest request)
return a JSON array containing the defined system connectionscom.fasterxml.jackson.databind.JsonNode
getVersion()
-
Methods inherited from class jmri.server.json.JsonHttpService
acceptForceDeleteToken, doDelete, doPut, doSchema, doSchema, getObjectMapper, message, message, message, message, message, throwDeleteConflictException
-
-
-
-
Constructor Detail
-
JsonUtilHttpService
public JsonUtilHttpService(com.fasterxml.jackson.databind.ObjectMapper mapper)
-
-
Method Detail
-
doGet
public com.fasterxml.jackson.databind.JsonNode doGet(java.lang.String type, @CheckForNull java.lang.String name, com.fasterxml.jackson.databind.JsonNode data, JsonRequest request) throws JsonException
Description copied from class:JsonHttpService
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 classJsonHttpService
- Parameters:
type
- the type of the requested objectname
- the system name of the requested objectdata
- JSON data set of attributes 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
-
doGetList
public com.fasterxml.jackson.databind.node.ArrayNode doGetList(java.lang.String type, com.fasterxml.jackson.databind.JsonNode data, JsonRequest request) throws JsonException
Description copied from class:JsonHttpService
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 theJsonTimeHttpService
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.- Specified by:
doGetList
in classJsonHttpService
- Parameters:
type
- the type of the requested listdata
- JSON data set of attributes of the requested objectsrequest
- the JSON request- Returns:
- a JSON list or message containing type "list", the list as data, and the passed in id
- Throws:
JsonException
- may be thrown by concrete implementations
-
doPost
public com.fasterxml.jackson.databind.JsonNode doPost(java.lang.String type, @CheckForNull java.lang.String name, com.fasterxml.jackson.databind.JsonNode data, JsonRequest request) throws JsonException
Description copied from class:JsonHttpService
Respond to an HTTP POST request for the requested name.This method should throw a 400 Invalid Request error if the named object does not exist.
- Specified by:
doPost
in classJsonHttpService
- 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 updatedrequest
- the JSON request- Returns:
- a JSON description of the requested object after updates have been applied
- Throws:
JsonException
- if the named object does not exist or other error occurs
-
getVersion
public com.fasterxml.jackson.databind.JsonNode getVersion() throws JsonException
- Returns:
- JSON map of complete versions and URL part for protocols
- Throws:
JsonException
- if a protocol version is not available
-
getHello
public com.fasterxml.jackson.databind.JsonNode getHello(int heartbeat, @Nonnull JsonRequest request)
Send a JSONJSON.HELLO
message.- Parameters:
heartbeat
- seconds in which a client must send a message before its connection is brokenrequest
- the JSON request- Returns:
- the JSON hello message
-
getMetadata
public com.fasterxml.jackson.databind.JsonNode getMetadata(@Nonnull java.lang.String name, @Nonnull JsonRequest request) throws JsonException
Get a JSON message with a metadata element fromMetadata
.- Parameters:
name
- The metadata element to getrequest
- the JSON request- Returns:
- JSON metadata element
- Throws:
JsonException
- if name is not a recognized metadata element
-
getMetadata
public com.fasterxml.jackson.databind.JsonNode getMetadata(java.util.Locale locale, java.lang.String name, int id) throws JsonException
Get a JSON message with a metadata element fromMetadata
.- Parameters:
locale
- The client's Locale.name
- The metadata element to get.id
- message id set by client- Returns:
- JSON metadata element.
- Throws:
JsonException
- if name is not a recognized metadata element.
-
getMetadata
public com.fasterxml.jackson.databind.node.ArrayNode getMetadata(@Nonnull JsonRequest request) throws JsonException
Get a JSON array of metadata elements as listed byMetadata.getSystemNameList()
.- Parameters:
request
- the JSON request- Returns:
- Array of JSON metadata elements
- Throws:
JsonException
- if thrown bygetMetadata(java.util.Locale, java.lang.String, int)
-
getNetworkService
public com.fasterxml.jackson.databind.JsonNode getNetworkService(@Nonnull java.lang.String name, @Nonnull JsonRequest request) throws JsonException
Get a runningZeroConfService
using the protocol as the name of the service.- Parameters:
name
- the service protocolrequest
- the JSON request- Returns:
- the JSON networkService message
- Throws:
JsonException
- if type is not a running zeroconf networking protocol
-
getNetworkServices
public com.fasterxml.jackson.databind.node.ArrayNode getNetworkServices(@Nonnull JsonRequest request)
- Parameters:
request
- the JSON request- Returns:
- the JSON networkServices message.
-
getNetworkServices
public com.fasterxml.jackson.databind.node.ArrayNode getNetworkServices(java.util.Locale locale, int id)
- Parameters:
locale
- the client's Locale.id
- message id set by client- Returns:
- the JSON networkServices message.
-
getNode
public com.fasterxml.jackson.databind.JsonNode getNode(JsonRequest request)
Send a JSONJSON.NODE
message containing the JMRI node identity and former identities.- Parameters:
request
- the JSON request- Returns:
- the JSON node message
- See Also:
NodeIdentity
-
getPanel
public com.fasterxml.jackson.databind.JsonNode getPanel(java.util.Locale locale, java.lang.String name, int id) throws JsonException
return a JSONJSON.NODE
message containing the requested panel details- Parameters:
locale
- the client's Localename
- panel name to returnid
- message id set by client- Returns:
- the JSON panel message.
- Throws:
JsonException
- if panel not found
-
getPanel
public com.fasterxml.jackson.databind.node.ObjectNode getPanel(Editor editor, java.lang.String format, int id)
-
getPanels
public com.fasterxml.jackson.databind.node.ArrayNode getPanels(java.lang.String format, int id)
-
getPanels
public com.fasterxml.jackson.databind.node.ArrayNode getPanels(int id)
-
getRailroad
public com.fasterxml.jackson.databind.JsonNode getRailroad(@Nonnull JsonRequest request)
return a JSONJSON.NODE
message containing the Railroad from the Railroad Name preferences.- Parameters:
request
- the JSON request- Returns:
- the JSON railroad name message
-
getSystemConnection
public com.fasterxml.jackson.databind.JsonNode getSystemConnection(java.lang.String name, JsonRequest request) throws JsonException
return a JSONJSON.NODE
message containing the requested systemConnection details- Parameters:
name
- system connection name to returnrequest
- the JSON request- Returns:
- the JSON systemConnections message
- Throws:
JsonException
- if systemConnection not found
-
getSystemConnections
public com.fasterxml.jackson.databind.node.ArrayNode getSystemConnections(@Nonnull JsonRequest request)
return a JSON array containing the defined system connections- Parameters:
request
- the JSON request- Returns:
- the JSON systemConnections message.
-
getConfigProfile
public com.fasterxml.jackson.databind.JsonNode getConfigProfile(@Nonnull java.lang.String name, @Nonnull JsonRequest request) throws JsonException
Get the named configuration profile.- Parameters:
name
- the Profile namerequest
- the JSON request- Returns:
- the JSON configProfiles message
- Throws:
JsonException
- if the requested configProfile is not found
-
getConfigProfiles
public com.fasterxml.jackson.databind.node.ArrayNode getConfigProfiles(@Nonnull JsonRequest request)
Get a JSON array of all configuration profiles.- Parameters:
request
- the JSON request- Returns:
- the JSON configProfiles message
-
addressForString
public static DccLocoAddress addressForString(java.lang.String address)
Gets theDccLocoAddress
for a String in the formnumber(type)
ornumber
.Type may be
L
for long orS
for short. If the type is not specified, type is assumed to be short.- Parameters:
address
- the address- Returns:
- The DccLocoAddress for address
-
doSchema
public com.fasterxml.jackson.databind.JsonNode doSchema(java.lang.String type, boolean server, JsonRequest request) throws JsonException
Description 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
-
-