Package com.kurento.kmf.jsonrpcconnector.client

Examples of com.kurento.kmf.jsonrpcconnector.client.JsonRpcClient


  }

  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);
    }
  }
View Full Code Here


  @Test
  public void test() throws IOException {

    log.info("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.info("Response:" + result);

    Assert.assertEquals(params.param1, result.param1);
    Assert.assertEquals(params.param2, result.param2);

    client.close();

    log.info("Client finished");

  }
View Full Code Here

  @Test
  public void test() throws IOException, InterruptedException {

    log.info("Client started");

    JsonRpcClient client = createJsonRpcClient("/jsonrpcreverse");

    final CountDownLatch afterConnectionEstablishedLatch = new CountDownLatch(
        1);
    final CountDownLatch afterConnectionClosedLatch = new CountDownLatch(1);
    final CountDownLatch inverseRequestLatch = new CountDownLatch(2);
    final String[] inverseRequestParams = new String[1];

    client.setServerRequestHandler(new DefaultJsonRpcHandler<String>() {

      @Override
      public void afterConnectionEstablished(Session session)
          throws Exception {

        log.info("Connection established with sessionId: "
            + session.getSessionId());
        afterConnectionEstablishedLatch.countDown();
      }

      @Override
      public void handleRequest(Transaction transaction,
          Request<String> request) throws Exception {

        log.info("Reverse request: " + request);

        transaction.sendResponse(request.getParams());
        inverseRequestParams[0] = request.getParams();

        inverseRequestLatch.countDown();
      }

      @Override
      public void afterConnectionClosed(Session session, String status)
          throws Exception {

        log.info("Connection closed: " + status);
        afterConnectionClosedLatch.countDown();
      }
    });

    String result = client.sendRequest("echo", "params", String.class);

    Assert.assertTrue(
        "The method 'afterConnectionEstablished' is not invoked",
        afterConnectionEstablishedLatch.await(TIMEOUT,
            TimeUnit.MILLISECONDS));

    log.info("Response:" + result);

    Assert.assertEquals("params", result);

    Assert.assertTrue("The method 'handleRequest' is not invoked",
        inverseRequestLatch.await(TIMEOUT, TimeUnit.MILLISECONDS));

    String newResult = inverseRequestParams[0];

    Assert.assertEquals("params", newResult);

    client.close();

    Assert.assertTrue("The method 'afterConnectionClosed' is not invoked",
        afterConnectionClosedLatch
            .await(TIMEOUT, TimeUnit.MILLISECONDS));
View Full Code Here

  }

  @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();

  }
View Full Code Here

  @Test
  public void test() throws IOException, InterruptedException {

    log.info("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.info("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.info("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.info("Client finished");

  }
View Full Code Here

    if (clientType == null) {
      clientType = "ws";
    }

    JsonRpcClient client;
    if ("ws".equals(clientType)) {
      client = new JsonRpcClientWebSocket("ws://localhost:" + getPort()
          + servicePath, headers);
    } else if ("http".equals(clientType)) {
      client = new JsonRpcClientHttp("http://localhost:" + getPort()
View Full Code Here

  }

  @Test
  public void test() throws IOException, InterruptedException {

    JsonRpcClient client = createJsonRpcClient("/close_session_handler");

    Assert.assertEquals("new",
        client.sendRequest("sessiontest", String.class));
    Assert.assertEquals("old",
        client.sendRequest("sessiontest", String.class));
    Assert.assertEquals("old",
        client.sendRequest("sessiontest", String.class));

    client = createJsonRpcClient("/close_session_handler");

    Assert.assertEquals("new",
        client.sendRequest("sessiontest", String.class));
    Assert.assertEquals("old",
        client.sendRequest("sessiontest", String.class));
    Assert.assertEquals("old",
        client.sendRequest("sessiontest", String.class));

    client.close();

  }
View Full Code Here

  @Test
  public void test() throws IOException, InterruptedException {

    log.info("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.info("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));
View Full Code Here

  @Test
  public void test() throws IOException, InterruptedException {

    log.info("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.info("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.info("Client finished");
  }
View Full Code Here

  @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();

  }
View Full Code Here

TOP

Related Classes of com.kurento.kmf.jsonrpcconnector.client.JsonRpcClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.