Search in sources :

Example 96 with ErrorDTO

use of org.wso2.carbon.apimgt.rest.api.gateway.dto.ErrorDTO in project carbon-apimgt by wso2.

the class RESTAPISecurityInterceptor method handleSecurityError.

/**
 * Handles error condition
 *
 * @param errorHandler Security error code
 * @param responder    HttpResponder instance which is used send error messages back to the client
 */
private void handleSecurityError(ErrorHandler errorHandler, Response responder) {
    HashMap<String, String> paramList = new HashMap<>();
    ErrorDTO errorDTO = RestApiUtil.getErrorDTO(errorHandler, paramList);
    responder.setStatus(errorHandler.getHttpStatusCode());
    responder.setHeader(javax.ws.rs.core.HttpHeaders.WWW_AUTHENTICATE, RestApiConstants.AUTH_TYPE_OAUTH2);
    responder.setEntity(errorDTO);
    responder.setMediaType(MediaType.APPLICATION_JSON);
    responder.send();
}
Also used : HashMap(java.util.HashMap) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)

Example 97 with ErrorDTO

use of org.wso2.carbon.apimgt.rest.api.gateway.dto.ErrorDTO in project carbon-apimgt by wso2.

the class BadRequestExceptionTestCase method testGetMessage.

@Test
public void testGetMessage() throws Exception {
    ErrorDTO errorDTO = new ErrorDTO();
    errorDTO.setDescription(testMessage);
    BadRequestException badRequestException = new BadRequestException(errorDTO);
    String message = badRequestException.getMessage();
    Assert.assertEquals(message, testMessage);
}
Also used : ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) BadRequestException(org.wso2.carbon.apimgt.rest.api.common.exception.BadRequestException) Test(org.testng.annotations.Test)

Example 98 with ErrorDTO

use of org.wso2.carbon.apimgt.rest.api.gateway.dto.ErrorDTO in project carbon-apimgt by wso2.

the class RestApiUtilTestCase method testGetErrorDTO.

@Test(description = "Testing get Error DTO")
public void testGetErrorDTO() throws Exception {
    ErrorHandler errorHandler = Mockito.mock(ErrorHandler.class);
    when(errorHandler.getErrorCode()).thenReturn((long) 900300);
    when(errorHandler.getErrorMessage()).thenReturn("Lifecycle exception occurred");
    when(errorHandler.getErrorDescription()).thenReturn("Error occurred while changing lifecycle state");
    ErrorDTO errorDTOExpected = new ErrorDTO();
    errorDTOExpected.setCode((long) 900300);
    errorDTOExpected.setMessage("Lifecycle exception occurred");
    errorDTOExpected.setDescription("Error occurred while changing lifecycle state");
    ErrorDTO errorDTO1 = RestApiUtil.getErrorDTO(errorHandler);
    Assert.assertEquals(errorDTO1.getCode(), errorDTOExpected.getCode());
    Assert.assertEquals(errorDTO1.getMessage(), errorDTOExpected.getMessage());
    Assert.assertEquals(errorDTO1.getDescription(), errorDTOExpected.getDescription());
}
Also used : ErrorHandler(org.wso2.carbon.apimgt.core.exception.ErrorHandler) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 99 with ErrorDTO

use of org.wso2.carbon.apimgt.rest.api.gateway.dto.ErrorDTO in project carbon-apimgt by wso2.

the class RestApiUtilTestCase method testGetErrorDTO1.

@Test(description = "Test get Error DTO")
public void testGetErrorDTO1() throws Exception {
    Map<String, String> paramList = new HashMap<>();
    ErrorDTO errorDTOExpected = new ErrorDTO();
    errorDTOExpected.setCode((long) 900300);
    errorDTOExpected.setMessage("Lifecycle exception occurred");
    errorDTOExpected.setDescription("Error occurred while changing lifecycle state");
    ErrorHandler errorHandler = Mockito.mock(ErrorHandler.class);
    when(errorHandler.getErrorCode()).thenReturn((long) 900300);
    when(errorHandler.getErrorMessage()).thenReturn("Lifecycle exception occurred");
    when(errorHandler.getErrorDescription()).thenReturn("Error occurred while changing lifecycle state");
    ErrorDTO errorDTO1 = RestApiUtil.getErrorDTO(errorHandler, paramList);
    Assert.assertEquals(errorDTO1.getCode(), errorDTOExpected.getCode());
    Assert.assertEquals(errorDTO1.getMessage(), errorDTOExpected.getMessage());
    Assert.assertEquals(errorDTO1.getMoreInfo(), new HashMap<String, String>());
}
Also used : ErrorHandler(org.wso2.carbon.apimgt.core.exception.ErrorHandler) HashMap(java.util.HashMap) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 100 with ErrorDTO

use of org.wso2.carbon.apimgt.rest.api.gateway.dto.ErrorDTO in project carbon-apimgt by wso2.

the class CompositeApisApiServiceImpl method compositeApisGet.

@Override
public Response compositeApisGet(Integer limit, Integer offset, String query, String ifNoneMatch, Request request) throws NotFoundException {
    String username = RestApiUtil.getLoggedInUsername(request);
    CompositeAPIListDTO apiListDTO = null;
    try {
        apiListDTO = CompositeAPIMappingUtil.toCompositeAPIListDTO(RestApiUtil.getConsumer(username).searchCompositeAPIs(query, offset, limit));
        return Response.ok().entity(apiListDTO).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error while retrieving APIs";
        HashMap<String, String> paramList = new HashMap<String, String>();
        ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList, e);
        return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) HashMap(java.util.HashMap) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) CompositeAPIListDTO(org.wso2.carbon.apimgt.rest.api.store.dto.CompositeAPIListDTO)

Aggregations

ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)170 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)154 HashMap (java.util.HashMap)108 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)48 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)45 APIMgtAdminService (org.wso2.carbon.apimgt.core.api.APIMgtAdminService)40 Map (java.util.Map)27 APIMgtResourceNotFoundException (org.wso2.carbon.apimgt.core.exception.APIMgtResourceNotFoundException)15 ErrorHandler (org.wso2.carbon.apimgt.core.exception.ErrorHandler)15 IOException (java.io.IOException)11 Application (org.wso2.carbon.apimgt.core.models.Application)11 URI (java.net.URI)10 URISyntaxException (java.net.URISyntaxException)10 ArrayList (java.util.ArrayList)9 DocumentInfo (org.wso2.carbon.apimgt.core.models.DocumentInfo)9 Response (javax.ws.rs.core.Response)7 Subscription (org.wso2.carbon.apimgt.core.models.Subscription)7 API (org.wso2.carbon.apimgt.core.models.API)6 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)6 Label (org.wso2.carbon.apimgt.core.models.Label)6