Search in sources :

Example 1 with MicroserviceResponse

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

the class ServiceCenterClient method getMicroserviceByServiceId.

@Override
public Microservice getMicroserviceByServiceId(String serviceId) {
    try {
        HttpResponse response = httpClient.getHttpRequest("/registry/microservices/" + serviceId, null, null);
        if (response.getStatusCode() == HttpStatus.SC_OK) {
            MicroserviceResponse microserviceResponse = HttpUtils.deserialize(response.getContent(), MicroserviceResponse.class);
            return microserviceResponse.getService();
        }
        sendUnAuthorizedEvent(response);
        throw new OperationException("get service message fails, statusCode = " + response.getStatusCode() + "; message = " + response.getMessage() + "; content = " + response.getContent());
    } catch (IOException e) {
        throw new OperationException("get service message fails", e);
    }
}
Also used : HttpResponse(org.apache.servicecomb.http.client.common.HttpResponse) IOException(java.io.IOException) RegisteredMicroserviceResponse(org.apache.servicecomb.service.center.client.model.RegisteredMicroserviceResponse) MicroserviceResponse(org.apache.servicecomb.service.center.client.model.MicroserviceResponse) OperationException(org.apache.servicecomb.service.center.client.exception.OperationException)

Example 2 with MicroserviceResponse

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

the class ServiceCenterClient method getMicroserviceByServiceId.

@Override
public Microservice getMicroserviceByServiceId(String serviceId) {
    try {
        HttpResponse response = httpClient.getHttpRequest("/registry/microservices/" + serviceId, null, null);
        if (response.getStatusCode() == HttpStatus.SC_OK) {
            MicroserviceResponse microserviceResponse = HttpUtils.deserialize(response.getContent(), MicroserviceResponse.class);
            return microserviceResponse.getService();
        }
        sendUnAuthorizedEvent(response);
        throw new OperationException("get service message fails, statusCode = " + response.getStatusCode() + "; message = " + response.getMessage() + "; content = " + response.getContent());
    } catch (IOException e) {
        throw new OperationException("get service message fails", e);
    }
}
Also used : HttpResponse(org.apache.servicecomb.http.client.common.HttpResponse) IOException(java.io.IOException) RegisteredMicroserviceResponse(org.apache.servicecomb.service.center.client.model.RegisteredMicroserviceResponse) MicroserviceResponse(org.apache.servicecomb.service.center.client.model.MicroserviceResponse) 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 MicroserviceResponse (org.apache.servicecomb.service.center.client.model.MicroserviceResponse)2 RegisteredMicroserviceResponse (org.apache.servicecomb.service.center.client.model.RegisteredMicroserviceResponse)2