Search in sources :

Example 21 with ScmBadRequestException

use of org.eclipse.che.api.factory.server.scm.exception.ScmBadRequestException in project devspaces-images by redhat-developer.

the class HttpBitbucketServerApiClient method deletePersonalAccessTokens.

@Override
public void deletePersonalAccessTokens(String userSlug, Long tokenId) throws ScmItemNotFoundException, ScmUnauthorizedException, ScmCommunicationException {
    URI uri = serverUri.resolve("/rest/access-tokens/1.0/users/" + userSlug + "/" + tokenId);
    HttpRequest request = HttpRequest.newBuilder(uri).DELETE().headers(HttpHeaders.AUTHORIZATION, computeAuthorizationHeader("DELETE", uri.toString()), HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON, HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).timeout(DEFAULT_HTTP_TIMEOUT).build();
    try {
        LOG.trace("executeRequest={}", request);
        executeRequest(httpClient, request, inputStream -> {
            try {
                return OM.readValue(inputStream, String.class);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        });
    } catch (ScmBadRequestException e) {
        throw new ScmCommunicationException(e.getMessage(), e);
    }
}
Also used : HttpRequest(java.net.http.HttpRequest) ScmCommunicationException(org.eclipse.che.api.factory.server.scm.exception.ScmCommunicationException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) URI(java.net.URI) ScmBadRequestException(org.eclipse.che.api.factory.server.scm.exception.ScmBadRequestException)

Example 22 with ScmBadRequestException

use of org.eclipse.che.api.factory.server.scm.exception.ScmBadRequestException in project devspaces-images by redhat-developer.

the class HttpBitbucketServerApiClient method getPersonalAccessToken.

@Override
public BitbucketPersonalAccessToken getPersonalAccessToken(String userSlug, Long tokenId) throws ScmItemNotFoundException, ScmUnauthorizedException, ScmCommunicationException {
    URI uri = serverUri.resolve("/rest/access-tokens/1.0/users/" + userSlug + "/" + tokenId);
    HttpRequest request = HttpRequest.newBuilder(uri).headers("Authorization", computeAuthorizationHeader("GET", uri.toString()), HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON).timeout(DEFAULT_HTTP_TIMEOUT).build();
    try {
        LOG.trace("executeRequest={}", request);
        return executeRequest(httpClient, request, inputStream -> {
            try {
                return OM.readValue(inputStream, BitbucketPersonalAccessToken.class);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        });
    } catch (ScmBadRequestException e) {
        throw new ScmCommunicationException(e.getMessage(), e);
    }
}
Also used : HttpRequest(java.net.http.HttpRequest) ScmCommunicationException(org.eclipse.che.api.factory.server.scm.exception.ScmCommunicationException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) URI(java.net.URI) ScmBadRequestException(org.eclipse.che.api.factory.server.scm.exception.ScmBadRequestException)

Aggregations

ScmBadRequestException (org.eclipse.che.api.factory.server.scm.exception.ScmBadRequestException)22 ScmCommunicationException (org.eclipse.che.api.factory.server.scm.exception.ScmCommunicationException)22 IOException (java.io.IOException)16 UncheckedIOException (java.io.UncheckedIOException)16 ScmItemNotFoundException (org.eclipse.che.api.factory.server.scm.exception.ScmItemNotFoundException)14 URI (java.net.URI)10 HttpRequest (java.net.http.HttpRequest)10 InputStream (java.io.InputStream)8 InputStreamReader (java.io.InputStreamReader)8 ScmUnauthorizedException (org.eclipse.che.api.factory.server.scm.exception.ScmUnauthorizedException)8 PersonalAccessToken (org.eclipse.che.api.factory.server.scm.PersonalAccessToken)6 List (java.util.List)4 Optional (java.util.Optional)4 Set (java.util.Set)4 OAuthToken (org.eclipse.che.api.auth.shared.dto.OAuthToken)4 BadRequestException (org.eclipse.che.api.core.BadRequestException)4 ConflictException (org.eclipse.che.api.core.ConflictException)4 ForbiddenException (org.eclipse.che.api.core.ForbiddenException)4 NotFoundException (org.eclipse.che.api.core.NotFoundException)4 ServerException (org.eclipse.che.api.core.ServerException)4