Package jmri.server.json.schema
Class JsonSchemaServiceCache
java.lang.Object
jmri.server.json.schema.JsonSchemaServiceCache
- All Implemented Interfaces:
InstanceManagerAutoDefault
Cache for mapping
JsonHttpServices to types for
getting schemas.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncom.networknt.schema.JsonSchemagetClientSchema(String type, JsonRequest request) Get the client schema for JSON messages or for specific JSON data schema.getClientTypes(String version) Get the types of JSON messages expected from clients.com.networknt.schema.JsonSchemagetServerSchema(String type, JsonRequest request) Get the server schema for JSON messages or for specific JSON data schema.getServerTypes(String version) Get the types of JSON messages this application sends.getServices(String type, String version) Get the services known to this cache that support a specific JSON type.Get all types of JSON messages.voidvalidateData(String type, com.fasterxml.jackson.databind.JsonNode data, boolean server, JsonRequest request) Validate a JSON data object against the schema for JSON messages and data.voidvalidateMessage(com.fasterxml.jackson.databind.JsonNode message, boolean server, JsonRequest request) Validate a JSON message against the schema for JSON messages and data.
-
Constructor Details
-
JsonSchemaServiceCache
public JsonSchemaServiceCache()
-
-
Method Details
-
getServices
Get the services known to this cache that support a specific JSON type.- Parameters:
type- the JSON type requestedversion- the JSON protocol version requested- Returns:
- the supporting services or an empty set if none
- Throws:
NullPointerException- if version is not a known version
-
getTypes
Get all types of JSON messages.- Parameters:
version- the JSON protocol version- Returns:
- the union of the results from
getClientTypes(java.lang.String)andgetServerTypes(java.lang.String)
-
getClientTypes
Get the types of JSON messages expected from clients.- Parameters:
version- the JSON protocol version- Returns:
- the message types
-
getServerTypes
Get the types of JSON messages this application sends.- Parameters:
version- the JSON protocol version- Returns:
- the message types
-
getClientSchema
@Nonnull public com.networknt.schema.JsonSchema getClientSchema(@Nonnull String type, @Nonnull JsonRequest request) throws JsonException Get the client schema for JSON messages or for specific JSON data schema.- Parameters:
type- the type; useJSON.JSONto get the schema for messages, or any other value for a data schemarequest- the JSON request- Returns:
- the requested schema
- Throws:
JsonException- if unable to get schema due to errors processing schemaIllegalArgumentException- if no JSON service provides schemas for type
-
getServerSchema
@Nonnull public com.networknt.schema.JsonSchema getServerSchema(@Nonnull String type, @Nonnull JsonRequest request) throws JsonException Get the server schema for JSON messages or for specific JSON data schema.- Parameters:
type- the type; useJSON.JSONto get the schema for messages, or any other value for a data schemarequest- the JSON request- Returns:
- the requested schema
- Throws:
JsonException- if unable to get schema due to errors processing schemaIllegalArgumentException- if no JSON service provides schemas for type
-
validateMessage
public void validateMessage(@Nonnull com.fasterxml.jackson.databind.JsonNode message, boolean server, @Nonnull JsonRequest request) throws JsonException Validate a JSON message against the schema for JSON messages and data.- Parameters:
message- the message to validateserver- true if message is from the JSON server; false otherwiserequest- the JSON request- Throws:
JsonException- if the message does not validate
-
validateData
public void validateData(@Nonnull String type, @Nonnull com.fasterxml.jackson.databind.JsonNode data, boolean server, @Nonnull JsonRequest request) throws JsonException Validate a JSON data object against the schema for JSON messages and data.- Parameters:
type- the type of data objectdata- the data object to validateserver- true if message is from the JSON server; false otherwiserequest- the JSON request- Throws:
JsonException- if the message does not validate
-