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");
}
}
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);
}
}
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());
}
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();
}
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);
}
Aggregations