Java Code Examples for org.kurento.jsonrpc.client.JsonRpcClient#sendRequest()
The following examples show how to use
org.kurento.jsonrpc.client.JsonRpcClient#sendRequest() .
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: BasicAsyncClientEchoTest.java From kurento-java with Apache License 2.0 | 5 votes |
@Test public void test() throws IOException, InterruptedException { log.debug("Client started"); JsonRpcClient client = createJsonRpcClient("/jsonrpc"); final JsonObject params = new JsonObject(); params.addProperty("param1", "Value1"); params.addProperty("param2", "Value2"); CountDownLatch finishTestLatch = new CountDownLatch(1); client.sendRequest("echo", params, new Continuation<JsonElement>() { @Override public void onSuccess(JsonElement result) { log.debug("Response:" + result); Assert.assertEquals(params.get("param1").getAsString(), "Value1"); Assert.assertEquals(params.get("param2").getAsString(), "Value2"); } @Override public void onError(Throwable cause) { cause.printStackTrace(); } }); finishTestLatch.await(5, TimeUnit.SECONDS); client.close(); log.debug("Client finished"); }
Example 3
Source File: BasicEchoTest.java From kurento-java with Apache License 2.0 | 4 votes |
@Test public void test() throws IOException { log.debug("Client started"); JsonRpcClient client = createJsonRpcClient("/jsonrpc"); 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); client.close(); log.debug("Client finished"); }
Example 4
Source File: MultipleSessionsTest.java From kurento-java with Apache License 2.0 | 4 votes |
private void counterSession() { JsonRpcClient client = createJsonRpcClient("/jsonrpc_multiple"); try { for (int i = 0; i < 5; i++) { int counter = client.sendRequest("count", null, Integer.class); Assert.assertEquals(i, counter); } client.close(); } catch (IOException e) { throw new RuntimeException(e); } }
Example 5
Source File: JsonRpcClientLocalTest.java From kurento-java with Apache License 2.0 | 4 votes |
@Test public void echoTest() throws Exception { LOG.info("Client started"); JsonRpcClient client = new JsonRpcClientLocal(new EchoJsonRpcHandler()); Params params = new Params(); params.param1 = "Value1"; params.param2 = "Value2"; Params result = client.sendRequest("echo", params, Params.class); LOG.info("Response:" + result); Assert.assertEquals(params.param1, result.param1); Assert.assertEquals(params.param2, result.param2); client.close(); LOG.info("Client finished"); }
Example 6
Source File: ServerEventsTest.java From kurento-java with Apache License 2.0 | 3 votes |
@Test public void test() throws IOException, InterruptedException { log.debug("Client started"); JsonRpcClient client = createJsonRpcClient("/serverevents"); String result = client.sendRequest("echo", "params", String.class); Assert.assertTrue("The method 'afterConnectionEstablished' is not invoked", afterConnectionEstablishedLatch.await(TIMEOUT, TimeUnit.MILLISECONDS)); log.debug("Response:" + result); Assert.assertEquals("params", result); Assert.assertTrue("The method 'handleRequest' is not invoked", requestLatch.await(TIMEOUT, TimeUnit.MILLISECONDS)); client.close(); Assert.assertTrue("The method 'afterConnectionClosed' is not invoked", afterConnectionClosedLatch.await(TIMEOUT, TimeUnit.MILLISECONDS)); log.debug("Client finished"); }
Example 7
Source File: AsyncServerTest.java From kurento-java with Apache License 2.0 | 3 votes |
@Test public void test() throws IOException, InterruptedException { JsonRpcClient client = createJsonRpcClient("/async_handler"); String response = client.sendRequest("count", "fakeparams", String.class); Assert.assertEquals("AsyncHello", response); client.close(); }
Example 8
Source File: LargePackageTest.java From kurento-java with Apache License 2.0 | 3 votes |
@Test public void test() throws IOException, InterruptedException { JsonRpcClient client = createJsonRpcClient("/largepackage"); String largePackage = client.sendRequest("echo", String.class); System.out.println(largePackage); Thread.sleep(2000); client.close(); }
Example 9
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 10
Source File: PingPongTest.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("/pingpong", new JsonRpcWSConnectionAdapter() { @Override public void connectionFailed() { System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); } @Override public void disconnected() { System.out.println("#######################################"); } }); client.setHeartbeatInterval(500); client.enableHeartbeat(); String result = client.sendRequest("echo", "Params", String.class); log.debug("Response:" + result); Assert.assertEquals(result, "OK"); Thread.sleep(20000); log.debug("----------------- Disabling heartbeat in client ----------------"); client.disableHeartbeat(); // This should lead to reconnect clients Thread.sleep(30000); log.debug("----------------- Enabling heartbeat in client ----------------"); client.enableHeartbeat(); Thread.sleep(30000); log.debug("Client finished"); }