use of org.wso2.carbon.apimgt.rest.api.core.dto.EndpointListDTO in project carbon-apimgt by wso2.
the class ExternalResourcesApiServiceImpl method externalResourcesServicesGet.
/**
* Retrieve all service endpoints after service discovery
*
* @param ifNoneMatch If-None-Match header value
* @param ifModifiedSince If-Modified-Since header
* @param request msf4j request object
* @return A list of service endpoints available in the cluster(s)
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response externalResourcesServicesGet(String ifNoneMatch, String ifModifiedSince, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
try {
APIPublisher apiPublisher = RestAPIPublisherUtil.getApiPublisher(username);
List<Endpoint> endpointList = apiPublisher.discoverServiceEndpoints();
EndPointListDTO endPointListDTO = new EndPointListDTO();
for (Endpoint endpoint : endpointList) {
endPointListDTO.addListItem(MappingUtil.toEndPointDTO(endpoint));
}
endPointListDTO.setCount(endPointListDTO.getList().size());
return Response.ok().entity(endPointListDTO).build();
} catch (APIManagementException e) {
String errorMessage = "Error while discovering service endpoints";
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
} catch (IOException e) {
String errorMessage = "Error while Converting Endpoint Security Details in Endpoint";
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(errorMessage, 900313L, errorMessage);
log.error(errorMessage, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorDTO).build();
}
}
use of org.wso2.carbon.apimgt.rest.api.core.dto.EndpointListDTO in project carbon-apimgt by wso2.
the class EndpointsApiServiceImplTestCase method endpointsGetTest.
@Test
public void endpointsGetTest() throws Exception {
APIMgtAdminServiceImpl apiMgtAdminService = Mockito.mock(APIMgtAdminServiceImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(apiMgtAdminService);
Endpoint endpointOne = SampleTestObjectCreator.createUniqueEndpoint();
Endpoint endpointTwo = SampleTestObjectCreator.createUniqueEndpoint();
Endpoint endpointThree = SampleTestObjectCreator.createUniqueEndpoint();
List<Endpoint> endpointList = new ArrayList<>();
endpointList.add(endpointOne);
endpointList.add(endpointTwo);
endpointList.add(endpointThree);
Mockito.when(apiMgtAdminService.getAllEndpoints()).thenReturn(endpointList);
EndpointsApiServiceImpl endpointsApiService = new EndpointsApiServiceImpl();
Response response = endpointsApiService.endpointsGet(null, null, getRequest());
Assert.assertEquals(response.getStatus(), 200);
Assert.assertEquals(((EndpointListDTO) response.getEntity()).getList().size(), 3);
}
use of org.wso2.carbon.apimgt.rest.api.core.dto.EndpointListDTO in project carbon-apimgt by wso2.
the class EndpointsApiServiceImpl method endpointsGet.
@Override
public Response endpointsGet(Integer limit, String accept, Request request) throws NotFoundException {
EndpointListDTO endpointListDTO = new EndpointListDTO();
try {
APIMgtAdminService adminService = RestApiUtil.getAPIMgtAdminService();
List<Endpoint> endpointList = adminService.getAllEndpoints();
endpointListDTO.setList(MappingUtil.toEndpointListDto(endpointList));
endpointListDTO.setCount(endpointList.size());
return Response.ok().entity(endpointListDTO).build();
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving APIs";
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
use of org.wso2.carbon.apimgt.rest.api.core.dto.EndpointListDTO in project carbon-apimgt by wso2.
the class EndpointsApiServiceImpl method endpointsGet.
/**
* Retrieve all endpoints available
*
* @param ifNoneMatch If-None-Match header value
* @param ifModifiedSince If-Modified-Since header
* @param request msf4j request object
* @return A list of endpoints avaliable
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response endpointsGet(String ifNoneMatch, String ifModifiedSince, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
try {
APIPublisher apiPublisher = RestAPIPublisherUtil.getApiPublisher(username);
List<Endpoint> endpointList = apiPublisher.getAllEndpoints();
EndPointListDTO endPointListDTO = new EndPointListDTO();
for (Endpoint endpoint : endpointList) {
endPointListDTO.addListItem(MappingUtil.toEndPointDTO(endpoint));
}
endPointListDTO.setCount(endPointListDTO.getList().size());
return Response.ok().entity(endPointListDTO).build();
} catch (APIManagementException e) {
String errorMessage = "Error while get All Endpoint";
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
} catch (IOException e) {
String errorMessage = "Error while Converting Endpoint Security Details in Endpoint";
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(errorMessage, 900313L, errorMessage);
log.error(errorMessage, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorDTO).build();
}
}
Aggregations