use of org.wso2.carbon.messaging.Header in project carbon-apimgt by wso2.
the class BlacklistApiServiceImpl method blacklistGet.
/**
* Get blacklist conditions.
*
* @param ifNoneMatch If-None-Match header value
* @param ifModifiedSince If-Modified-Since 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 blacklistGet(String ifNoneMatch, String ifModifiedSince, Request request) throws NotFoundException {
if (log.isDebugEnabled()) {
log.debug("Received BlockCondition GET request");
}
try {
APIMgtAdminService apiMgtAdminService = RestApiUtil.getAPIMgtAdminService();
List<BlockConditions> blockConditions = apiMgtAdminService.getBlockConditions();
BlockingConditionListDTO listDTO = BlockingConditionMappingUtil.fromBlockConditionListToListDTO(blockConditions);
return Response.ok().entity(listDTO).build();
} catch (APIManagementException e) {
String errorMessage = "Error occurred while getting blacklist ";
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
use of org.wso2.carbon.messaging.Header in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method apisApiIdGet.
/**
* Get API of given ID
*
* @param apiId API ID
* @param ifNoneMatch If-None-Match header value
* @param ifModifiedSince If-Modified-Since header value
* @param request msf4j request object
* @return API of the given ID
* @throws NotFoundException If failed to get the API
*/
@Override
public Response apisApiIdGet(String apiId, String ifNoneMatch, String ifModifiedSince, Request request) throws NotFoundException {
APIDTO apiToReturn = null;
try {
String username = RestApiUtil.getLoggedInUsername(request);
APIStore apiStore = RestApiUtil.getConsumer(username);
String existingFingerprint = apisApiIdGetFingerprint(apiId, ifNoneMatch, ifModifiedSince, request);
if (!StringUtils.isEmpty(ifNoneMatch) && !StringUtils.isEmpty(existingFingerprint) && ifNoneMatch.contains(existingFingerprint)) {
return Response.notModified().build();
}
API api = apiStore.getAPIbyUUID(apiId);
boolean isWSDLExists = apiStore.isWSDLExists(apiId);
apiToReturn = APIMappingUtil.toAPIDTO(api);
if (isWSDLExists) {
String wsdlUri = RestApiConstants.WSDL_URI_TEMPLATE.replace(RestApiConstants.APIID_PARAM, api.getId());
apiToReturn.setWsdlUri(wsdlUri);
}
return Response.ok().entity(apiToReturn).header(HttpHeaders.ETAG, "\"" + existingFingerprint + "\"").build();
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving 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()).entity(errorDTO).build();
}
}
use of org.wso2.carbon.messaging.Header in project carbon-apimgt by wso2.
the class ApplicationsApiServiceImpl method applicationsPost.
/**
* Adds a new application
*
* @param body Application details to be added
* @param request msf4j request object
* @return 201 Response if successful
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response applicationsPost(ApplicationDTO body, Request request) throws NotFoundException {
URI location = null;
ApplicationDTO createdApplicationDTO = null;
String username = RestApiUtil.getLoggedInUsername(request);
try {
APIStore apiConsumer = RestApiUtil.getConsumer(username);
Application application = ApplicationMappingUtil.fromDTOtoApplication(body, username);
ApplicationCreationResponse applicationResponse = apiConsumer.addApplication(application);
String applicationUUID = applicationResponse.getApplicationUUID();
Application createdApplication = apiConsumer.getApplication(applicationUUID, username);
createdApplicationDTO = ApplicationMappingUtil.fromApplicationToDTO(createdApplication);
location = new URI(RestApiConstants.RESOURCE_PATH_APPLICATIONS + "/" + createdApplicationDTO.getApplicationId());
// be in either pending or approved state) send back the workflow response
if (ApplicationStatus.APPLICATION_ONHOLD.equals(createdApplication.getStatus())) {
WorkflowResponseDTO workflowResponse = MiscMappingUtil.fromWorkflowResponseToDTO(applicationResponse.getWorkflowResponse());
return Response.status(Response.Status.ACCEPTED).header(RestApiConstants.LOCATION_HEADER, location).entity(workflowResponse).build();
}
} catch (APIManagementException e) {
String errorMessage = "Error while adding new application : " + body.getName();
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.APPLICATION_NAME, body.getName());
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
} catch (URISyntaxException e) {
String errorMessage = "Error while adding location header in response for application : " + body.getName();
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.APPLICATION_NAME, body.getName());
ErrorHandler errorHandler = ExceptionCodes.LOCATION_HEADER_INCORRECT;
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(errorHandler, paramList);
log.error(errorMessage, e);
return Response.status(errorHandler.getHttpStatusCode()).entity(errorDTO).build();
}
// .build()
return Response.status(Response.Status.CREATED).header(RestApiConstants.LOCATION_HEADER, location).entity(createdApplicationDTO).build();
}
use of org.wso2.carbon.messaging.Header in project carbon-apimgt by wso2.
the class ApplicationsApiServiceImpl method applicationsApplicationIdDelete.
/**
* Deletes an existing application
*
* @param applicationId ID of the application
* @param ifMatch If-Match header value
* @param ifUnmodifiedSince If-Unmodified-Since header value
* @param request msf4j request object
* @return 200 response if the deletion was successful
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response applicationsApplicationIdDelete(String applicationId, String ifMatch, String ifUnmodifiedSince, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
try {
APIStore apiConsumer = RestApiUtil.getConsumer(username);
String existingFingerprint = applicationsApplicationIdGetFingerprint(applicationId, null, null, request);
if (!StringUtils.isEmpty(ifMatch) && !StringUtils.isEmpty(existingFingerprint) && !ifMatch.contains(existingFingerprint)) {
return Response.status(Response.Status.PRECONDITION_FAILED).build();
}
apiConsumer.deleteApplication(applicationId);
} catch (APIManagementException e) {
String errorMessage = "Error while deleting application: " + applicationId;
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.APPLICATION_ID, applicationId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
return Response.ok().build();
}
use of org.wso2.carbon.messaging.Header in project carbon-apimgt by wso2.
the class ApplicationsApiServiceImpl method applicationsGet.
/**
* Retrieves all applications that qualifies for the search query
*
* @param query Search query
* @param limit Max number of applications to return
* @param offset Starting position of pagination
* @param ifNoneMatch If-None-Match header value
* @param request msf4j request object
* @return A list of qualifying application DTOs as the response
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response applicationsGet(String query, Integer limit, Integer offset, String ifNoneMatch, Request request) throws NotFoundException {
ApplicationListDTO applicationListDTO = null;
String username = RestApiUtil.getLoggedInUsername(request);
limit = limit != null ? limit : RestApiConstants.PAGINATION_LIMIT_DEFAULT;
offset = offset != null ? offset : RestApiConstants.PAGINATION_OFFSET_DEFAULT;
try {
APIStore apiConsumer = RestApiUtil.getConsumer(username);
List<Application> allMatchedApps = new ArrayList<>();
if (StringUtils.isBlank(query)) {
allMatchedApps = apiConsumer.getApplications(username);
} else {
Application application = apiConsumer.getApplicationByName(username, query);
if (application != null) {
allMatchedApps = new ArrayList<>();
allMatchedApps.add(application);
}
}
// allMatchedApps are already sorted to application name
applicationListDTO = ApplicationMappingUtil.fromApplicationsToDTO(allMatchedApps, limit, offset);
ApplicationMappingUtil.setPaginationParams(applicationListDTO, limit, offset, allMatchedApps.size());
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving applications";
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.APPLICATION_NAME, query);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
return Response.ok().entity(applicationListDTO).build();
}
Aggregations