use of org.wso2.carbon.apimgt.impl.dto.SoapToRestMediationDto in project carbon-apimgt by wso2.
the class TemplateBuilderUtil method retrieveGatewayAPIDto.
public static GatewayAPIDTO retrieveGatewayAPIDto(API api, Environment environment, String tenantDomain, APIDTO apidto, String extractedFolderPath) throws APIManagementException, XMLStreamException, APITemplateException {
List<ClientCertificateDTO> clientCertificatesDTOList = ImportUtils.retrieveClientCertificates(extractedFolderPath);
List<SoapToRestMediationDto> soapToRestInMediationDtoList = ImportUtils.retrieveSoapToRestFlowMediations(extractedFolderPath, ImportUtils.IN);
List<SoapToRestMediationDto> soapToRestOutMediationDtoList = ImportUtils.retrieveSoapToRestFlowMediations(extractedFolderPath, ImportUtils.OUT);
JSONObject originalProperties = api.getAdditionalProperties();
// add new property for entires that has a __display suffix
JSONObject modifiedProperties = getModifiedProperties(originalProperties);
api.setAdditionalProperties(modifiedProperties);
APITemplateBuilder apiTemplateBuilder = TemplateBuilderUtil.getAPITemplateBuilder(api, tenantDomain, clientCertificatesDTOList, soapToRestInMediationDtoList, soapToRestOutMediationDtoList);
GatewayAPIDTO gatewaAPIDto = createAPIGatewayDTOtoPublishAPI(environment, api, apiTemplateBuilder, tenantDomain, extractedFolderPath, apidto, clientCertificatesDTOList);
// Reset the additional properties to the original values
if (originalProperties != null) {
api.setAdditionalProperties(originalProperties);
}
return gatewaAPIDto;
}
use of org.wso2.carbon.apimgt.impl.dto.SoapToRestMediationDto in project carbon-apimgt by wso2.
the class ImportUtils method retrieveSoapToRestFlowMediations.
public static List<SoapToRestMediationDto> retrieveSoapToRestFlowMediations(String pathToArchive, String type) throws APIManagementException {
List<SoapToRestMediationDto> soapToRestMediationDtoList = new ArrayList<>();
String fileLocation = null;
if (IN.equals(type)) {
fileLocation = pathToArchive + File.separator + SOAPTOREST + File.separator + IN;
} else if (OUT.equals(type)) {
fileLocation = pathToArchive + File.separator + SOAPTOREST + File.separator + OUT;
}
if (CommonUtil.checkFileExistence(fileLocation)) {
Path flowDirectory = Paths.get(fileLocation);
try (DirectoryStream<Path> stream = Files.newDirectoryStream(flowDirectory)) {
for (Path file : stream) {
String fileName = file.getFileName().toString();
String method = "";
String resource = "";
if (fileName.split(".xml").length != 0) {
method = fileName.split(".xml")[0].substring(file.getFileName().toString().lastIndexOf("_") + 1);
resource = fileName.substring(0, fileName.indexOf("_"));
}
try (InputStream inputFlowStream = new FileInputStream(file.toFile())) {
String content = IOUtils.toString(inputFlowStream);
SoapToRestMediationDto soapToRestMediationDto = new SoapToRestMediationDto(resource, method, content);
soapToRestMediationDtoList.add(soapToRestMediationDto);
}
}
} catch (IOException e) {
throw new APIManagementException("Error while reading mediation content", e);
}
}
return soapToRestMediationDtoList;
}
use of org.wso2.carbon.apimgt.impl.dto.SoapToRestMediationDto in project carbon-apimgt by wso2.
the class ImportUtils method importMediationLogic.
/**
* Method created to add inflow and outflow mediation logic.
*
* @param sequenceData Inflow and outflow directory
* @param registry Registry
* @param soapToRestLocation Folder location
* @throws APIImportExportException If an error occurs while importing/storing SOAP to REST mediation logic
*/
private static void importMediationLogic(SoapToRestMediationDto sequenceData, Registry registry, String soapToRestLocation) throws APIManagementException {
String fileName = sequenceData.getResource().concat("_").concat(sequenceData.getMethod()).concat(".xml");
try {
byte[] inSeqData = sequenceData.getContent().getBytes();
Resource inSeqResource = registry.newResource();
inSeqResource.setContent(inSeqData);
inSeqResource.addProperty(SOAPToRESTConstants.METHOD, sequenceData.getMethod());
inSeqResource.setMediaType("text/xml");
registry.put(soapToRestLocation + RegistryConstants.PATH_SEPARATOR + fileName, inSeqResource);
} catch (DirectoryIteratorException e) {
throw new APIManagementException("Error in importing SOAP to REST mediation logic", e);
} catch (RegistryException e) {
throw new APIManagementException("Error in storing imported SOAP to REST mediation logic", e);
}
}
use of org.wso2.carbon.apimgt.impl.dto.SoapToRestMediationDto in project carbon-apimgt by wso2.
the class TemplateBuilderUtil method getAPITemplateBuilder.
public static APITemplateBuilderImpl getAPITemplateBuilder(API api, String tenantDomain, List<ClientCertificateDTO> clientCertificateDTOS, List<SoapToRestMediationDto> soapToRestInMediationDtos, List<SoapToRestMediationDto> soapToRestMediationDtos) throws APIManagementException {
int tenantId = APIUtil.getTenantIdFromTenantDomain(tenantDomain);
APITemplateBuilderImpl vtb = new APITemplateBuilderImpl(api, soapToRestInMediationDtos, soapToRestMediationDtos);
Map<String, String> latencyStatsProperties = new HashMap<String, String>();
latencyStatsProperties.put(APIConstants.API_UUID, api.getUUID());
if (!APIUtil.isStreamingApi(api)) {
vtb.addHandler("org.wso2.carbon.apimgt.gateway.handlers.common.APIMgtLatencyStatsHandler", latencyStatsProperties);
}
Map<String, String> corsProperties = new HashMap<String, String>();
corsProperties.put(APIConstants.CORSHeaders.IMPLEMENTATION_TYPE_HANDLER_VALUE, api.getImplementation());
// Get authorization header from the API object or from the tenant registry
String authorizationHeader;
if (!StringUtils.isBlank(api.getAuthorizationHeader())) {
authorizationHeader = api.getAuthorizationHeader();
} else {
// Retrieves the auth configuration from tenant registry or api-manager.xml if not available
// in tenant registry
authorizationHeader = APIUtil.getOAuthConfiguration(tenantDomain, APIConstants.AUTHORIZATION_HEADER);
}
if (!StringUtils.isBlank(authorizationHeader)) {
corsProperties.put(APIConstants.AUTHORIZATION_HEADER, authorizationHeader);
}
if (!(APIConstants.APITransportType.WS.toString().equals(api.getType()))) {
if (api.getCorsConfiguration() != null && api.getCorsConfiguration().isCorsConfigurationEnabled()) {
CORSConfiguration corsConfiguration = api.getCorsConfiguration();
if (corsConfiguration.getAccessControlAllowHeaders() != null) {
StringBuilder allowHeaders = new StringBuilder();
for (String header : corsConfiguration.getAccessControlAllowHeaders()) {
allowHeaders.append(header).append(',');
}
if (allowHeaders.length() != 0) {
allowHeaders.deleteCharAt(allowHeaders.length() - 1);
corsProperties.put(APIConstants.CORSHeaders.ALLOW_HEADERS_HANDLER_VALUE, allowHeaders.toString());
}
}
if (corsConfiguration.getAccessControlAllowOrigins() != null) {
StringBuilder allowOrigins = new StringBuilder();
for (String origin : corsConfiguration.getAccessControlAllowOrigins()) {
allowOrigins.append(origin).append(',');
}
if (allowOrigins.length() != 0) {
allowOrigins.deleteCharAt(allowOrigins.length() - 1);
corsProperties.put(APIConstants.CORSHeaders.ALLOW_ORIGIN_HANDLER_VALUE, allowOrigins.toString());
}
}
if (corsConfiguration.getAccessControlAllowMethods() != null) {
StringBuilder allowedMethods = new StringBuilder();
for (String methods : corsConfiguration.getAccessControlAllowMethods()) {
allowedMethods.append(methods).append(',');
}
if (allowedMethods.length() != 0) {
allowedMethods.deleteCharAt(allowedMethods.length() - 1);
corsProperties.put(APIConstants.CORSHeaders.ALLOW_METHODS_HANDLER_VALUE, allowedMethods.toString());
}
}
if (corsConfiguration.isAccessControlAllowCredentials()) {
corsProperties.put(APIConstants.CORSHeaders.ALLOW_CREDENTIALS_HANDLER_VALUE, String.valueOf(corsConfiguration.isAccessControlAllowCredentials()));
}
vtb.addHandler("org.wso2.carbon.apimgt.gateway.handlers.security.CORSRequestHandler", corsProperties);
} else if (APIUtil.isCORSEnabled()) {
vtb.addHandler("org.wso2.carbon.apimgt.gateway.handlers.security.CORSRequestHandler", corsProperties);
}
vtb.addHandler("org.wso2.carbon.apimgt.gateway.handlers.common.APIStatusHandler", Collections.emptyMap());
}
Map<String, String> clientCertificateObject = null;
CertificateMgtUtils certificateMgtUtils = CertificateMgtUtils.getInstance();
if (clientCertificateDTOS != null) {
clientCertificateObject = new HashMap<>();
for (ClientCertificateDTO clientCertificateDTO : clientCertificateDTOS) {
clientCertificateObject.put(certificateMgtUtils.getUniqueIdentifierOfCertificate(clientCertificateDTO.getCertificate()), clientCertificateDTO.getTierName());
}
}
Map<String, String> authProperties = new HashMap<>();
if (!StringUtils.isBlank(authorizationHeader)) {
authProperties.put(APIConstants.AUTHORIZATION_HEADER, authorizationHeader);
}
String apiSecurity = api.getApiSecurity();
String apiLevelPolicy = api.getApiLevelPolicy();
authProperties.put(APIConstants.API_SECURITY, apiSecurity);
authProperties.put(APIConstants.API_LEVEL_POLICY, apiLevelPolicy);
if (clientCertificateObject != null) {
authProperties.put(APIConstants.CERTIFICATE_INFORMATION, clientCertificateObject.toString());
}
// Get RemoveHeaderFromOutMessage from tenant registry or api-manager.xml
String removeHeaderFromOutMessage = APIUtil.getOAuthConfiguration(tenantDomain, APIConstants.REMOVE_OAUTH_HEADER_FROM_OUT_MESSAGE);
if (!StringUtils.isBlank(removeHeaderFromOutMessage)) {
authProperties.put(APIConstants.REMOVE_OAUTH_HEADER_FROM_OUT_MESSAGE, removeHeaderFromOutMessage);
} else {
authProperties.put(APIConstants.REMOVE_OAUTH_HEADER_FROM_OUT_MESSAGE, APIConstants.REMOVE_OAUTH_HEADER_FROM_OUT_MESSAGE_DEFAULT);
}
authProperties.put(APIConstants.API_UUID, api.getUUID());
authProperties.put("keyManagers", String.join(",", api.getKeyManagers()));
if (APIConstants.GRAPHQL_API.equals(api.getType())) {
Map<String, String> apiUUIDProperty = new HashMap<String, String>();
apiUUIDProperty.put(APIConstants.API_UUID, api.getUUID());
vtb.addHandler("org.wso2.carbon.apimgt.gateway.handlers.graphQL.GraphQLAPIHandler", apiUUIDProperty);
}
if (APIConstants.APITransportType.WEBSUB.toString().equals(api.getType())) {
authProperties.put(APIConstants.WebHookProperties.EVENT_RECEIVING_RESOURCE_PATH, APIConstants.WebHookProperties.DEFAULT_SUBSCRIPTION_RESOURCE_PATH);
authProperties.put(APIConstants.WebHookProperties.TOPIC_QUERY_PARAM_NAME, APIConstants.WebHookProperties.DEFAULT_TOPIC_QUERY_PARAM_NAME);
vtb.addHandler("org.wso2.carbon.apimgt.gateway.handlers.streaming.webhook.WebhookApiHandler", authProperties);
vtb.addHandler("org.wso2.carbon.apimgt.gateway.handlers.streaming.webhook." + "WebhooksExtensionHandler", Collections.emptyMap());
} else if (APIConstants.APITransportType.SSE.toString().equals(api.getType())) {
vtb.addHandler("org.wso2.carbon.apimgt.gateway.handlers.streaming.sse.SseApiHandler", authProperties);
} else if (!(APIConstants.APITransportType.WS.toString().equals(api.getType()))) {
vtb.addHandler("org.wso2.carbon.apimgt.gateway.handlers.security.APIAuthenticationHandler", authProperties);
}
if (APIConstants.GRAPHQL_API.equals(api.getType())) {
vtb.addHandler("org.wso2.carbon.apimgt.gateway.handlers.graphQL.GraphQLQueryAnalysisHandler", Collections.emptyMap());
}
if (!APIUtil.isStreamingApi(api)) {
Map<String, String> properties = new HashMap<String, String>();
if (api.getProductionMaxTps() != null) {
properties.put("productionMaxCount", api.getProductionMaxTps());
}
if (api.getSandboxMaxTps() != null) {
properties.put("sandboxMaxCount", api.getSandboxMaxTps());
}
vtb.addHandler("org.wso2.carbon.apimgt.gateway.handlers.throttling.ThrottleHandler", properties);
properties = new HashMap<String, String>();
properties.put("configKey", APIConstants.GA_CONF_KEY);
vtb.addHandler("org.wso2.carbon.apimgt.gateway.handlers.analytics.APIMgtGoogleAnalyticsTrackingHandler", properties);
String extensionHandlerPosition = getExtensionHandlerPosition(tenantDomain);
if ("top".equalsIgnoreCase(extensionHandlerPosition)) {
vtb.addHandlerPriority("org.wso2.carbon.apimgt.gateway.handlers.ext.APIManagerExtensionHandler", Collections.emptyMap(), 2);
} else {
vtb.addHandler("org.wso2.carbon.apimgt.gateway.handlers.ext.APIManagerExtensionHandler", Collections.emptyMap());
}
}
return vtb;
}
use of org.wso2.carbon.apimgt.impl.dto.SoapToRestMediationDto in project carbon-apimgt by wso2.
the class SequenceUtils method getSequenceTemplateConfigContext.
/**
* Gets the velocity template config context with sequence data populated
*
* @param soapToRestMediationDtoList registry resource path
* @param seqType sequence type whether in or out sequence
* @param configContext velocity template config context
* @return {@link ConfigContext} sequences populated velocity template config context
*/
public static ConfigContext getSequenceTemplateConfigContext(List<SoapToRestMediationDto> soapToRestMediationDtoList, String seqType, ConfigContext configContext) {
if (soapToRestMediationDtoList.size() > 0) {
JSONObject pathObj = new JSONObject();
for (SoapToRestMediationDto soapToRestMediationDto : soapToRestMediationDtoList) {
String method = soapToRestMediationDto.getMethod();
String resourceName = soapToRestMediationDto.getResource();
JSONObject contentObj = new JSONObject();
contentObj.put(method, soapToRestMediationDto.getContent());
pathObj.put(SOAPToRESTConstants.SequenceGen.PATH_SEPARATOR.concat(resourceName), contentObj);
}
configContext = new SOAPToRESTAPIConfigContext(configContext, pathObj, seqType);
}
return configContext;
}
Aggregations