Search in sources :

Example 16 with ServiceErrorRestRep

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;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) ServiceErrorRestRep(com.emc.storageos.model.errorhandling.ServiceErrorRestRep) AuthSvcInternalApiClientIterator(com.emc.storageos.security.authentication.AuthSvcInternalApiClientIterator) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) FatalSecurityException(com.emc.storageos.security.exceptions.FatalSecurityException) SecurityException(com.emc.storageos.security.exceptions.SecurityException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 17 with ServiceErrorRestRep

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;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) ServiceErrorRestRep(com.emc.storageos.model.errorhandling.ServiceErrorRestRep) ClientHandlerException(com.sun.jersey.api.client.ClientHandlerException) GeoException(com.emc.storageos.security.geo.exceptions.GeoException)

Example 18 with ServiceErrorRestRep

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;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) ServiceErrorRestRep(com.emc.storageos.model.errorhandling.ServiceErrorRestRep) ServiceErrorException(com.emc.vipr.client.exceptions.ServiceErrorException) ViPRHttpException(com.emc.vipr.client.exceptions.ViPRHttpException) ClientHandlerException(com.sun.jersey.api.client.ClientHandlerException) ServiceErrorException(com.emc.vipr.client.exceptions.ServiceErrorException) ViPRHttpException(com.emc.vipr.client.exceptions.ViPRHttpException)

Example 19 with ServiceErrorRestRep

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));
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) ServiceErrorRestRep(com.emc.storageos.model.errorhandling.ServiceErrorRestRep)

Example 20 with ServiceErrorRestRep

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;
}
Also used : ServiceErrorRestRep(com.emc.storageos.model.errorhandling.ServiceErrorRestRep)

Aggregations

ServiceErrorRestRep (com.emc.storageos.model.errorhandling.ServiceErrorRestRep)22 ClientResponse (com.sun.jersey.api.client.ClientResponse)8 AuthSvcInternalApiClientIterator (com.emc.storageos.security.authentication.AuthSvcInternalApiClientIterator)4 SecurityException (com.emc.storageos.security.exceptions.SecurityException)4 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)4 ClientHandlerException (com.sun.jersey.api.client.ClientHandlerException)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 FatalSecurityException (com.emc.storageos.security.exceptions.FatalSecurityException)3 InternalServerErrorException (com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException)3 ServiceErrorException (com.emc.vipr.client.exceptions.ServiceErrorException)2 Response (javax.ws.rs.core.Response)2 CustomConfigPreviewRep (com.emc.storageos.model.customconfig.CustomConfigPreviewRep)1 GeoException (com.emc.storageos.security.geo.exceptions.GeoException)1 ServiceErrorFactory.toServiceErrorRestRep (com.emc.storageos.svcs.errorhandling.resources.ServiceErrorFactory.toServiceErrorRestRep)1 ViPRHttpException (com.emc.vipr.client.exceptions.ViPRHttpException)1 Locale (java.util.Locale)1 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)1 StatusType (javax.ws.rs.core.Response.StatusType)1