use of org.apache.servicecomb.service.center.client.exception.OperationException 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);
}
}
use of org.apache.servicecomb.service.center.client.exception.OperationException 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);
}
}
use of org.apache.servicecomb.service.center.client.exception.OperationException in project java-chassis by ServiceComb.
the class ServiceCenterClient method updateServiceSchemaContext.
@Override
public boolean updateServiceSchemaContext(String serviceId, SchemaInfo schemaInfo) {
try {
CreateSchemaRequest request = new CreateSchemaRequest();
request.setSchema(schemaInfo.getSchema());
request.setSummary(schemaInfo.getSummary());
HttpResponse response = httpClient.putHttpRequest("/registry/microservices/" + serviceId + "/schemas/" + schemaInfo.getSchemaId(), null, HttpUtils.serialize(request));
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);
}
}
use of org.apache.servicecomb.service.center.client.exception.OperationException 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);
}
}
use of org.apache.servicecomb.service.center.client.exception.OperationException in project incubator-servicecomb-java-chassis by apache.
the class ServiceCenterClient method updateServiceSchemaContext.
@Override
public boolean updateServiceSchemaContext(String serviceId, SchemaInfo schemaInfo) {
try {
CreateSchemaRequest request = new CreateSchemaRequest();
request.setSchema(schemaInfo.getSchema());
request.setSummary(schemaInfo.getSummary());
HttpResponse response = httpClient.putHttpRequest("/registry/microservices/" + serviceId + "/schemas/" + schemaInfo.getSchemaId(), null, HttpUtils.serialize(request));
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);
}
}
Aggregations