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(java.io.DataOutputStream output)
JsonConnection(org.eclipse.jetty.websocket.api.Session connection)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description com.fasterxml.jackson.databind.ObjectMapper
getObjectMapper()
Get the ObjectMapper for this connection.java.lang.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(java.lang.String version)
-
Methods inherited from class jmri.jmris.JmriConnection
close, getDataOutputStream, getLocale, getSession, sendMessage, setLocale
-
-
-
-
Field Detail
-
preferences
protected final JsonServerPreferences preferences
-
schemas
protected final JsonSchemaServiceCache schemas
-
-
Constructor Detail
-
JsonConnection
public JsonConnection(org.eclipse.jetty.websocket.api.Session connection)
-
JsonConnection
public JsonConnection(java.io.DataOutputStream output)
-
-
Method Detail
-
getObjectMapper
@Nonnull public com.fasterxml.jackson.databind.ObjectMapper 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 java.io.IOException
Send 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:
java.io.IOException
- if unable to send the message
-
sendMessage
public void sendMessage(@Nonnull com.fasterxml.jackson.databind.JsonNode message, int id) throws java.io.IOException
Send 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:
java.io.IOException
- if unable to send the message
-
getVersion
public java.lang.String getVersion()
-
setVersion
public void setVersion(java.lang.String version)
-
-