Class JsonUtilHttpService

    • Method Detail

      • doGet

        public JsonNode doGet​(java.lang.String type,
                              @CheckForNull
                              java.lang.String name,
                              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 class JsonHttpService
        Parameters:
        type - the type of the requested object
        name - the system name of the requested object
        data - JSON data set of attributes 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
      • doGetList

        public ArrayNode doGetList​(java.lang.String type,
                                   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 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.

        Specified by:
        doGetList in class JsonHttpService
        Parameters:
        type - the type of the requested list
        data - JSON data set of attributes of the requested objects
        request - 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 JsonNode doPost​(java.lang.String type,
                               @CheckForNull
                               java.lang.String name,
                               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 class JsonHttpService
        Parameters:
        type - the type of the requested object
        name - the system name of the requested object
        data - JSON data set of attributes of the requested object to be updated
        request - 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
      • getHello

        public JsonNode getHello​(int heartbeat,
                                 @Nonnull
                                 JsonRequest request)
        Send a JSON JSON.HELLO message.
        Parameters:
        heartbeat - seconds in which a client must send a message before its connection is broken
        request - the JSON request
        Returns:
        the JSON hello message
      • getMetadata

        public JsonNode getMetadata​(java.util.Locale locale,
                                    java.lang.String name,
                                    int id)
                             throws JsonException
        Get a JSON message with a metadata element from Metadata.
        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.
      • getNetworkServices

        public 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 JsonNode getNode​(JsonRequest request)
        Send a JSON JSON.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 JsonNode getPanel​(java.util.Locale locale,
                                 java.lang.String name,
                                 int id)
                          throws JsonException
        return a JSON JSON.NODE message containing the requested panel details
        Parameters:
        locale - the client's Locale
        name - panel name to return
        id - message id set by client
        Returns:
        the JSON panel message.
        Throws:
        JsonException - if panel not found
      • getRailroad

        public JsonNode getRailroad​(@Nonnull
                                    JsonRequest request)
        return a JSON JSON.NODE message containing the Railroad from the Railroad Name preferences.
        Parameters:
        request - the JSON request
        Returns:
        the JSON railroad name message
      • getSystemConnection

        public JsonNode getSystemConnection​(java.lang.String name,
                                            JsonRequest request)
                                     throws JsonException
        return a JSON JSON.NODE message containing the requested systemConnection details
        Parameters:
        name - system connection name to return
        request - the JSON request
        Returns:
        the JSON systemConnections message
        Throws:
        JsonException - if systemConnection not found
      • getSystemConnections

        public ArrayNode getSystemConnections​(@Nonnull
                                              JsonRequest request)
        return a JSON array containing the defined system connections
        Parameters:
        request - the JSON request
        Returns:
        the JSON systemConnections message.
      • addressForString

        public static DccLocoAddress addressForString​(java.lang.String address)
        Gets the DccLocoAddress for a String in the form number(type) or number.

        Type may be L for long or S 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 JsonNode doSchema​(java.lang.String type,
                                 boolean server,
                                 JsonRequest request)
                          throws JsonException
        Description copied from class: JsonHttpService
        Get the JSON Schema for the data 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 class JsonHttpService
        Parameters:
        type - the type for which a schema is requested
        server - true if the schema is for a message from the server; false if the schema is for a message from the client
        request - 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