use of org.wso2.carbon.humantask.client.api.types in project carbon-apimgt by wso2.
the class ServiceDiscoveryInPublisherTestCase method testDiscoverServiceEndpoints.
@Test
public void testDiscoverServiceEndpoints() throws Exception {
/* Create a impl config without any namespace or criteria */
ServiceDiscoveryImplConfig sdImplConfig = new ServiceDiscoveryImplConfig();
sdImplConfig.setImplClass("org.wso2.carbon.apimgt.core.impl.ServiceDiscovererTestClass");
sdImplConfig.setImplParameters(new HashMap<>());
/* Create a impl config with a namespace set */
Map<String, String> implParamWithNamespace = new HashMap<>();
implParamWithNamespace.put(APIMgtConstants.ServiceDiscoveryConstants.NAMESPACE, "dev");
ServiceDiscoveryImplConfig sdImplConfigWithNamespace = new ServiceDiscoveryImplConfig();
sdImplConfigWithNamespace.setImplClass("org.wso2.carbon.apimgt.core.impl.ServiceDiscovererTestClass");
sdImplConfigWithNamespace.setImplParameters(implParamWithNamespace);
/* Create a impl config with a criteria set */
Map<String, String> implParamWithCriteria = new HashMap<>();
implParamWithCriteria.put(APIMgtConstants.ServiceDiscoveryConstants.CRITERIA, "app=web");
ServiceDiscoveryImplConfig sdImplConfigWitCriteria = new ServiceDiscoveryImplConfig();
sdImplConfigWitCriteria.setImplClass("org.wso2.carbon.apimgt.core.impl.ServiceDiscovererTestClass");
sdImplConfigWitCriteria.setImplParameters(implParamWithCriteria);
/* Create a impl config with both a namespace and a criteria is set */
Map<String, String> implParamWithNamespaceAndCriteria = new HashMap<>();
implParamWithNamespaceAndCriteria.put(APIMgtConstants.ServiceDiscoveryConstants.NAMESPACE, "dev");
implParamWithNamespaceAndCriteria.put(APIMgtConstants.ServiceDiscoveryConstants.CRITERIA, "app=web");
ServiceDiscoveryImplConfig sdImplConfigWithNamespaceNCriteria = new ServiceDiscoveryImplConfig();
sdImplConfigWithNamespaceNCriteria.setImplClass("org.wso2.carbon.apimgt.core.impl.ServiceDiscovererTestClass");
sdImplConfigWithNamespaceNCriteria.setImplParameters(implParamWithNamespaceAndCriteria);
/* Create the implementationsList adding all four impl configs */
List<ServiceDiscoveryImplConfig> implementationsList = new ArrayList<>();
implementationsList.add(sdImplConfig);
implementationsList.add(sdImplConfigWithNamespace);
implementationsList.add(sdImplConfigWitCriteria);
implementationsList.add(sdImplConfigWithNamespaceNCriteria);
/* Create the final configuration */
ServiceDiscoveryConfigurations sdConfig = new ServiceDiscoveryConfigurations();
sdConfig.setEnabled(true);
sdConfig.setImplementationsList(implementationsList);
PowerMockito.mockStatic(ServiceDiscoveryConfigBuilder.class);
PowerMockito.when(ServiceDiscoveryConfigBuilder.getServiceDiscoveryConfiguration()).thenReturn(sdConfig);
/* Check whether all four types of #listServices methods have been called */
APIPublisherImpl apiPublisher = getApiPublisherImpl();
List<Endpoint> endpoints = apiPublisher.discoverServiceEndpoints();
Assert.assertEquals(endpoints.size(), 4);
}
use of org.wso2.carbon.humantask.client.api.types 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.humantask.client.api.types 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.humantask.client.api.types in project carbon-apimgt by wso2.
the class ResourcesApiServiceImpl method resourcesGet.
@Override
public Response resourcesGet(String apiContext, String apiVersion, String accept, Request request) throws NotFoundException {
try {
APIMgtAdminService apiMgtAdminService = APIManagerFactory.getInstance().getAPIMgtAdminService();
List<UriTemplate> resourcesOfApi = new ArrayList<>();
if (!StringUtils.isEmpty(apiContext) && !StringUtils.isEmpty(apiVersion)) {
resourcesOfApi = apiMgtAdminService.getAllResourcesForApi(apiContext, apiVersion);
}
ResourcesListDTO resourcesListDTO = new ResourcesListDTO();
resourcesListDTO.setList(MappingUtil.convertToResourceListDto(resourcesOfApi));
return Response.ok(resourcesListDTO).build();
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving resources.";
Map<String, String> paramList = new HashMap<String, String>();
if (!StringUtils.isEmpty(apiContext)) {
paramList.put(APIMgtConstants.ExceptionsConstants.API_CONTEXT, apiContext);
}
if (!StringUtils.isEmpty(apiVersion)) {
paramList.put(APIMgtConstants.ExceptionsConstants.API_VERSION, apiVersion);
}
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.humantask.client.api.types in project carbon-apimgt by wso2.
the class ServiceReferenceHolder method getApimUIConfigurations.
public APIMUIConfigurations getApimUIConfigurations() {
try {
if (configProvider != null) {
apimUIConfigurations = configProvider.getConfigurationObject(APIMUIConfigurations.class);
} else {
log.error("Configuration provider is null");
}
} catch (ConfigurationException e) {
log.error("Error getting config : org.wso2.carbon.apimgt.rest.api.configurations.models." + "EnvironmentConfigurations", e);
}
if (apimUIConfigurations == null) {
apimUIConfigurations = new APIMUIConfigurations();
log.info("Setting default configurations...");
}
return apimUIConfigurations;
}
Aggregations