Class JsonServlet

  • All Implemented Interfaces:, javax.servlet.Servlet, javax.servlet.ServletConfig

    public class JsonServlet
    extends org.eclipse.jetty.websocket.servlet.WebSocketServlet
    Provide JSON formatted responses to requests for information from the JMRI Web Server.

    See jmri.server.json for details on how this Servlet handles JSON requests.

    See Also:
    Serialized Form
    • Constructor Summary

      Constructor Description
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void configure​(org.eclipse.jetty.websocket.servlet.WebSocketServletFactory factory)  
      protected void doDelete​(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)  
      protected void doGet​(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
      Handle HTTP get requests for JSON data.
      protected void doPost​(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)  
      protected void doPut​(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)  
      void init()  
      (package private) void superInit()
      Package private method to call WebSocketServlet.init() so this call can be mocked out in unit tests.
      • Methods inherited from class org.eclipse.jetty.websocket.servlet.WebSocketServlet

        destroy, service
      • Methods inherited from class javax.servlet.http.HttpServlet

        doHead, doOptions, doTrace, getLastModified, service
      • Methods inherited from class javax.servlet.GenericServlet

        getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • init

        public void init()
                  throws javax.servlet.ServletException
        init in class org.eclipse.jetty.websocket.servlet.WebSocketServlet
      • superInit

        void superInit()
                throws javax.servlet.ServletException
        Package private method to call WebSocketServlet.init() so this call can be mocked out in unit tests.
        javax.servlet.ServletException - if unable to initialize server
      • configure

        public void configure​(org.eclipse.jetty.websocket.servlet.WebSocketServletFactory factory)
        Specified by:
        configure in class org.eclipse.jetty.websocket.servlet.WebSocketServlet
      • doGet

        protected void doGet​(javax.servlet.http.HttpServletRequest request,
                             javax.servlet.http.HttpServletResponse response)
        Handle HTTP get requests for JSON data. Examples:
        • /json/v5/sensor/IS22 (return data for sensor with system name "IS22")
        • /json/v5/sensor (returns a list of all sensors known to JMRI)
        sample responses:
        • {"type":"sensor","data":{"name":"IS22","userName":"FarEast","comment":null,"inverted":false,"state":4}}
        • [{"type":"sensor","data":{"name":"IS22","userName":"FarEast","comment":null,"inverted":false,"state":4}}]
        Note that data will vary for each type. Note that if an array is returned when requesting a single object, the client must resolve the multiple objects in the array, since it is possible for plugins to JMRI to provide their own response, and JMRI is incapable of judging the correctness of the plugin's response.

        If the request includes a result attribute, the content of the response will be solely the contents of that attribute. This is an aid to the development and testing of JMRI and clients, but is not considered a usable feature in production. This capability may be removed without notice if it is deemed too complex to maintain.

        doGet in class javax.servlet.http.HttpServlet
        request - an HttpServletRequest object that contains the request the client has made of the servlet
        response - an HttpServletResponse object that contains the response the servlet sends to the client
        Throws: - if an input or output error is detected when the servlet handles the GET request
      • doPost

        protected void doPost​(javax.servlet.http.HttpServletRequest request,
                              javax.servlet.http.HttpServletResponse response)
        doPost in class javax.servlet.http.HttpServlet
      • doPut

        protected void doPut​(javax.servlet.http.HttpServletRequest request,
                             javax.servlet.http.HttpServletResponse response)
        doPut in class javax.servlet.http.HttpServlet
      • doDelete

        protected void doDelete​(javax.servlet.http.HttpServletRequest request,
                                javax.servlet.http.HttpServletResponse response)
                         throws javax.servlet.ServletException,
        doDelete in class javax.servlet.http.HttpServlet