Class JsonServlet

java.lang.Object
javax.servlet.GenericServlet
javax.servlet.http.HttpServlet
org.eclipse.jetty.websocket.servlet.WebSocketServlet
jmri.web.servlet.json.JsonServlet
All Implemented Interfaces:
Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

@WebServlet(name="JsonServlet",
            urlPatterns="/json")
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

    Constructors 
    Constructor Description
    JsonServlet()  
  • Method Summary

    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
  • Constructor Details

  • Method Details

    • init

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

      void superInit() throws javax.servlet.ServletException
      Package private method to call WebSocketServlet.init() so this call can be mocked out in unit tests.
      Throws:
      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) throws IOException
      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.

      Overrides:
      doGet in class javax.servlet.http.HttpServlet
      Parameters:
      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:
      IOException - 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) throws IOException
      Overrides:
      doPost in class javax.servlet.http.HttpServlet
      Throws:
      IOException
    • doPut

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

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