Search in sources :

Example 1 with CreateMicroserviceRequest

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

the class ServiceCenterClient method registerMicroservice.

@Override
public RegisteredMicroserviceResponse registerMicroservice(Microservice microservice) {
    try {
        CreateMicroserviceRequest request = new CreateMicroserviceRequest();
        request.setService(microservice);
        HttpResponse response = httpClient.postHttpRequest("/registry/microservices", null, HttpUtils.serialize(request));
        if (response.getStatusCode() == HttpStatus.SC_OK) {
            return HttpUtils.deserialize(response.getContent(), RegisteredMicroserviceResponse.class);
        }
        sendUnAuthorizedEvent(response);
        throw new OperationException("register service fails, statusCode = " + response.getStatusCode() + "; message = " + response.getMessage() + "; content = " + response.getContent());
    } catch (IOException e) {
        throw new OperationException("register service fails", e);
    }
}
Also used : CreateMicroserviceRequest(org.apache.servicecomb.service.center.client.model.CreateMicroserviceRequest) HttpResponse(org.apache.servicecomb.http.client.common.HttpResponse) IOException(java.io.IOException) OperationException(org.apache.servicecomb.service.center.client.exception.OperationException)

Aggregations

IOException (java.io.IOException)1 HttpResponse (org.apache.servicecomb.http.client.common.HttpResponse)1 OperationException (org.apache.servicecomb.service.center.client.exception.OperationException)1 CreateMicroserviceRequest (org.apache.servicecomb.service.center.client.model.CreateMicroserviceRequest)1