Search in sources :

Example 1 with ErrorMessage

use of org.apache.servicecomb.service.center.client.model.ErrorMessage in project java-chassis by ServiceComb.

the class ServiceCenterClient method queryToken.

@Override
public RbacTokenResponse queryToken(RbacTokenRequest request) {
    try {
        HttpResponse response = httpClient.postHttpRequestAbsoluteUrl("/v4/token", null, HttpUtils.serialize(request));
        if (response.getStatusCode() == HttpStatus.SC_OK) {
            RbacTokenResponse result = HttpUtils.deserialize(response.getContent(), RbacTokenResponse.class);
            result.setStatusCode(HttpStatus.SC_OK);
            return result;
        }
        if (response.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
            RbacTokenResponse result = new RbacTokenResponse();
            result.setStatusCode(response.getStatusCode());
            return result;
        }
        if (response.getStatusCode() == HttpStatus.SC_UNAUTHORIZED || response.getStatusCode() == HttpStatus.SC_FORBIDDEN) {
            RbacTokenResponse result = new RbacTokenResponse();
            result.setStatusCode(response.getStatusCode());
            ErrorMessage errorMessage = HttpUtils.deserialize(response.getContent(), ErrorMessage.class);
            result.setErrorCode(errorMessage.getErrorCode());
            return result;
        }
        throw new OperationException("query token failed, statusCode = " + response.getStatusCode() + "; message = " + response.getMessage() + "; content = " + response.getContent());
    } catch (IOException e) {
        throw new OperationException("query token failed", e);
    }
}
Also used : HttpResponse(org.apache.servicecomb.http.client.common.HttpResponse) IOException(java.io.IOException) ErrorMessage(org.apache.servicecomb.service.center.client.model.ErrorMessage) RbacTokenResponse(org.apache.servicecomb.service.center.client.model.RbacTokenResponse) OperationException(org.apache.servicecomb.service.center.client.exception.OperationException)

Example 2 with ErrorMessage

use of org.apache.servicecomb.service.center.client.model.ErrorMessage in project incubator-servicecomb-java-chassis by apache.

the class ServiceCenterClient method queryToken.

@Override
public RbacTokenResponse queryToken(RbacTokenRequest request) {
    try {
        HttpResponse response = httpClient.postHttpRequestAbsoluteUrl("/v4/token", null, HttpUtils.serialize(request));
        if (response.getStatusCode() == HttpStatus.SC_OK) {
            RbacTokenResponse result = HttpUtils.deserialize(response.getContent(), RbacTokenResponse.class);
            result.setStatusCode(HttpStatus.SC_OK);
            return result;
        }
        if (response.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
            RbacTokenResponse result = new RbacTokenResponse();
            result.setStatusCode(response.getStatusCode());
            return result;
        }
        if (response.getStatusCode() == HttpStatus.SC_UNAUTHORIZED || response.getStatusCode() == HttpStatus.SC_FORBIDDEN) {
            RbacTokenResponse result = new RbacTokenResponse();
            result.setStatusCode(response.getStatusCode());
            ErrorMessage errorMessage = HttpUtils.deserialize(response.getContent(), ErrorMessage.class);
            result.setErrorCode(errorMessage.getErrorCode());
            return result;
        }
        throw new OperationException("query token failed, statusCode = " + response.getStatusCode() + "; message = " + response.getMessage() + "; content = " + response.getContent());
    } catch (IOException e) {
        throw new OperationException("query token failed", e);
    }
}
Also used : HttpResponse(org.apache.servicecomb.http.client.common.HttpResponse) IOException(java.io.IOException) ErrorMessage(org.apache.servicecomb.service.center.client.model.ErrorMessage) RbacTokenResponse(org.apache.servicecomb.service.center.client.model.RbacTokenResponse) OperationException(org.apache.servicecomb.service.center.client.exception.OperationException)

Aggregations

IOException (java.io.IOException)2 HttpResponse (org.apache.servicecomb.http.client.common.HttpResponse)2 OperationException (org.apache.servicecomb.service.center.client.exception.OperationException)2 ErrorMessage (org.apache.servicecomb.service.center.client.model.ErrorMessage)2 RbacTokenResponse (org.apache.servicecomb.service.center.client.model.RbacTokenResponse)2