use of org.wso2.carbon.apimgt.rest.api.authenticator.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();
}
use of org.wso2.carbon.apimgt.rest.api.authenticator.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);
}
use of org.wso2.carbon.apimgt.rest.api.authenticator.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());
}
use of org.wso2.carbon.apimgt.rest.api.authenticator.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>());
}
use of org.wso2.carbon.apimgt.rest.api.authenticator.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();
}
}
Aggregations