Пример #1
0
 public void fillInOptions(ClientOptions opts) {
   opts.restHost = restHost;
   opts.realtimeHost = realtimeHost;
   opts.port = port;
   opts.tlsPort = tlsPort;
   opts.tls = tls;
 }
Пример #2
0
 private static void __clearTestVars() {
   if (testVars != null) {
     try {
       ClientOptions opts = new ClientOptions(testVars.keys[0].keyStr);
       opts.restHost = host;
       opts.port = port;
       opts.tlsPort = tlsPort;
       opts.tls = true;
       ably = new AblyRest(opts);
       ably.http.del("/apps/" + testVars.appId, HttpUtils.defaultAcceptHeaders(false), null, null);
     } catch (AblyException ae) {
       System.err.println("Unable to delete test app: " + ae);
       ae.printStackTrace();
       System.exit(1);
     }
     testVars = null;
   }
 }
Пример #3
0
  private static TestVars __getTestVars() {
    if (testVars == null) {
      host = System.getenv("ABLY_REST_HOST");
      if (host != null) {
        wsHost = System.getenv("ABLY_REALTIME_HOST");
        if (wsHost == null) wsHost = host;
      } else {
        environment = System.getenv("ABLY_ENV");
        if (environment == null) environment = "sandbox";

        host = environment + "-rest.ably.io";
        wsHost = environment + "-realtime.ably.io";
      }

      if (System.getenv("ABLY_PORT") != null) {
        port = Integer.valueOf(System.getenv("ABLY_PORT"));
        tlsPort = Integer.valueOf(System.getenv("ABLY_TLS_PORT"));
      } else if (host.contains("local")) {
        port = 8080;
        tlsPort = 8081;
      } else {
        /* default to connecting to sandbox or production through load balancer */
        port = 80;
        tlsPort = 443;
      }

      if (ably == null) {
        try {
          ClientOptions opts = new ClientOptions();
          /* we need to provide an appId to keep the library happy,
           * but we are only instancing the library to use the http
           * convenience methods */
          opts.key = "none:none";
          opts.restHost = host;
          opts.port = port;
          opts.tlsPort = tlsPort;
          opts.tls = true;
          ably = new AblyRest(opts);
        } catch (AblyException e) {
          System.err.println("Unable to instance AblyRest: " + e);
          e.printStackTrace();
          System.exit(1);
        }
      }

      Setup.AppSpec appSpec = null;
      try {
        appSpec = (Setup.AppSpec) loadJSON(specFile, Setup.AppSpec.class);
        appSpec.notes =
            "Test app; created by ably-java realtime tests; date = " + new Date().toString();
      } catch (IOException ioe) {
        System.err.println("Unable to read spec file: " + ioe);
        ioe.printStackTrace();
        System.exit(1);
      }
      try {
        testVars =
            ably.http.post(
                "/apps",
                null,
                null,
                new JSONRequestBody(appSpec),
                new ResponseHandler<TestVars>() {
                  @Override
                  public TestVars handleResponse(
                      int statusCode, String contentType, Collection<String> headers, byte[] body)
                      throws AblyException {
                    TestVars result =
                        (TestVars) Serialisation.gson.fromJson(new String(body), TestVars.class);
                    result.restHost = host;
                    result.realtimeHost = wsHost;
                    result.port = port;
                    result.tlsPort = tlsPort;
                    result.tls = true;
                    return result;
                  }
                });
      } catch (AblyException ae) {
        System.err.println("Unable to create test app: " + ae);
        ae.printStackTrace();
        System.exit(1);
      }
    }
    return testVars;
  }