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:
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:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidconfigure(org.eclipse.jetty.websocket.servlet.WebSocketServletFactory factory) protected voiddoDelete(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) protected voiddoGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) Handle HTTP get requests for JSON data.protected voiddoPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) protected voiddoPut(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) voidinit()(package private) voidPackage private method to callWebSocketServlet.init()so this call can be mocked out in unit tests.Methods inherited from class org.eclipse.jetty.websocket.servlet.WebSocketServlet
destroy, serviceMethods inherited from class javax.servlet.http.HttpServlet
doHead, doOptions, doTrace, getLastModified, serviceMethods inherited from class javax.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
-
Constructor Details
-
JsonServlet
public JsonServlet()
-
-
Method Details
-
init
- Overrides:
initin classorg.eclipse.jetty.websocket.servlet.WebSocketServlet- Throws:
javax.servlet.ServletException
-
superInit
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
- Specified by:
configurein classorg.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)
- {"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:
doGetin 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:
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:
doPostin classjavax.servlet.http.HttpServlet- Throws:
IOException
-
doPut
protected void doPut(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws IOException - Overrides:
doPutin classjavax.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:
doDeletein classjavax.servlet.http.HttpServlet- Throws:
javax.servlet.ServletExceptionIOException
-