use of com.emc.storageos.model.errorhandling.ServiceErrorRestRep in project coprhd-controller by CoprHD.
the class Validator method validatePrincipals.
/**
* Validates the principals within the tenant
*
* @param principalsToValidate
* @param error
* :a string representing that error that happened.
* @return true if all the principal are valid within the tenant
*/
public static boolean validatePrincipals(PrincipalsToValidate principalsToValidate, StringBuilder error) {
String endpoint = null;
principalsToValidate.setUsers(deDuplicate(principalsToValidate.getUsers()));
principalsToValidate.setGroups(deDuplicate(principalsToValidate.getGroups()));
principalsToValidate.setAltTenantUsers(deDuplicate(principalsToValidate.getAltTenantUsers()));
int attempts = 0;
while (attempts < _MAX_VALIDATION_RETRIES) {
_log.debug("Validation attempt {}", ++attempts);
AuthSvcInternalApiClientIterator authSvcClientItr = new AuthSvcInternalApiClientIterator(_authSvcEndPointLocator, _coordinator);
try {
if (authSvcClientItr.hasNext()) {
endpoint = authSvcClientItr.peek().toString();
_log.info("validatePrincipals(): {}", endpoint);
final ClientResponse response = authSvcClientItr.post(_URI_VALIDATE_PRINCIPALS, principalsToValidate);
final int status = response.getStatus();
_log.debug("Status: {}", status);
if (status == ClientResponse.Status.OK.getStatusCode()) {
return true;
} else if (status == ClientResponse.Status.BAD_REQUEST.getStatusCode() || status == ClientResponse.Status.INTERNAL_SERVER_ERROR.getStatusCode()) {
ServiceErrorRestRep errorXml = response.getEntity(ServiceErrorRestRep.class);
error.append(errorXml.getDetailedMessage());
return false;
} else {
_log.info("Unexpected response code {}.", status);
}
}
} catch (Exception e) {
_log.info("Exception connecting to {}. ", endpoint, e);
if (e.getMessage().contains("Read timed out")) {
throw InternalServerErrorException.internalServerErrors.authTimeout();
}
}
}
return false;
}
use of com.emc.storageos.model.errorhandling.ServiceErrorRestRep in project coprhd-controller by CoprHD.
the class GeoServiceExceptionFilter method handle.
@Override
public ClientResponse handle(ClientRequest request) throws ClientHandlerException {
ClientResponse response = getNext().handle(request);
int status = response.getStatus();
if (status >= 400 && status < 600) {
try {
ServiceErrorRestRep serviceError = response.getEntity(ServiceErrorRestRep.class);
if (serviceError != null) {
logAndThrow(status, serviceError);
} else {
String content = response.getEntity(String.class);
logAndThrow(status, content);
}
} catch (Exception e) {
// Cause to fall-through to default exception
log.error("Failed to parse exception from the remote VDC. Parsing error message", e);
String content = response.getEntity(String.class);
logAndThrow(status, content);
}
// Fallback for unknown entity types
}
return response;
}
use of com.emc.storageos.model.errorhandling.ServiceErrorRestRep in project coprhd-controller by CoprHD.
the class ExceptionOnErrorFilter method handle.
@Override
public ClientResponse handle(ClientRequest request) throws ClientHandlerException {
ClientResponse response = getNext().handle(request);
int status = response.getStatus();
if (status >= 400 && status < 600) {
if (isSupportedType(response.getType())) {
ServiceErrorRestRep serviceError;
try {
serviceError = response.getEntity(ServiceErrorRestRep.class);
} catch (Exception e) {
// Cause to fall-through to default exception
log.error("Error parsing error message", e);
serviceError = null;
}
if (serviceError != null) {
logAndThrow(new ServiceErrorException(status, serviceError));
}
}
// Fallback for unknown entity types
String content = response.getEntity(String.class);
logAndThrow(new ViPRHttpException(status, content));
}
return response;
}
use of com.emc.storageos.model.errorhandling.ServiceErrorRestRep in project coprhd-controller by CoprHD.
the class ApiTestUserGroup method changeUserGroupDomainAndExpectFailure.
private void changeUserGroupDomainAndExpectFailure(UserGroupRestRep restRep) {
UserGroupUpdateParam updateParam = getUserGroupUpdateParamFromRestRep(restRep);
Assert.assertNotNull(restRep);
updateParam.setDomain(getSecondDomain());
String editApi = getTestEditApi(restRep.getId());
ClientResponse clientResponseUserGroupEdit = rSys.path(editApi).put(ClientResponse.class, updateParam);
Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, clientResponseUserGroupEdit.getStatus());
final String partialExpectedErrorString = "Deleting or editing the domain of an user group is not allowed because";
final ServiceErrorRestRep actualErrorMsg = clientResponseUserGroupEdit.getEntity(ServiceErrorRestRep.class);
Assert.assertTrue(actualErrorMsg.getDetailedMessage().contains(partialExpectedErrorString));
}
use of com.emc.storageos.model.errorhandling.ServiceErrorRestRep in project coprhd-controller by CoprHD.
the class ServiceErrorFactory method toServiceErrorRestRep.
public static ServiceErrorRestRep toServiceErrorRestRep(final ServiceCoded coded, final Locale locale) {
final ServiceErrorRestRep error = new ServiceErrorRestRep();
error.setCode(coded.getServiceCode().getCode());
error.setRetryable(coded.isRetryable());
error.setCodeDescription(coded.getServiceCode().getSummary(locale));
error.setDetailedMessage(coded.getMessage(locale));
return error;
}
Aggregations