use of org.wso2.carbon.apimgt.rest.api.gateway.dto.ErrorDTO 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.gateway.dto.ErrorDTO in project carbon-apimgt by wso2.
the class EndpointsApiServiceImpl method endpointsEndpointIdGatewayConfigGet.
@Override
public Response endpointsEndpointIdGatewayConfigGet(String endpointId, String accept, Request request) throws NotFoundException {
try {
APIMgtAdminService apiMgtAdminService = APIManagerFactory.getInstance().getAPIMgtAdminService();
String endpointGatewayConfig = apiMgtAdminService.getEndpointGatewayConfig(endpointId);
if (endpointGatewayConfig != null) {
return Response.ok().entity(endpointGatewayConfig).build();
} else {
String msg = "Endpoint is not found with apiId : " + endpointId;
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(msg, 900314L, msg);
log.error(msg);
return Response.status(Response.Status.NOT_FOUND).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).entity(errorDTO).build();
}
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving gateway config of Endpoint : " + endpointId;
Map<String, String> paramList = new HashMap<>();
paramList.put(APIMgtConstants.ExceptionsConstants.ENDPOINT_ID, endpointId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).entity(errorDTO).build();
}
}
use of org.wso2.carbon.apimgt.rest.api.gateway.dto.ErrorDTO in project carbon-apimgt by wso2.
the class ExportApiServiceImpl method exportPoliciesThrottleGet.
/**
* Export throttle policies containing zip.
*
* @param accept Accept header value
* @param request msf4j request object
* @return Response object
* @throws NotFoundException if an error occurred when particular resource does not exits in the system.
*/
@Override
public Response exportPoliciesThrottleGet(String accept, Request request) throws NotFoundException {
String archiveName = "exported-policies";
// files will be written to following directory
String exportedPoliciesDirName = "exported-policies";
// archive will be here at following location tmp directory
String archiveDir = System.getProperty("java.io.tmpdir");
if (log.isDebugEnabled()) {
log.debug("Received export policies GET request ");
}
try {
APIMgtAdminService apiMgtAdminService = APIManagerFactory.getInstance().getAPIMgtAdminService();
PolicyExportManager policyExportManager = new PolicyExportManager(apiMgtAdminService);
// create archive and get the archive location
String zippedFilePath = policyExportManager.createArchiveFromExecutionPlans(exportedPoliciesDirName, archiveDir, archiveName);
APIFileUtils.deleteDirectory(exportedPoliciesDirName);
File exportedApiArchiveFile = new File(zippedFilePath);
Response.ResponseBuilder responseBuilder = Response.status(Response.Status.OK).entity(exportedApiArchiveFile);
responseBuilder.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM).header("Content-Disposition", "attachment; filename=\"" + exportedApiArchiveFile.getName() + "\"");
Response response = responseBuilder.build();
return response;
} catch (APIManagementException e) {
String errorMessage = "Error while exporting policies";
log.error(errorMessage, e);
org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
use of org.wso2.carbon.apimgt.rest.api.gateway.dto.ErrorDTO in project carbon-apimgt by wso2.
the class GatewaysApiServiceImpl method gatewaysRegisterPost.
/**
* Register gateway
*
* @param body RegistrationDTO
* @param contentType Content-Type header value
* @return Registration summary details
* @throws NotFoundException If failed to register gateway
*/
@Override
public Response gatewaysRegisterPost(RegistrationDTO body, String contentType, Request request) throws NotFoundException {
try {
LabelInfoDTO labelInfoDTO = body.getLabelInfo();
if (labelInfoDTO != null) {
APIMgtAdminService adminService = RestApiUtil.getAPIMgtAdminService();
String overwriteLabels = labelInfoDTO.getOverwriteLabels();
List<Label> labels = MappingUtil.convertToLabels(labelInfoDTO.getLabelList());
adminService.registerGatewayLabels(labels, overwriteLabels);
RegistrationSummary registrationSummary = adminService.getRegistrationSummary();
return Response.ok().entity(MappingUtil.toRegistrationSummaryDTO(registrationSummary)).build();
} else {
String errorMessage = "Label information cannot be null";
APIMgtResourceNotFoundException e = new APIMgtResourceNotFoundException(errorMessage, ExceptionCodes.LABEL_INFORMATION_CANNOT_BE_NULL);
HashMap<String, String> paramList = new HashMap<String, String>();
org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
} catch (APIManagementException e) {
String errorMessage = "Error while registering the gateway";
HashMap<String, String> paramList = new HashMap<String, String>();
org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
use of org.wso2.carbon.apimgt.rest.api.gateway.dto.ErrorDTO in project carbon-apimgt by wso2.
the class PoliciesApiServiceImpl method policiesGet.
@Override
public Response policiesGet(String accept, Request request) throws NotFoundException {
PolicyListDTO policyListDTO = new PolicyListDTO();
try {
APIMgtAdminService adminService = RestApiUtil.getAPIMgtAdminService();
List<PolicyDTO> policyDTOList = MappingUtil.convertToPolicyDtoList(adminService.getAllPolicies());
policyListDTO.setList(policyDTOList);
policyListDTO.setCount(policyDTOList.size());
return Response.ok().entity(policyListDTO).build();
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving Policies";
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
Aggregations