Search in sources :

Example 1 with BadRequestException

use of org.wso2.carbon.identity.user.endpoint.exceptions.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 2 with BadRequestException

use of org.wso2.carbon.identity.user.endpoint.exceptions.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 3 with BadRequestException

use of org.wso2.carbon.identity.user.endpoint.exceptions.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 4 with BadRequestException

use of org.wso2.carbon.identity.user.endpoint.exceptions.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 5 with BadRequestException

use of org.wso2.carbon.identity.user.endpoint.exceptions.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)138 SCIMResourceTypeSchema (org.wso2.charon3.core.schema.SCIMResourceTypeSchema)114 Test (org.testng.annotations.Test)104 SCIMResponse (org.wso2.charon3.core.protocol.SCIMResponse)103 User (org.wso2.charon3.core.objects.User)101 CharonException (org.wso2.charon3.core.exceptions.CharonException)97 JSONObject (org.json.JSONObject)83 SimpleAttribute (org.wso2.charon3.core.attributes.SimpleAttribute)58 JSONDecoder (org.wso2.charon3.core.encoder.JSONDecoder)56 ComplexAttribute (org.wso2.charon3.core.attributes.ComplexAttribute)54 Group (org.wso2.charon3.core.objects.Group)52 InternalErrorException (org.wso2.charon3.core.exceptions.InternalErrorException)47 MultiValuedAttribute (org.wso2.charon3.core.attributes.MultiValuedAttribute)44 NotFoundException (org.wso2.charon3.core.exceptions.NotFoundException)44 DataProvider (org.testng.annotations.DataProvider)42 HashMap (java.util.HashMap)41 NotImplementedException (org.wso2.charon3.core.exceptions.NotImplementedException)41 AbstractSCIMObject (org.wso2.charon3.core.objects.AbstractSCIMObject)39 Attribute (org.wso2.charon3.core.attributes.Attribute)28 Role (org.wso2.charon3.core.objects.Role)27