Search in sources :

Example 6 with ServiceErrorRestRep

use of com.emc.storageos.model.errorhandling.ServiceErrorRestRep in project coprhd-controller by CoprHD.

the class ErrorHandlingTest method assertResponse.

private void assertResponse(final ClientResponse actualResponse, final int expectedStatusCode, final int expectedServiceCode) {
    Assert.assertEquals(expectedStatusCode, actualResponse.getStatus());
    try {
        final ServiceErrorRestRep error = actualResponse.getEntity(ServiceErrorRestRep.class);
        Assert.assertEquals(expectedServiceCode, error.getCode());
    } catch (final ClientHandlerException e) {
        Assert.fail("Expected a ServiceError object");
    }
}
Also used : ClientHandlerException(com.sun.jersey.api.client.ClientHandlerException) ServiceErrorRestRep(com.emc.storageos.model.errorhandling.ServiceErrorRestRep)

Example 7 with ServiceErrorRestRep

use of com.emc.storageos.model.errorhandling.ServiceErrorRestRep in project coprhd-controller by CoprHD.

the class CustomConfigs method preview.

public static void preview(String configType, String scopeType, String scopeValue, String value) {
    try {
        CustomConfigPreviewRep preview = CustomConfigUtils.generatePreview(configType, scopeType, scopeValue, value);
        renderJSON(preview);
    } catch (ServiceErrorException ex) {
        ServiceErrorRestRep error = ex.getServiceError();
        renderJSON(error);
    }
}
Also used : ServiceErrorRestRep(com.emc.storageos.model.errorhandling.ServiceErrorRestRep) CustomConfigPreviewRep(com.emc.storageos.model.customconfig.CustomConfigPreviewRep) ServiceErrorException(com.emc.vipr.client.exceptions.ServiceErrorException)

Example 8 with ServiceErrorRestRep

use of com.emc.storageos.model.errorhandling.ServiceErrorRestRep in project coprhd-controller by CoprHD.

the class UserInfoHelper method getUserDetails.

/**
 * Gets the groups a user is a member of.
 *
 * @param username the name of the user
 * @return UserGroupList
 */
public UserDetails getUserDetails(String username, StringBuilder error) {
    String endpoint = null;
    String param;
    try {
        param = "?username=" + URLEncoder.encode(username, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw APIException.badRequests.unableToEncodeString(username, e);
    }
    int attempts = 0;
    while (attempts < _MAX_VALIDATION_RETRIES) {
        _log.debug("Get user details attempt {}", ++attempts);
        AuthSvcInternalApiClientIterator authSvcClientItr = new AuthSvcInternalApiClientIterator(_authSvcEndPointLocator, _coordinator);
        try {
            if (authSvcClientItr.hasNext()) {
                endpoint = authSvcClientItr.peek().toString();
                _log.info("getUserDetails(): {}", endpoint);
                final ClientResponse response = authSvcClientItr.get(URI.create(_URI_GET_USER_GROUPS + param));
                final int status = response.getStatus();
                _log.debug("Status: {}", status);
                if (status == ClientResponse.Status.OK.getStatusCode()) {
                    return response.getEntity(UserDetails.class);
                } 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 null;
                } else {
                    _log.warn("Unexpected response code {}.", status);
                }
            }
        } catch (Exception e) {
            _log.error("Exception while getting user groups. Details: " + e.getLocalizedMessage(), e);
        }
    }
    throw SecurityException.retryables.requiredServiceUnvailable(ServiceLocatorInfo.AUTH_SVC.getServiceName());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) ServiceErrorRestRep(com.emc.storageos.model.errorhandling.ServiceErrorRestRep) AuthSvcInternalApiClientIterator(com.emc.storageos.security.authentication.AuthSvcInternalApiClientIterator) UnsupportedEncodingException(java.io.UnsupportedEncodingException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) SecurityException(com.emc.storageos.security.exceptions.SecurityException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 9 with ServiceErrorRestRep

use of com.emc.storageos.model.errorhandling.ServiceErrorRestRep in project coprhd-controller by CoprHD.

the class ServiceCodeExceptionMapper method toResponse.

@Override
public Response toResponse(final Exception t) {
    final Throwable e = getException(t);
    final Locale preferedLocale = getPreferedLocale(headers);
    final ServiceErrorRestRep serviceError = toServiceError(e, preferedLocale);
    final StatusType status = getHTTPStatus(e, info);
    // Just get the ServiceCode from the ServiceError
    final int code = serviceError.getCode();
    // CQs 603808, 603811
    // Check for those WebApplicationExceptions which result from the XML parser
    // correctly processing its input. Stack traces are not necessary and should
    // be filtered out in order not to raise undue concerns
    String prefix = "Responding to internal " + code + " with HTTP " + status;
    if (isStackTracePrinted(e)) {
        _log.warn(prefix + "; Caused by", e);
    } else {
        _log.warn(prefix + "; Caused by " + e.getMessage());
    }
    final ResponseBuilder builder = Response.status(status);
    if (status.getStatusCode() == SERVICE_UNAVAILABLE.getStatusCode()) {
        // recommend how many seconds to wait before retrying
        builder.header("Retry-After", "30");
    }
    builder.type(getPreferredMediaType(headers));
    builder.entity(serviceError);
    return builder.build();
}
Also used : Locale(java.util.Locale) ServiceErrorFactory.toServiceErrorRestRep(com.emc.storageos.svcs.errorhandling.resources.ServiceErrorFactory.toServiceErrorRestRep) ServiceErrorRestRep(com.emc.storageos.model.errorhandling.ServiceErrorRestRep) StatusType(javax.ws.rs.core.Response.StatusType) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder)

Example 10 with ServiceErrorRestRep

use of com.emc.storageos.model.errorhandling.ServiceErrorRestRep in project coprhd-controller by CoprHD.

the class BaseServiceCodeExceptionTest method assertException.

protected void assertException(final String expectedMessage, final int expectedServiceCode, final String expectedDescription, final int expectedStatus, final Exception actualException) {
    final Response response = mapper.toResponse(actualException);
    assertResponse(expectedStatus, response);
    Object entity = response.getEntity();
    Assert.assertTrue("The response is not a ServiceError", entity instanceof ServiceErrorRestRep);
    final ServiceErrorRestRep error = (ServiceErrorRestRep) entity;
    assertServiceError(expectedMessage, expectedServiceCode, expectedDescription, error);
}
Also used : Response(javax.ws.rs.core.Response) 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