Java Code Examples for org.kurento.jsonrpc.client.JsonRpcClient#setServerRequestHandler()
The following examples show how to use
org.kurento.jsonrpc.client.JsonRpcClient#setServerRequestHandler() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BidirectionalMultiTest.java From kurento-java with Apache License 2.0 | 6 votes |
@Test public void test() throws IOException, InterruptedException { log.debug("Client started"); JsonRpcClient client = createJsonRpcClient("/BidirectionalMultiTest"); client.setServerRequestHandler(new DefaultJsonRpcHandler<Integer>() { @Override public void handleRequest(Transaction transaction, Request<Integer> request) throws Exception { log.debug("Reverse request: " + request); transaction.sendResponse(request.getParams() + 1); } }); for (int i = 0; i < 60; i++) { client.sendRequest("echo", i, Integer.class); } client.close(); log.debug("Client finished"); }
Example 2
Source File: NotificationTest.java From kurento-java with Apache License 2.0 | 3 votes |
@Test public void test() throws IOException, InterruptedException { serverRequestLatch = new CountDownLatch(3); JsonRpcClient client = createJsonRpcClient("/notification"); client.setServerRequestHandler(new DefaultJsonRpcHandler<Integer>() { @Override public void handleRequest(Transaction transaction, Request<Integer> request) throws Exception { serverRequestLatch.countDown(); } }); client.sendNotification("echo", 1); client.sendNotification("echo", 2); client.sendNotification("echo", 3); Assert.assertTrue("The server has not invoked requests", serverRequestLatch.await(5000, TimeUnit.MILLISECONDS)); client.close(); }
Example 3
Source File: BidirectionalTest.java From kurento-java with Apache License 2.0 | 2 votes |
@Test public void test() throws IOException, InterruptedException { log.debug("Client started"); JsonRpcClient client = createJsonRpcClient("/jsonrpcreverse"); final CountDownLatch inverseRequestLatch = new CountDownLatch(2); final Params[] inverseRequestParams = new Params[1]; client.setServerRequestHandler(new DefaultJsonRpcHandler<Params>() { @Override public void handleRequest(Transaction transaction, Request<Params> request) throws Exception { log.debug("Reverse request: " + request); transaction.sendResponse(request.getParams()); inverseRequestParams[0] = request.getParams(); inverseRequestLatch.countDown(); } }); Params params = new Params(); params.param1 = "Value1"; params.param2 = "Value2"; Params result = client.sendRequest("echo", params, Params.class); log.debug("Response:" + result); Assert.assertEquals(params.param1, result.param1); Assert.assertEquals(params.param2, result.param2); inverseRequestLatch.await(); Params newResult = inverseRequestParams[0]; Assert.assertEquals(params.param1, newResult.param1); Assert.assertEquals(params.param2, newResult.param2); client.close(); log.debug("Client finished"); }
Example 4
Source File: ReconnectionFromServerTest.java From kurento-java with Apache License 2.0 | 2 votes |
@Test public void test() throws IOException, InterruptedException { JsonRpcClient client = new JsonRpcClientWebSocket( "ws://localhost:" + getPort() + "/reconnection2"); client.setServerRequestHandler(new DefaultJsonRpcHandler<JsonElement>() { @Override public void handleRequest(Transaction transaction, Request<JsonElement> request) throws Exception { log.debug("Receive request in client: " + request); transaction.sendResponse("world"); log.debug("Response sent from client"); } }); Assert.assertEquals("new", client.sendRequest("sessiontest", String.class)); waitForServer(); Assert.assertEquals("old", client.sendRequest("sessiontest", String.class)); waitForServer(); log.debug("SessionId: " + client.getSession().getSessionId()); JsonRpcClientWebSocket webSocketClient = (JsonRpcClientWebSocket) client; webSocketClient.closeNativeClient(); Thread.sleep(100); Assert.assertEquals("old", client.sendRequest("sessiontest", String.class)); waitForServer(); log.debug("Acquired"); client.close(); }