Search in sources :

Example 36 with OperationException

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

the class ServiceCenterClient method sendHeartBeat.

@Override
public boolean sendHeartBeat(String serviceId, String instanceId) {
    try {
        HttpResponse response = httpClient.putHttpRequest("/registry/microservices/" + serviceId + "/instances/" + instanceId + "/heartbeat", null, null);
        if (response.getStatusCode() == HttpStatus.SC_OK) {
            return true;
        }
        sendUnAuthorizedEvent(response);
        throw new OperationException("heartbeats fails, statusCode = " + response.getStatusCode() + "; message = " + response.getMessage() + "; content = " + response.getContent());
    } catch (IOException e) {
        throw new OperationException("heartbeats fails ", e);
    }
}
Also used : HttpResponse(org.apache.servicecomb.http.client.common.HttpResponse) IOException(java.io.IOException) OperationException(org.apache.servicecomb.service.center.client.exception.OperationException)

Example 37 with OperationException

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

the class ServiceCenterClient method getServiceSchemasList.

@Override
public List<SchemaInfo> getServiceSchemasList(String serviceId, boolean withContent) {
    String url = "/registry/microservices/" + serviceId + "/schemas";
    if (withContent) {
        url = url + "?withSchema=1";
    }
    try {
        HttpResponse response = httpClient.getHttpRequest(url, null, null);
        if (response.getStatusCode() == HttpStatus.SC_OK) {
            GetSchemaListResponse getSchemaResponse = HttpUtils.deserialize(response.getContent(), GetSchemaListResponse.class);
            return getSchemaResponse.getSchemas();
        }
        sendUnAuthorizedEvent(response);
        throw new OperationException("get service schemas list fails, statusCode = " + response.getStatusCode() + "; message = " + response.getMessage() + "; content = " + response.getContent());
    } catch (IOException e) {
        throw new OperationException("get service schemas list fails", e);
    }
}
Also used : HttpResponse(org.apache.servicecomb.http.client.common.HttpResponse) IOException(java.io.IOException) GetSchemaListResponse(org.apache.servicecomb.service.center.client.model.GetSchemaListResponse) OperationException(org.apache.servicecomb.service.center.client.exception.OperationException)

Example 38 with OperationException

use of org.apache.servicecomb.service.center.client.exception.OperationException 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)38 HttpResponse (org.apache.servicecomb.http.client.common.HttpResponse)38 OperationException (org.apache.servicecomb.service.center.client.exception.OperationException)38 URISyntaxException (java.net.URISyntaxException)2 HashMap (java.util.HashMap)2 URIBuilder (org.apache.http.client.utils.URIBuilder)2 CreateMicroserviceInstanceRequest (org.apache.servicecomb.service.center.client.model.CreateMicroserviceInstanceRequest)2 CreateMicroserviceRequest (org.apache.servicecomb.service.center.client.model.CreateMicroserviceRequest)2 CreateSchemaRequest (org.apache.servicecomb.service.center.client.model.CreateSchemaRequest)2 ErrorMessage (org.apache.servicecomb.service.center.client.model.ErrorMessage)2 FindMicroserviceInstancesResponse (org.apache.servicecomb.service.center.client.model.FindMicroserviceInstancesResponse)2 GetSchemaListResponse (org.apache.servicecomb.service.center.client.model.GetSchemaListResponse)2 GetSchemaResponse (org.apache.servicecomb.service.center.client.model.GetSchemaResponse)2 MicroserviceInstanceResponse (org.apache.servicecomb.service.center.client.model.MicroserviceInstanceResponse)2 MicroserviceInstancesResponse (org.apache.servicecomb.service.center.client.model.MicroserviceInstancesResponse)2 MicroserviceResponse (org.apache.servicecomb.service.center.client.model.MicroserviceResponse)2 RbacTokenResponse (org.apache.servicecomb.service.center.client.model.RbacTokenResponse)2 RegisteredMicroserviceInstanceResponse (org.apache.servicecomb.service.center.client.model.RegisteredMicroserviceInstanceResponse)2 RegisteredMicroserviceResponse (org.apache.servicecomb.service.center.client.model.RegisteredMicroserviceResponse)2