use of org.wso2.carbon.apimgt.rest.api.util.exception.BadRequestException in project charon by wso2.
the class AbstractSCIMObject method setLastModified.
/*
* set the last modified date and time of the resource
*
* @param lastModifiedDate
*/
public void setLastModified(Date lastModifiedDate) throws CharonException, BadRequestException {
// create the lastModified date attribute as defined in schema.
SimpleAttribute lastModifiedAttribute = (SimpleAttribute) DefaultAttributeFactory.createAttribute(SCIMSchemaDefinitions.LAST_MODIFIED, new SimpleAttribute(SCIMConstants.CommonSchemaConstants.LAST_MODIFIED, lastModifiedDate));
// check meta complex attribute already exist.
if (getMetaAttribute() != null) {
ComplexAttribute metaAttribute = getMetaAttribute();
// check last modified attribute already exist
if (metaAttribute.isSubAttributeExist(lastModifiedAttribute.getName())) {
metaAttribute.removeSubAttribute(lastModifiedAttribute.getName());
metaAttribute.setSubAttribute(lastModifiedAttribute);
} else {
metaAttribute.setSubAttribute(lastModifiedAttribute);
}
} else {
// create meta attribute and set the sub attribute.
createMetaAttribute();
getMetaAttribute().setSubAttribute(lastModifiedAttribute);
}
}
use of org.wso2.carbon.apimgt.rest.api.util.exception.BadRequestException in project carbon-apimgt by wso2.
the class RestApiUtilTest method testHandleBadRequest.
@Test
public void testHandleBadRequest() {
String errorMessage = "Application name or owner should not be empty or null.";
Log log = Mockito.mock(Log.class);
PowerMockito.mockStatic(LogFactory.class);
PowerMockito.when(LogFactory.getLog(Mockito.any(Class.class))).thenReturn(log);
Exception exceptionCaught = null;
try {
RestApiUtil.handleBadRequest(errorMessage, log);
} catch (BadRequestException exception) {
exceptionCaught = exception;
}
Assert.assertEquals(errorMessage, exceptionCaught.getMessage());
Mockito.verify(log).error(errorMessage);
}
use of org.wso2.carbon.apimgt.rest.api.util.exception.BadRequestException in project carbon-apimgt by wso2.
the class RestApiUtil method handleBadRequest.
/**
* Logs the error, builds a BadRequestException with specified details and throws it
*
* @param errorHandlers A List of error handler objects containing the error information
* @param log Log instance
* @throws BadRequestException
*/
public static void handleBadRequest(List<ErrorHandler> errorHandlers, Log log) throws BadRequestException {
BadRequestException badRequestException = buildBadRequestException(errorHandlers);
StringBuilder builder = new StringBuilder();
for (int i = 0; i < errorHandlers.size(); i++) {
ErrorHandler handler = errorHandlers.get(i);
builder.append(handler.getErrorMessage());
if (StringUtils.isNotBlank(handler.getErrorDescription())) {
builder.append(":");
builder.append(handler.getErrorDescription());
}
if (i < errorHandlers.size() - 1) {
builder.append(", ");
}
}
log.error(builder.toString());
throw badRequestException;
}
use of org.wso2.carbon.apimgt.rest.api.util.exception.BadRequestException in project carbon-apimgt by wso2.
the class RestApiUtil method handleMetaInformationFailureError.
/**
* Logs the error, builds a BadRequestException with specified details and throws it
*
* @param description description of the error
* @param t Throwable instance
* @param log Log instance
* @throws BadRequestException
*/
public static void handleMetaInformationFailureError(String description, Throwable t, Log log) throws BadRequestException {
BadRequestException badRequestException = buildBadRequestException(description);
log.error(description, t);
throw badRequestException;
}
use of org.wso2.carbon.apimgt.rest.api.util.exception.BadRequestException in project carbon-apimgt by wso2.
the class RestApiUtil method handleBadRequest.
/**
* Logs the error, builds a BadRequestException with specified details and throws it
*
* @param errorHandler ErrorHandler object containing the error information
* @param log Log instance
* @throws BadRequestException
*/
public static void handleBadRequest(ErrorHandler errorHandler, Log log) throws BadRequestException {
BadRequestException badRequestException = buildBadRequestException(errorHandler);
log.error(errorHandler.getErrorMessage());
throw badRequestException;
}
Aggregations