use of org.wso2.carbon.apimgt.rest.api.gateway.dto.ErrorDTO in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method apisApiIdGatewayConfigGet.
/**
* Retrieve API's gateway configuration
*
* @param apiId UUID of the API
* @param request msf4j request object
* @return 200 OK if the opration was successful
* @throws NotFoundException If failed to retrieve API gateway configuration
*/
@Override
public Response apisApiIdGatewayConfigGet(String apiId, String accept, Request request) throws NotFoundException {
try {
APIMgtAdminService apiMgtAdminService = APIManagerFactory.getInstance().getAPIMgtAdminService();
String apiGatewayConfig = null;
apiGatewayConfig = apiMgtAdminService.getAPIGatewayServiceConfig(apiId);
if (apiGatewayConfig != null) {
return Response.ok().entity(apiGatewayConfig).build();
} else {
String msg = "API is not found with apiId : " + apiId;
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 API : " + apiId;
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.API_ID, apiId);
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 ApisApiServiceImpl method apisGet.
/**
* Retrieve a list of APIs with given gateway labels and status.
*
* @param labels Gateway labels
* @param status Lifecycle status
* @param request msf4j request object
* @return 200 OK if the opration was successful
* @throws NotFoundException If failed to retrieve APIs
*/
@Override
public Response apisGet(String labels, String status, Request request) throws NotFoundException {
APIListDTO apiListDTO;
try {
APIMgtAdminService adminService = RestApiUtil.getAPIMgtAdminService();
if (labels != null && !labels.isEmpty()) {
String[] gatewayLabels = labels.split(",");
List<String> labelList = new ArrayList<String>(Arrays.asList(gatewayLabels));
if (status != null && !status.isEmpty()) {
apiListDTO = MappingUtil.toAPIListDTO(adminService.getAPIsByStatus(labelList, status));
return Response.ok().entity(apiListDTO).build();
} else {
apiListDTO = MappingUtil.toAPIListDTO(adminService.getAPIsByGatewayLabel(labelList));
return Response.ok().entity(apiListDTO).build();
}
} else {
apiListDTO = new APIListDTO();
return Response.ok().entity(apiListDTO).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 ApplicationsApiServiceImpl method applicationsGet.
@Override
public Response applicationsGet(String accept, Request request) throws NotFoundException {
try {
APIMgtAdminService apiMgtAdminService = APIManagerFactory.getInstance().getAPIMgtAdminService();
List<Application> applicationList = apiMgtAdminService.getAllApplications();
ApplicationListDTO applicationListDTO = new ApplicationListDTO();
applicationListDTO.setList(MappingUtil.convertToApplicationDtoList(applicationList));
return Response.ok(applicationListDTO).build();
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving Applications.";
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 RestApiUtil method getErrorDTO.
/**
* Returns a generic errorDTO
*
* @param message specifies the error message
* @param code error code.
* @param description error description.
* @return A generic errorDTO with the specified details
*/
public static ErrorDTO getErrorDTO(String message, Long code, String description) {
ErrorDTO errorDTO = new ErrorDTO();
errorDTO.setCode(code);
errorDTO.setMessage(message);
errorDTO.setDescription(description);
return errorDTO;
}
use of org.wso2.carbon.apimgt.rest.api.gateway.dto.ErrorDTO in project carbon-apimgt by wso2.
the class ApiLoggingConfigsApiServiceImpl method apiLoggingConfigsGet.
public Response apiLoggingConfigsGet(MessageContext messageContext) {
ErrorDTO errorObject = new ErrorDTO();
Response.Status status = Response.Status.NOT_IMPLEMENTED;
errorObject.setCode(200);
errorObject.setMessage(status.toString());
List<APILoggingConfigDTO> loggingAPIDTOList = new ArrayList<>();
try {
List<APILogInfoDTO> apiLoggerList = LoggingMgtDAO.getInstance().retrieveAllAPILoggerList();
for (APILogInfoDTO apiLogInfo : apiLoggerList) {
APILoggingConfigDTO apiLoggingConfigDTO = new APILoggingConfigDTO();
apiLoggingConfigDTO.setContext(apiLogInfo.getContext());
apiLoggingConfigDTO.setLogLevel(apiLogInfo.getLogLevel());
loggingAPIDTOList.add(apiLoggingConfigDTO);
}
} catch (APIManagementException e) {
log.error("Error while retrieving api logger list");
}
APILoggingConfigListDTO apiLoggingConfigListDTO = new APILoggingConfigListDTO();
apiLoggingConfigListDTO.apis(loggingAPIDTOList);
return Response.ok().entity(apiLoggingConfigListDTO).build();
}
Aggregations