Search in sources :

Example 16 with HttpResponse

use of org.apache.servicecomb.http.client.common.HttpResponse 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)

Example 17 with HttpResponse

use of org.apache.servicecomb.http.client.common.HttpResponse in project java-chassis by ServiceComb.

the class ServiceCenterClient method getMicroserviceInstanceList.

@Override
public MicroserviceInstancesResponse getMicroserviceInstanceList(String serviceId) {
    try {
        HttpResponse response = httpClient.getHttpRequest("/registry/microservices/" + serviceId + "/instances", null, null);
        if (response.getStatusCode() == HttpStatus.SC_OK) {
            return HttpUtils.deserialize(response.getContent(), MicroserviceInstancesResponse.class);
        }
        sendUnAuthorizedEvent(response);
        throw new OperationException("get service instances list fails, statusCode = " + response.getStatusCode() + "; message = " + response.getMessage() + "; content = " + response.getContent());
    } catch (IOException e) {
        throw new OperationException("get service instances list 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 18 with HttpResponse

use of org.apache.servicecomb.http.client.common.HttpResponse in project java-chassis by ServiceComb.

the class ServiceCenterClient method getServiceSchemaContext.

/**
 * Get one schema context of service
 *
 * @param serviceId
 * @param schemaId
 * @return
 * @throws OperationException
 */
public String getServiceSchemaContext(String serviceId, String schemaId) {
    try {
        HttpResponse response = httpClient.getHttpRequest("/registry/microservices/" + serviceId + "/schemas/" + schemaId, null, null);
        if (response.getStatusCode() == HttpStatus.SC_OK) {
            GetSchemaResponse getSchemaResponse = HttpUtils.deserialize(response.getContent(), GetSchemaResponse.class);
            return getSchemaResponse.getSchema();
        }
        sendUnAuthorizedEvent(response);
        throw new OperationException("get service schema context fails, statusCode = " + response.getStatusCode() + "; message = " + response.getMessage() + "; content = " + response.getContent());
    } catch (IOException e) {
        throw new OperationException("get service schemas context fails", e);
    }
}
Also used : HttpResponse(org.apache.servicecomb.http.client.common.HttpResponse) GetSchemaResponse(org.apache.servicecomb.service.center.client.model.GetSchemaResponse) IOException(java.io.IOException) OperationException(org.apache.servicecomb.service.center.client.exception.OperationException)

Example 19 with HttpResponse

use of org.apache.servicecomb.http.client.common.HttpResponse in project java-chassis by ServiceComb.

the class ServiceCenterClient method registerSchema.

@Override
public boolean registerSchema(String serviceId, String schemaId, CreateSchemaRequest schema) {
    try {
        HttpResponse response = httpClient.putHttpRequest("/registry/microservices/" + serviceId + "/schemas/" + schemaId, null, HttpUtils.serialize(schema));
        if (response.getStatusCode() == HttpStatus.SC_OK) {
            return true;
        }
        sendUnAuthorizedEvent(response);
        throw new OperationException("update service schema fails, statusCode = " + response.getStatusCode() + "; message = " + response.getMessage() + "; content = " + response.getContent());
    } catch (IOException e) {
        throw new OperationException("update service schema 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 20 with HttpResponse

use of org.apache.servicecomb.http.client.common.HttpResponse in project java-chassis by ServiceComb.

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)

Aggregations

HttpResponse (org.apache.servicecomb.http.client.common.HttpResponse)37 IOException (java.io.IOException)21 OperationException (org.apache.servicecomb.service.center.client.exception.OperationException)19 Test (org.junit.Test)15 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 Microservice (org.apache.servicecomb.service.center.client.model.Microservice)4 HttpRequest (org.apache.servicecomb.http.client.common.HttpRequest)3 MicroserviceInstancesResponse (org.apache.servicecomb.service.center.client.model.MicroserviceInstancesResponse)3 RegisteredMicroserviceResponse (org.apache.servicecomb.service.center.client.model.RegisteredMicroserviceResponse)3 HashMap (java.util.HashMap)2 MicroserviceInstance (org.apache.servicecomb.service.center.client.model.MicroserviceInstance)2 RegisteredMicroserviceInstanceResponse (org.apache.servicecomb.service.center.client.model.RegisteredMicroserviceInstanceResponse)2 SchemaInfo (org.apache.servicecomb.service.center.client.model.SchemaInfo)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 EventBus (com.google.common.eventbus.EventBus)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 URIBuilder (org.apache.http.client.utils.URIBuilder)1 OperationException (org.apache.servicecomb.config.center.client.exception.OperationException)1