@Test(expected = MessageDecodeException.class) public void decodeMissingAttribute() throws Exception { MessageDecoder decoder = new MessageDecoder(); Message result = decoder.decode(new StringReader( "{ " + " \"message\" : \"subscribe\"" + "}")); }
@Override public Message decode(Reader reader) throws DecodeException, IOException { JsonReader jReader = Json.createReader(reader); JsonObject jObject = jReader.readObject(); String messageType = jObject.getString("message", null); switch (messageType) { case "subscribe": return new MessageSubscribe(jObject); case "write": return new MessageWrite(jObject); case "pause": return new MessagePause(jObject); case "resume": return new MessageResume(jObject); case "unsubscribe": return new MessageUnsubscribe(jObject); case "event": String eventType = jObject.getString("type"); switch(eventType) { case "connection": return new MessageConnectionEvent(jObject); case "value": return new MessageValueEvent(jObject); case "writeCompleted": return new MessageWriteCompletedEvent(jObject); case "error": return new MessageErrorEvent(jObject); default: throw new DecodeException("", "Event " + eventType + " is not supported"); } default: throw MessageDecodeException.unsupportedMessage(jObject); } }
MessageDecoder implements Decoder.TextStream<Message> { @Override public Message decode(Reader reader) throws DecodeException, IOException { JsonReader jReader = Json.createReader(reader); JsonObject jObject = jReader.readObject(); String messageType = jObject.getString("message", null); switch (messageType) { case "subscribe": return new MessageSubscribe(jObject); case "write": return new MessageWrite(jObject); case "pause": return new MessagePause(jObject); case "resume": return new MessageResume(jObject); case "unsubscribe": return new MessageUnsubscribe(jObject); case "event": String eventType = jObject.getString("type"); switch(eventType) { case "connection": return new MessageConnectionEvent(jObject); case "value": return new MessageValueEvent(jObject); case "writeCompleted": return new MessageWriteCompletedEvent(jObject); case "error": return new MessageErrorEvent(jObject); default: throw new DecodeException("", "Event " + eventType + " is not supported"); } default: throw MessageDecodeException.unsupportedMessage(jObject); } } }
MessageDecoder implements Decoder.TextStream<Message> { @Override public Message decode(Reader reader) throws DecodeException, IOException { JsonReader jReader = Json.createReader(reader); JsonObject jObject = jReader.readObject(); String messageType = jObject.getString("message", null); switch (messageType) { case "subscribe": return new MessageSubscribe(jObject); case "write": return new MessageWrite(jObject); case "pause": return new MessagePause(jObject); case "resume": return new MessageResume(jObject); case "unsubscribe": return new MessageUnsubscribe(jObject); case "event": String eventType = jObject.getString("type"); switch(eventType) { case "connection": return new MessageConnectionEvent(jObject); case "value": return new MessageValueEvent(jObject); case "writeCompleted": return new MessageWriteCompletedEvent(jObject); case "error": return new MessageErrorEvent(jObject); default: throw new DecodeException("", "Event " + eventType + " is not supported"); } default: throw MessageDecodeException.unsupportedMessage(jObject); } }  }
MessageDecoder implements Decoder.TextStream<Message> { @Override public Message decode(Reader reader) throws DecodeException, IOException { JsonReader jReader = Json.createReader(reader); JsonObject jObject = jReader.readObject(); String messageType = jObject.getString("message", null); switch (messageType) { case "subscribe": return new MessageSubscribe(jObject); case "write": return new MessageWrite(jObject); case "pause": return new MessagePause(jObject); case "resume": return new MessageResume(jObject); case "unsubscribe": return new MessageUnsubscribe(jObject); case "event": String eventType = jObject.getString("type"); switch(eventType) { case "connection": return new MessageConnectionEvent(jObject); case "value": return new MessageValueEvent(jObject); case "writeCompleted": return new MessageWriteCompletedEvent(jObject); case "error": return new MessageErrorEvent(jObject); default: throw new DecodeException("", "Event " + eventType + " is not supported"); } default: throw MessageDecodeException.unsupportedMessage(jObject); } }  @Override Message decode(Reader reader); @Override void init(EndpointConfig config); @Override void destroy(); }
MessageDecoder implements Decoder.TextStream<Message> { @Override public Message decode(Reader reader) throws DecodeException, IOException { JsonReader jReader = Json.createReader(reader); JsonObject jObject = jReader.readObject(); String messageType = jObject.getString("message", null); switch (messageType) { case "subscribe": return new MessageSubscribe(jObject); case "write": return new MessageWrite(jObject); case "pause": return new MessagePause(jObject); case "resume": return new MessageResume(jObject); case "unsubscribe": return new MessageUnsubscribe(jObject); case "event": String eventType = jObject.getString("type"); switch(eventType) { case "connection": return new MessageConnectionEvent(jObject); case "value": return new MessageValueEvent(jObject); case "writeCompleted": return new MessageWriteCompletedEvent(jObject); case "error": return new MessageErrorEvent(jObject); default: throw new DecodeException("", "Event " + eventType + " is not supported"); } default: throw MessageDecodeException.unsupportedMessage(jObject); } }  @Override Message decode(Reader reader); @Override void init(EndpointConfig config); @Override void destroy();  }