Ejemplo n.º 1
0
  public DrvLicRepresentation cancel() {
    try {
      HttpDelete request = new HttpDelete(link.getHref());
      request.addHeader("Accept", DrvLicRepresentation.DRVLIC_MEDIA_TYPE);

      log.debug("calling {} {}", request.getMethod(), request.getURI());
      HttpResponse response = httpClient.execute(request);
      result = HttpResult.getResult(Void.class, null, response);
      if (result.status >= 200 && result.status <= 299) {
        return new DrvLicRepresentation(); // no links
      } else {
        log.warn(
            String.format(
                "error calling %s %s, %d:%s",
                request.getMethod(), link, result.status, result.errorMsg));
        return null;
      }
    } catch (UnsupportedEncodingException ex) {
      throw new RuntimeException(ex);
    } catch (IllegalStateException ex) {
      ex.printStackTrace();
      throw new RuntimeException("State error reading stream", ex);
    } catch (IOException ex) {
      ex.printStackTrace();
      throw new RuntimeException("IO error reading stream", ex);
    } catch (JAXBException ex) {
      ex.printStackTrace();
      throw new RuntimeException("JAXB error demarshalling result", ex);
    } finally {
    }
  }
Ejemplo n.º 2
0
  @Override
  public void deleteItem(final ProxyRepository repository, final ResourceStoreRequest request)
      throws ItemNotFoundException, UnsupportedStorageOperationException, RemoteStorageException {
    final URL remoteUrl =
        appendQueryString(getAbsoluteUrlFromBase(repository, request), repository);

    final HttpDelete method = new HttpDelete(remoteUrl.toExternalForm());

    final HttpResponse httpResponse = executeRequestAndRelease(repository, request, method);
    final int statusCode = httpResponse.getStatusLine().getStatusCode();

    if (statusCode != HttpStatus.SC_OK
        && statusCode != HttpStatus.SC_NO_CONTENT
        && statusCode != HttpStatus.SC_ACCEPTED) {
      throw new RemoteStorageException(
          "The response to HTTP "
              + method.getMethod()
              + " was unexpected HTTP Code "
              + statusCode
              + " : "
              + httpResponse.getStatusLine().getReasonPhrase()
              + " [repositoryId=\""
              + repository.getId()
              + "\", requestPath=\""
              + request.getRequestPath()
              + "\", remoteUrl=\""
              + remoteUrl.toString()
              + "\"]");
    }
  }