/** * Deserializes a proto from JSON. Only protos whose classes have been * registered can be deserialized. * * @throws SerializationException if no class called {@code type} has been * registered. */ public Message fromJson(JsonElement json, String type) throws SerializationException { return getSerializer(type).fromJson(json, null, gson); }
@Override public void run() { clientChannel.sendMessage(sequenceNo, Rpc.CancelRpc.getDefaultInstance()); } });
private static void initializeRobotAgents(ServerRpcProvider server) { server.addServlet(PasswordRobot.ROBOT_URI + "/*", PasswordRobot.class); server.addServlet(PasswordAdminRobot.ROBOT_URI + "/*", PasswordAdminRobot.class); server.addServlet(WelcomeRobot.ROBOT_URI + "/*", WelcomeRobot.class); server.addServlet(RegistrationRobot.ROBOT_URI + "/*", RegistrationRobot.class); }
private <T extends Message> T fetchWaverRefAndParse(WaveRef waveref, Class<T> klass) throws Exception { String message = fetchWaveRef(waveref); JsonElement json = new JsonParser().parse(message); return protoSerializer.fromJson(json, klass); } }
@Override public void setUp() { callback = new TestCallback(); channel = new TestWebSocketChannel(callback); }
private ClientRpcChannel newClient() throws IOException { return new WebSocketClientRpcChannel(server.getWebSocketAddress()); }
public void testRoundTrippingJson() throws Exception { WaveClientRpc.ProtocolOpenRequest.Builder sourceBuilder = buildProtocolOpenRequest(); checkRoundtripping(sourceBuilder); }
@Override public void shutdown() throws Exception { server.stopServer(); } }, ServerMain.class.getSimpleName(), ShutdownPriority.Server);
/** * Serializes a proto to JSON. Only protos whose classes have been registered * will be serialized. * * @throws SerializationException if the class of {@code message} has not been * registered. */ public <P extends Message>JsonElement toJson(P message) throws SerializationException { return getSerializer(message.getClass()).toGson(message, null, gson); }
/** * Assert that this controller is in the given status. */ private void checkStatus(Status statusToAssert) { Status currentStatus = status(); if (!currentStatus.equals(statusToAssert)) { throw new IllegalStateException("Controller expected status " + statusToAssert + ", was " + currentStatus); } }
WebSocketConnection(ParticipantId loggedInUser, ServerRpcProvider provider) { super(loggedInUser, provider); socketChannel = new WebSocketChannelImpl(this); LOG.info("New websocket connection set up for user " + loggedInUser); expectMessages(socketChannel); }
@Override public boolean failed() { checkStatus(Status.COMPLETE); return state.failed; }
static <P extends Message, D extends ProtoWrapper<P> & GsonSerializable> ProtoImplSerializer<P, D> of( Class<P> protoClass, Class<D> dtoClass) { return new ProtoImplSerializer<P, D>(protoClass, dtoClass); }
@Override public RpcController newRpcController() { return new ClientRpcController(this); }
private <T extends Message> T fetchWaverRefAndParse(WaveRef waveref, Class<T> klass) throws Exception { String message = fetchWaveRef(waveref); JsonElement json = new JsonParser().parse(message); return protoSerializer.fromJson(json, klass); } }
@Override public void setUp() { callback = new TestCallback(); channel = new TestWebSocketChannel(callback); }
private ClientRpcChannel newClient() throws IOException { return new WebSocketClientRpcChannel(server.getWebSocketAddress()); }
@VisibleForTesting public <P extends Message> P fromJson(JsonElement json, Class<P> clazz) throws SerializationException { return getSerializer(clazz).fromJson(json, null, gson); } }
/** * Add a servlet to the servlet registry. This servlet will be attached to the * specified URL pattern when the server is started up. * @param urlPattern the URL pattern for paths. Eg, '/foo', '/foo/*'. * @param servlet the servlet class to bind to the specified paths. * @return the {@link ServletHolder} that holds the servlet. */ public ServletHolder addServlet(String urlPattern, Class<? extends HttpServlet> servlet) { return addServlet(urlPattern, servlet, null); }
@Override public void reset() { checkStatus(Status.COMPLETE); state = null; }