Package jmri.server.json
Class JsonConnection
java.lang.Object
jmri.jmris.JmriConnection
jmri.server.json.JsonConnection
public class JsonConnection extends JmriConnection
Abstraction of DataOutputStream and WebSocket.Connection classes for JSON
clients.
-
Field Summary
Fields Modifier and Type Field Description protected JsonServerPreferences
preferences
protected JsonSchemaServiceCache
schemas
-
Constructor Summary
Constructors Constructor Description JsonConnection(DataOutputStream output)
JsonConnection(org.eclipse.jetty.websocket.api.Session connection)
-
Method Summary
Modifier and Type Method Description com.fasterxml.jackson.databind.ObjectMapper
getObjectMapper()
Get the ObjectMapper for this connection.String
getVersion()
void
sendMessage(com.fasterxml.jackson.databind.JsonNode message, int id)
Send a JsonNode to the instantiated connection.void
sendMessage(com.fasterxml.jackson.databind.JsonNode message, JsonRequest request)
Send a JsonNode to the instantiated connection.void
setVersion(String version)
Methods inherited from class jmri.jmris.JmriConnection
close, getDataOutputStream, getLocale, getSession, sendMessage, setLocale
-
Field Details
-
Constructor Details
-
Method Details
-
getObjectMapper
Get the ObjectMapper for this connection.- Returns:
- the ObjectMapper
-
sendMessage
public void sendMessage(@Nonnull com.fasterxml.jackson.databind.JsonNode message, @Nonnull JsonRequest request) throws IOExceptionSend a JsonNode to the instantiated connection.This method throws an IOException so the server or servlet holding the connection open can respond to the exception.
If
JsonServerPreferences.getValidateServerMessages()
istrue
, a message is sent to the client that validation failed instead of the intended message.Overriding methods must ensure that
message
is only sent if validated.- Parameters:
message
- the object or array to send as a messagerequest
- the JSON request- Throws:
IOException
- if unable to send the message
-
sendMessage
public void sendMessage(@Nonnull com.fasterxml.jackson.databind.JsonNode message, int id) throws IOExceptionSend a JsonNode to the instantiated connection.This method throws an IOException so the server or servlet holding the connection open can respond to the exception.
If
JsonServerPreferences.getValidateServerMessages()
istrue
, a message is sent to the client that validation failed instead of the intended message.Overriding methods must ensure that
message
is only sent if validated.- Parameters:
message
- the object or array to send as a messageid
- the message id set by the client- Throws:
IOException
- if unable to send the message
-
getVersion
-
setVersion
-