public void delete()

in dicom_util/src/main/java/com/google/cloud/healthcare/DicomWebClientJetty.java [175:259]


  public void delete(String path) throws IDicomWebClient.DicomWebException {
    try {
      String deletePath = String.format("%s/%s", stowPath, StringUtil.trim(path));
      log.debug("DELETE to: " + deletePath);

      HTTP2Client client = new HTTP2Client();
      SslContextFactory sslContextFactory = new SslContextFactory.Client();
      client.addBean(sslContextFactory);
      client.start();

      HttpURI uri = new HttpURI(deletePath);

      FuturePromise<Session> sessionPromise = new FuturePromise<>();
      client.connect(
          sslContextFactory,
          new InetSocketAddress(uri.getHost(), CONNECT_PORT),
          new ServerSessionListener.Adapter(),
          sessionPromise);

      // Applied based on logic in the STOW request.
      Session session = sessionPromise.get(300, TimeUnit.SECONDS);

      // Prepare the request
      HttpFields requestFields = new HttpFields();
      if (credentials != null) {
        credentials.getRequestMetadata();
        requestFields.add(
            HttpHeader.AUTHORIZATION, "Bearer " + credentials.getAccessToken().getTokenValue());
      }

      MetaData.Request request =
          new MetaData.Request("DELETE", uri, HttpVersion.HTTP_2, requestFields);
      HeadersFrame headersFrame = new HeadersFrame(request, null, true);

      // Prepare the listener to receive the HTTP response frames.
      final StringBuilder resultBuilder = new StringBuilder();
      final CompletableFuture<Integer> responseCodeFuture = new CompletableFuture<>();
      final CompletableFuture<Boolean> doneFuture = new CompletableFuture<>();

      session.newStream(
          headersFrame,
          new FuturePromise<>(),
          new Stream.Listener.Adapter() {
            @Override
            public void onReset(Stream stream, ResetFrame frame) {
              doneFuture.complete(false);
            }

            @Override
            public void onHeaders(Stream stream, HeadersFrame frame) {
              if (frame.getMetaData() instanceof Response) {
                responseCodeFuture.complete(((Response) frame.getMetaData()).getStatus());
              }
            }

            @Override
            public void onData(Stream stream, DataFrame frame, Callback callback) {
              byte[] bytes = new byte[frame.getData().remaining()];
              frame.getData().get(bytes);
              resultBuilder.append(new String(bytes, StandardCharsets.UTF_8));

              if (frame.isEndStream()) {
                doneFuture.complete(true);
              }

              callback.succeeded();
            }
          });

      doneFuture.get();
      client.stop();

      int httpStatus = responseCodeFuture.get();
      if (httpStatus != HttpStatus.OK_200) {
        String resp = resultBuilder.toString();
        throw new DicomWebException(
            "Http_" + httpStatus + ": " + resp, httpStatus, Status.ProcessingFailure);
      }
    } catch (Exception e) {
      if (e instanceof DicomWebException) {
        throw (DicomWebException) e;
      }
      throw new DicomWebException(e);
    }
  }