use of org.wso2.carbon.apimgt.common.analytics.publishers.dto.Target in project carbon-apimgt by wso2.
the class ExtendedHTTPEventAdaptorTestCase method testHttpPublisherFactory.
@Test
public void testHttpPublisherFactory() {
logger.info("Test case for factory properties of Extended HTTP output adaptor.");
ExtendedHTTPEventAdapterFactory adapterFactory = new ExtendedHTTPEventAdapterFactory();
List<Property> dyPropertyList = adapterFactory.getDynamicPropertyList();
List<Property> propertyList = new ArrayList<>();
Property property = new Property("http.url");
property.setRequired(true);
property.setSecured(false);
property.setEncrypted(false);
property.setDisplayName("URL");
property.setDefaultValue(null);
property.setOptions(null);
property.setHint("The target HTTP/HTTPS URL, e.g. \"http://yourhost:8080/service\"");
propertyList.add(property);
property = new Property("http.username");
property.setRequired(false);
property.setSecured(false);
property.setEncrypted(false);
property.setDisplayName("Username");
property.setDefaultValue(null);
property.setOptions(null);
property.setHint("HTTP BasicAuth username");
propertyList.add(property);
property = new Property("http.password");
property.setRequired(false);
property.setSecured(true);
property.setEncrypted(true);
property.setDisplayName("Password");
property.setDefaultValue(null);
property.setOptions(null);
property.setHint("HTTP BasicAuth password");
propertyList.add(property);
property = new Property("http.headers");
property.setRequired(false);
property.setSecured(false);
property.setEncrypted(false);
property.setDisplayName("Headers");
property.setDefaultValue(null);
property.setOptions(null);
property.setHint("Custom HTTP headers, e.g. \"header1: value1, header2: value2\"");
propertyList.add(property);
Assert.assertEquals(4, dyPropertyList.size());
int i = 0;
for (Property prop : propertyList) {
Assert.assertEquals(prop.getPropertyName(), dyPropertyList.get(i).getPropertyName());
Assert.assertEquals(prop.getDefaultValue(), dyPropertyList.get(i).getDefaultValue());
Assert.assertEquals(prop.getDisplayName(), dyPropertyList.get(i).getDisplayName());
Assert.assertEquals(prop.getHint(), dyPropertyList.get(i).getHint());
i++;
}
List<String> types = new ArrayList<>();
types.add("text");
types.add("xml");
types.add("json");
List<String> supportedTypes = adapterFactory.getSupportedMessageFormats();
Assert.assertEquals(supportedTypes.toString(), types.toString());
Assert.assertEquals("http-extended", adapterFactory.getType());
setupCarbonConfig();
PrivilegedCarbonContext privilegedCarbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
privilegedCarbonContext.setTenantId(-1234);
OutputEventAdapterConfiguration eventAdapterConfiguration = new OutputEventAdapterConfiguration();
eventAdapterConfiguration.setName("TestHttpAdaptor");
eventAdapterConfiguration.setType("http-extended");
eventAdapterConfiguration.setMessageFormat("text");
Map<String, String> staticPropertes = new HashMap<>();
staticPropertes.put("http.client.method", "HttpPost");
staticPropertes.put("http.proxy.port", "9090");
staticPropertes.put("http.proxy.host", "localhost");
staticPropertes.put("oauth.url", "localhost:9090/token");
staticPropertes.put("oauth.consumer.key", "key");
staticPropertes.put("oauth.consumer.secret", "secret");
eventAdapterConfiguration.setStaticProperties(staticPropertes);
Map<String, String> globalProperties = new HashMap<>();
globalProperties.put("jobQueueSize", "10000");
globalProperties.put("keepAliveTimeInMillis", "20000");
globalProperties.put("maxThread", "100");
globalProperties.put("minThread", "8");
globalProperties.put("defaultMaxConnectionsPerHost", "50");
globalProperties.put("maxTotalConnections", "1000");
adapterFactory.createEventAdapter(eventAdapterConfiguration, globalProperties);
}
use of org.wso2.carbon.apimgt.common.analytics.publishers.dto.Target in project carbon-apimgt by wso2.
the class RestApiAdminUtils method importTenantTheme.
/**
* Import the content of the provided tenant theme archive to the file system and the database
*
* @param themeContentInputStream content relevant to the tenant theme
* @param tenantDomain tenant to which the theme is imported
* @throws APIManagementException if an error occurs while importing the tenant theme
* @throws IOException if an error occurs while performing file or directory related operations
*/
public static void importTenantTheme(InputStream themeContentInputStream, String tenantDomain) throws APIManagementException, IOException {
ZipInputStream zipInputStream = null;
byte[] buffer = new byte[1024];
InputStream existingTenantTheme = null;
InputStream themeContent = null;
File tenantThemeDirectory;
File backupDirectory = null;
int tenantId = APIUtil.getTenantIdFromTenantDomain(tenantDomain);
try {
APIAdmin apiAdmin = new APIAdminImpl();
// add or update the tenant theme in the database
if (apiAdmin.isTenantThemeExist(tenantId)) {
existingTenantTheme = apiAdmin.getTenantTheme(tenantId);
apiAdmin.updateTenantTheme(tenantId, themeContentInputStream);
} else {
apiAdmin.addTenantTheme(tenantId, themeContentInputStream);
}
// retrieve the tenant theme from the database to import it to the file system
themeContent = apiAdmin.getTenantTheme(tenantId);
// import the tenant theme to the file system
String outputFolder = getTenantThemeDirectoryPath(tenantDomain);
tenantThemeDirectory = new File(outputFolder);
if (!tenantThemeDirectory.exists()) {
if (!tenantThemeDirectory.mkdirs()) {
APIUtil.handleException("Unable to create tenant theme directory at " + outputFolder);
}
} else {
// copy the existing tenant theme as a backup in case a restoration is needed to take place
String tempPath = getTenantThemeBackupDirectoryPath(tenantDomain);
backupDirectory = new File(tempPath);
FileUtils.copyDirectory(tenantThemeDirectory, backupDirectory);
// remove existing files inside the directory
FileUtils.cleanDirectory(tenantThemeDirectory);
}
// get the zip file content
zipInputStream = new ZipInputStream(themeContent);
// get the zipped file list entry
ZipEntry zipEntry = zipInputStream.getNextEntry();
while (zipEntry != null) {
String fileName = zipEntry.getName();
APIUtil.validateFileName(fileName);
File newFile = new File(outputFolder + File.separator + fileName);
String canonicalizedNewFilePath = newFile.getCanonicalPath();
String canonicalizedDestinationPath = new File(outputFolder).getCanonicalPath();
if (!canonicalizedNewFilePath.startsWith(canonicalizedDestinationPath)) {
APIUtil.handleException("Attempt to upload invalid zip archive with file at " + fileName + ". File path is " + "outside target directory");
}
if (zipEntry.isDirectory()) {
if (!newFile.exists()) {
boolean status = newFile.mkdir();
if (!status) {
APIUtil.handleException("Error while creating " + newFile.getName() + " directory");
}
}
} else {
String ext = FilenameUtils.getExtension(zipEntry.getName());
if (EXTENSION_WHITELIST.contains(ext)) {
// create all non exists folders
// else you will hit FileNotFoundException for compressed folder
new File(newFile.getParent()).mkdirs();
FileOutputStream fileOutputStream = new FileOutputStream(newFile);
int len;
while ((len = zipInputStream.read(buffer)) > 0) {
fileOutputStream.write(buffer, 0, len);
}
fileOutputStream.close();
} else {
APIUtil.handleException("Unsupported file is uploaded with tenant theme by " + tenantDomain + " : file name : " + zipEntry.getName());
}
}
zipEntry = zipInputStream.getNextEntry();
}
zipInputStream.closeEntry();
zipInputStream.close();
if (backupDirectory != null) {
FileUtils.deleteDirectory(backupDirectory);
}
} catch (APIManagementException | IOException e) {
// if an error occurs, revert the changes that were done when importing a tenant theme
revertTenantThemeImportChanges(tenantDomain, existingTenantTheme);
throw new APIManagementException(e.getMessage(), e, ExceptionCodes.from(ExceptionCodes.TENANT_THEME_IMPORT_FAILED, tenantDomain, e.getMessage()));
} finally {
IOUtils.closeQuietly(zipInputStream);
IOUtils.closeQuietly(themeContent);
IOUtils.closeQuietly(themeContentInputStream);
}
}
use of org.wso2.carbon.apimgt.common.analytics.publishers.dto.Target in project carbon-apimgt by wso2.
the class WebhooksAnalyticsDataProvider method getTarget.
@Override
public Target getTarget() {
Target target = new Target();
boolean isCacheHit = messageContext.getPropertyKeySet().contains(Constants.CACHED_RESPONSE_KEY);
String endpointAddress = (String) messageContext.getProperty(APIConstants.Webhooks.SUBSCRIBER_CALLBACK_PROPERTY);
int targetResponseCode = getTargetResponseCode();
target.setResponseCacheHit(isCacheHit);
target.setDestination(endpointAddress);
target.setTargetResponseCode(targetResponseCode);
return target;
}
use of org.wso2.carbon.apimgt.common.analytics.publishers.dto.Target in project carbon-apimgt by wso2.
the class ImportUtils method isTierAvailable.
/**
* Check whether a target Tier is available to subscribe
*
* @param targetTierName Target Tier Name
* @param apiTypeWrapper - {@link ApiTypeWrapper}
* @return true, if the target tier is available
*/
private static boolean isTierAvailable(String targetTierName, ApiTypeWrapper apiTypeWrapper) {
Set<Tier> availableTiers;
API api = null;
APIProduct apiProduct = null;
if (!apiTypeWrapper.isAPIProduct()) {
api = apiTypeWrapper.getApi();
availableTiers = api.getAvailableTiers();
} else {
apiProduct = apiTypeWrapper.getApiProduct();
availableTiers = apiProduct.getAvailableTiers();
}
for (Tier tier : availableTiers) {
if (StringUtils.equals(tier.getName(), targetTierName)) {
return true;
}
}
if (!apiTypeWrapper.isAPIProduct()) {
log.error("Tier:" + targetTierName + " is not available for API " + api.getId().getApiName() + "-" + api.getId().getVersion());
} else {
log.error("Tier:" + targetTierName + " is not available for API Product " + apiProduct.getId().getName() + "-" + apiProduct.getId().getVersion());
}
return false;
}
use of org.wso2.carbon.apimgt.common.analytics.publishers.dto.Target in project ballerina by ballerina-lang.
the class TypeChecker method checkNamedTransformerInvocation.
private List<BType> checkNamedTransformerInvocation(BLangTypeConversionExpr conversionExpr, BType sourceType, BType targetType) {
List<BType> actualTypes = getListWithErrorTypes(expTypes.size());
BLangInvocation transformerInvocation = conversionExpr.transformerInvocation;
BSymbol transformerSymbol = symResolver.lookupSymbolInPackage(transformerInvocation.pos, env, names.fromIdNode(transformerInvocation.pkgAlias), names.fromIdNode(transformerInvocation.name), SymTag.TRANSFORMER);
if (transformerSymbol == symTable.notFoundSymbol) {
dlog.error(conversionExpr.pos, DiagnosticCode.UNDEFINED_TRANSFORMER, transformerInvocation.name);
} else {
conversionExpr.conversionSymbol = (BConversionOperatorSymbol) (transformerInvocation.symbol = transformerSymbol);
// Check the transformer invocation. Expected type for the transformer is the target type
// of the cast conversion operator, but not the lhs type.
List<BType> prevExpType = expTypes;
expTypes = Lists.of(targetType);
checkInvocationParamAndReturnType(transformerInvocation);
expTypes = prevExpType;
if (transformerInvocation.type != symTable.errType) {
BInvokableType transformerSymType = (BInvokableType) transformerSymbol.type;
transformerInvocation.types = transformerSymType.retTypes;
actualTypes = getActualTypesOfConversionExpr(conversionExpr, targetType, sourceType, conversionExpr.conversionSymbol);
}
}
return actualTypes;
}
Aggregations