Search in sources :

Example 1 with EndpointListDTO

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();
    }
}
Also used : EndPointListDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.EndPointListDTO) Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) IOException(java.io.IOException)

Example 2 with EndpointListDTO

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);
}
Also used : Response(javax.ws.rs.core.Response) APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl) Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) ArrayList(java.util.ArrayList) EndpointListDTO(org.wso2.carbon.apimgt.rest.api.core.dto.EndpointListDTO) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with EndpointListDTO

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();
    }
}
Also used : APIMgtAdminService(org.wso2.carbon.apimgt.core.api.APIMgtAdminService) Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) EndpointListDTO(org.wso2.carbon.apimgt.rest.api.core.dto.EndpointListDTO)

Example 4 with EndpointListDTO

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();
    }
}
Also used : EndPointListDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.EndPointListDTO) Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) IOException(java.io.IOException)

Aggregations

Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)4 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)3 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)3 IOException (java.io.IOException)2 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)2 EndpointListDTO (org.wso2.carbon.apimgt.rest.api.core.dto.EndpointListDTO)2 EndPointListDTO (org.wso2.carbon.apimgt.rest.api.publisher.dto.EndPointListDTO)2 ArrayList (java.util.ArrayList)1 Response (javax.ws.rs.core.Response)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1 APIMgtAdminService (org.wso2.carbon.apimgt.core.api.APIMgtAdminService)1 APIMgtAdminServiceImpl (org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl)1