Search in sources :

Example 41 with BadRequestException

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);
    }
}
Also used : SimpleAttribute(org.wso2.charon3.core.attributes.SimpleAttribute) ComplexAttribute(org.wso2.charon3.core.attributes.ComplexAttribute)

Example 42 with BadRequestException

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);
}
Also used : Log(org.apache.commons.logging.Log) BadRequestException(org.wso2.carbon.apimgt.rest.api.util.exception.BadRequestException) AuthorizationFailedException(org.wso2.carbon.registry.core.secure.AuthorizationFailedException) ConflictException(org.wso2.carbon.apimgt.rest.api.util.exception.ConflictException) ForbiddenException(org.wso2.carbon.apimgt.rest.api.util.exception.ForbiddenException) APIMgtAuthorizationFailedException(org.wso2.carbon.apimgt.api.APIMgtAuthorizationFailedException) ApplicationNameWhiteSpaceValidationException(org.wso2.carbon.apimgt.api.ApplicationNameWhiteSpaceValidationException) BadRequestException(org.wso2.carbon.apimgt.rest.api.util.exception.BadRequestException) DuplicateAPIException(org.wso2.carbon.apimgt.api.model.DuplicateAPIException) APIMgtResourceAlreadyExistsException(org.wso2.carbon.apimgt.api.APIMgtResourceAlreadyExistsException) ApplicationNameWithInvalidCharactersException(org.wso2.carbon.apimgt.api.ApplicationNameWithInvalidCharactersException) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ResourceNotFoundException(org.wso2.carbon.registry.core.exceptions.ResourceNotFoundException) APIMgtResourceNotFoundException(org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 43 with 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 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;
}
Also used : ErrorHandler(org.wso2.carbon.apimgt.api.ErrorHandler) BadRequestException(org.wso2.carbon.apimgt.rest.api.util.exception.BadRequestException)

Example 44 with 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;
}
Also used : BadRequestException(org.wso2.carbon.apimgt.rest.api.util.exception.BadRequestException)

Example 45 with 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;
}
Also used : BadRequestException(org.wso2.carbon.apimgt.rest.api.util.exception.BadRequestException)

Aggregations

BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)63 CharonException (org.wso2.charon3.core.exceptions.CharonException)31 SimpleAttribute (org.wso2.charon3.core.attributes.SimpleAttribute)30 ComplexAttribute (org.wso2.charon3.core.attributes.ComplexAttribute)27 MultiValuedAttribute (org.wso2.charon3.core.attributes.MultiValuedAttribute)23 HashMap (java.util.HashMap)22 Attribute (org.wso2.charon3.core.attributes.Attribute)20 InternalErrorException (org.wso2.charon3.core.exceptions.InternalErrorException)19 SCIMResponse (org.wso2.charon3.core.protocol.SCIMResponse)19 SCIMResourceTypeSchema (org.wso2.charon3.core.schema.SCIMResourceTypeSchema)19 NotFoundException (org.wso2.charon3.core.exceptions.NotFoundException)18 JSONObject (org.json.JSONObject)16 AbstractSCIMObject (org.wso2.charon3.core.objects.AbstractSCIMObject)16 JSONException (org.json.JSONException)15 JSONEncoder (org.wso2.charon3.core.encoder.JSONEncoder)15 JSONDecoder (org.wso2.charon3.core.encoder.JSONDecoder)14 NotImplementedException (org.wso2.charon3.core.exceptions.NotImplementedException)14 User (org.wso2.charon3.core.objects.User)12 JSONArray (org.json.JSONArray)11 BadRequestException (org.wso2.carbon.apimgt.rest.api.util.exception.BadRequestException)10