Search in sources :

Example 1 with JsonConnection

use of jmri.server.json.JsonConnection in project JMRI by JMRI.

the class JsonServer method handleClient.

// Handle communication to a client through inStream and outStream
@Override
public void handleClient(DataInputStream inStream, DataOutputStream outStream) throws IOException {
    ObjectReader reader = this.mapper.reader();
    JsonClientHandler handler = new JsonClientHandler(new JsonConnection(outStream));
    // Start by sending a welcome message
    handler.onMessage(JsonClientHandler.HELLO_MSG);
    while (true) {
        try {
            handler.onMessage(reader.readTree((InputStream) inStream));
        // Read the command from the client
        } catch (IOException e) {
            // attempt to close the connection and throw the exception
            handler.dispose();
            throw e;
        } catch (NoSuchElementException nse) {
            // so break out of the loop
            break;
        }
    }
    handler.dispose();
}
Also used : JsonClientHandler(jmri.server.json.JsonClientHandler) DataInputStream(java.io.DataInputStream) InputStream(java.io.InputStream) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) IOException(java.io.IOException) JsonConnection(jmri.server.json.JsonConnection) NoSuchElementException(java.util.NoSuchElementException)

Example 2 with JsonConnection

use of jmri.server.json.JsonConnection in project JMRI by JMRI.

the class JsonThrottleServiceFactoryTest method testGetSocketService.

/**
     * Test of getSocketService method, of class JsonThrottleServiceFactory.
     */
@Test
public void testGetSocketService() {
    JsonConnection connection = new JsonMockConnection((DataOutputStream) null);
    JsonThrottleServiceFactory instance = new JsonThrottleServiceFactory();
    JsonSocketService result = instance.getSocketService(connection);
    Assert.assertNotNull(result);
    Assert.assertTrue(JsonSocketService.class.isInstance(result));
}
Also used : JsonSocketService(jmri.server.json.JsonSocketService) JsonMockConnection(jmri.server.json.JsonMockConnection) JsonConnection(jmri.server.json.JsonConnection) Test(org.junit.Test)

Example 3 with JsonConnection

use of jmri.server.json.JsonConnection in project JMRI by JMRI.

the class JsonUtilServiceFactoryTest method testGetSocketService.

/**
     * Test of getSocketService method, of class JsonUtilServiceFactory.
     */
@Test
public void testGetSocketService() {
    JsonConnection connection = new JsonMockConnection((DataOutputStream) null);
    JsonUtilServiceFactory instance = new JsonUtilServiceFactory();
    JsonUtilSocketService result = instance.getSocketService(connection);
    assertNotNull(result);
}
Also used : JsonMockConnection(jmri.server.json.JsonMockConnection) JsonConnection(jmri.server.json.JsonConnection) Test(org.junit.Test)

Aggregations

JsonConnection (jmri.server.json.JsonConnection)3 JsonMockConnection (jmri.server.json.JsonMockConnection)2 Test (org.junit.Test)2 ObjectReader (com.fasterxml.jackson.databind.ObjectReader)1 DataInputStream (java.io.DataInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 NoSuchElementException (java.util.NoSuchElementException)1 JsonClientHandler (jmri.server.json.JsonClientHandler)1 JsonSocketService (jmri.server.json.JsonSocketService)1