Exemple #1
0
 public void onComplete(
     final HttpClientResponse response, final AsyncResultHandler<Void> doneHandler) {
   final Buffer buff = new Buffer(16);
   response.dataHandler(
       new Handler<Buffer>() {
         public void handle(Buffer data) {
           buff.appendBuffer(data);
         }
       });
   response.endHandler(
       new SimpleHandler() {
         public void handle() {
           byte[] bytes = buff.getBytes();
           AsyncResult<Void> res;
           try {
             if (challenge.verify(bytes)) {
               res = new AsyncResult<>((Void) null);
             } else {
               res = new AsyncResult<>(new Exception("Invalid websocket handshake response"));
             }
           } catch (Exception e) {
             res = new AsyncResult<>(e);
           }
           doneHandler.handle(res);
         }
       });
 }
Exemple #2
0
  public void onComplete(HttpClientResponse response, final CompletionHandler<Void> doneHandler) {

    final Buffer buff = Buffer.create(16);
    response.dataHandler(
        new Handler<Buffer>() {
          public void handle(Buffer data) {
            buff.appendBuffer(data);
          }
        });
    response.endHandler(
        new SimpleHandler() {
          public void handle() {
            byte[] bytes = buff.getBytes();
            SimpleFuture<Void> fut = new SimpleFuture<>();
            try {
              if (challenge.verify(bytes)) {
                fut.setResult(null);
              } else {
                fut.setException(new Exception("Invalid websocket handshake response"));
              }
            } catch (Exception e) {
              fut.setException(e);
            }
            doneHandler.handle(fut);
          }
        });
  }
Exemple #3
0
  public void handle(HttpClientResponse response) {
    if (response.statusCode != 200) {
      throw new IllegalStateException("Invalid response");
    }
    response.endHandler(
        new SimpleHandler() {
          public void handle() {
            long start = startTimeMs.remove();
            long now = System.currentTimeMillis();
            long delta = now - start;
            ;

            deltas[nextDelta] = delta;
            nextDelta += 1;
            if (nextDelta >= NUM_DELTAS) {
              nextDelta = 0;
              batchCount += 1;

              long min = Long.MAX_VALUE;
              long max = Long.MIN_VALUE;
              double sum = 0;
              for (long d : deltas) {
                sum += d;
                min = Math.min(min, d);
                max = Math.max(max, d);
              }
              double mean = sum / (double) NUM_DELTAS;

              double sumsq_diff = 0;
              for (long d : deltas) {
                double diff = (double) d - mean;
                sumsq_diff += diff * diff;
              }
              double stdev = Math.sqrt(sumsq_diff / (double) NUM_DELTAS);

              double rate = (double) NUM_DELTAS * 1000.0 / (double) (now - lastBatchMs);
              eb.send("batch-count", batchCount);
              eb.send("rate", rate);
              eb.send("delta-min", min);
              eb.send("delta-max", max);
              eb.send("delta-avg", mean);
              eb.send("delta-stdev", stdev);

              lastBatchMs = System.currentTimeMillis();
            }

            requestCredits++;
            makeRequest();
          }
        });
  }
  @Override
  public void handle(HttpClientResponse clientResponse) {
    delegate.handle(clientResponse);

    MultiMap headers = clientResponse.headers();
    for (String headerName : rewriteHeaders) {
      List<String> headerValues = headers.getAll(headerName);
      int size = headerValues.size();
      if (size > 0) {
        List<String> newHeaders = new ArrayList<String>(size);
        for (String headerValue : headerValues) {
          String newValue = headerValue;
          if (headerValue != null && headerValue.length() > 0) {
            newValue = proxyMappingDetails.rewriteBackendUrl(headerValue);
          }
        }
        LOG.info(
            "Rewriting header " + headerName + " from: " + headerValues + " to: " + newHeaders);
        headers.set(headerName, newHeaders);
      }
    }
  }
 @Override
 public T read(Class<? extends T> clazz, byte[] buffer, HttpClientResponse httpClientResponse)
     throws HttpMessageConverterException {
   return readInternal(clazz, buffer, httpClientResponse.headers());
 }