Package jmri.web.servlet.json
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:
java.io.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
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 callWebSocketServlet.init()
so this call can be mocked out in unit tests.-
Methods inherited from class javax.servlet.http.HttpServlet
doHead, doOptions, doTrace, getLastModified, service
-
-
-
-
Constructor Detail
-
JsonServlet
public JsonServlet()
-
-
Method Detail
-
init
public void init() throws javax.servlet.ServletException
- Overrides:
init
in classorg.eclipse.jetty.websocket.servlet.WebSocketServlet
- Throws:
javax.servlet.ServletException
-
superInit
void superInit() throws javax.servlet.ServletException
Package private method to callWebSocketServlet.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 classorg.eclipse.jetty.websocket.servlet.WebSocketServlet
-
doGet
protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.io.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)
- {"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}}]
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 classjavax.servlet.http.HttpServlet
- Parameters:
request
- an HttpServletRequest object that contains the request the client has made of the servletresponse
- an HttpServletResponse object that contains the response the servlet sends to the client- Throws:
java.io.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 java.io.IOException
- Overrides:
doPost
in classjavax.servlet.http.HttpServlet
- Throws:
java.io.IOException
-
doPut
protected void doPut(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.io.IOException
- Overrides:
doPut
in classjavax.servlet.http.HttpServlet
- Throws:
java.io.IOException
-
doDelete
protected void doDelete(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException
- Overrides:
doDelete
in classjavax.servlet.http.HttpServlet
- Throws:
javax.servlet.ServletException
java.io.IOException
-
-