use of org.wso2.carbon.apimgt.api.gateway.GatewayContentDTO in project carbon-apimgt by wso2.
the class InMemoryAPIDeployer method addDeployedCertificatesToAPIAssociation.
private void addDeployedCertificatesToAPIAssociation(GatewayAPIDTO gatewayAPIDTO) {
if (gatewayAPIDTO != null) {
String apiId = gatewayAPIDTO.getApiId();
List<String> aliasList = new ArrayList<>();
if (gatewayAPIDTO.getClientCertificatesToBeAdd() != null) {
for (GatewayContentDTO gatewayContentDTO : gatewayAPIDTO.getClientCertificatesToBeAdd()) {
aliasList.add(gatewayContentDTO.getName());
}
}
DataHolder.getInstance().addApiToAliasList(apiId, aliasList);
}
}
use of org.wso2.carbon.apimgt.api.gateway.GatewayContentDTO in project carbon-apimgt by wso2.
the class TemplateBuilderUtil method createAPIGatewayDTOtoPublishAPI.
private static GatewayAPIDTO createAPIGatewayDTOtoPublishAPI(Environment environment, API api, APITemplateBuilder builder, String tenantDomain, String extractedPath, APIDTO apidto, List<ClientCertificateDTO> clientCertificatesDTOList) throws APIManagementException, APITemplateException, XMLStreamException {
GatewayAPIDTO gatewayAPIDTO = new GatewayAPIDTO();
gatewayAPIDTO.setName(api.getId().getName());
gatewayAPIDTO.setVersion(api.getId().getVersion());
gatewayAPIDTO.setProvider(api.getId().getProviderName());
gatewayAPIDTO.setApiId(api.getUUID());
gatewayAPIDTO.setTenantDomain(tenantDomain);
gatewayAPIDTO.setKeyManagers(api.getKeyManagers());
String definition;
boolean isGraphQLSubscriptionAPI = false;
if (api.getType() != null && APIConstants.APITransportType.GRAPHQL.toString().equals(api.getType())) {
// Build schema with additional info
gatewayAPIDTO.setLocalEntriesToBeRemove(GatewayUtils.addStringToList(api.getUUID() + "_graphQL", gatewayAPIDTO.getLocalEntriesToBeRemove()));
GatewayContentDTO graphqlLocalEntry = new GatewayContentDTO();
graphqlLocalEntry.setName(api.getUUID() + "_graphQL");
graphqlLocalEntry.setContent("<localEntry key=\"" + api.getUUID() + "_graphQL" + "\">" + "<![CDATA[" + api.getGraphQLSchema() + "]]>" + "</localEntry>");
gatewayAPIDTO.setLocalEntriesToBeAdd(addGatewayContentToList(graphqlLocalEntry, gatewayAPIDTO.getLocalEntriesToBeAdd()));
gatewayAPIDTO.setGraphQLSchema(api.getGraphQLSchema());
Set<URITemplate> uriTemplates = new HashSet<>();
URITemplate template = new URITemplate();
template.setAuthType("Any");
template.setHTTPVerb("POST");
template.setHttpVerbs("POST");
template.setUriTemplate("/*");
uriTemplates.add(template);
api.setUriTemplates(uriTemplates);
GraphQLSchemaDefinition graphql = new GraphQLSchemaDefinition();
if (graphql.isSubscriptionAvailable(api.getGraphQLSchema())) {
isGraphQLSubscriptionAPI = true;
// if subscriptions are available add new URI template with wild card resource without http verb.
template = new URITemplate();
template.setUriTemplate("/*");
uriTemplates.add(template);
api.setUriTemplates(uriTemplates);
api.setEndpointConfig(populateSubscriptionEndpointConfig(api.getEndpointConfig()));
addGqlWebSocketTopicMappings(api);
}
} else if (api.getType() != null && (APIConstants.APITransportType.HTTP.toString().equals(api.getType()) || APIConstants.API_TYPE_SOAP.equals(api.getType()) || APIConstants.API_TYPE_SOAPTOREST.equals(api.getType()))) {
definition = api.getSwaggerDefinition();
gatewayAPIDTO.setLocalEntriesToBeRemove(GatewayUtils.addStringToList(api.getUUID(), gatewayAPIDTO.getLocalEntriesToBeRemove()));
GatewayContentDTO apiLocalEntry = new GatewayContentDTO();
apiLocalEntry.setName(api.getUUID());
apiLocalEntry.setContent("<localEntry key=\"" + api.getUUID() + "\">" + definition.replaceAll("&(?!amp;)", "&").replaceAll("<", "<").replaceAll(">", ">") + "</localEntry>");
gatewayAPIDTO.setLocalEntriesToBeAdd(addGatewayContentToList(apiLocalEntry, gatewayAPIDTO.getLocalEntriesToBeAdd()));
} else if (api.getType() != null && (APIConstants.APITransportType.WS.toString().equals(api.getType()) || APIConstants.APITransportType.SSE.toString().equals(api.getType()) || APIConstants.APITransportType.WEBSUB.toString().equals(api.getType()))) {
gatewayAPIDTO.setLocalEntriesToBeRemove(GatewayUtils.addStringToList(api.getUUID(), gatewayAPIDTO.getLocalEntriesToBeRemove()));
definition = api.getAsyncApiDefinition();
GatewayContentDTO apiLocalEntry = new GatewayContentDTO();
apiLocalEntry.setName(api.getUUID());
apiLocalEntry.setContent("<localEntry key=\"" + api.getUUID() + "\">" + definition.replaceAll("&(?!amp;)", "&").replaceAll("<", "<").replaceAll(">", ">") + "</localEntry>");
gatewayAPIDTO.setLocalEntriesToBeAdd(addGatewayContentToList(apiLocalEntry, gatewayAPIDTO.getLocalEntriesToBeAdd()));
}
if ((APIConstants.GATEWAY_ENV_TYPE_PRODUCTION.equals(environment.getType()) && !APIUtil.isProductionEndpointsExists(api.getEndpointConfig())) || (APIConstants.GATEWAY_ENV_TYPE_SANDBOX.equals(environment.getType()) && !APIUtil.isSandboxEndpointsExists(api.getEndpointConfig()))) {
if (log.isDebugEnabled()) {
log.debug("Not adding API to environment " + environment.getName() + " since its endpoint URL " + "cannot be found");
}
return null;
}
GatewayUtils.setCustomSequencesToBeRemoved(api, gatewayAPIDTO);
setAPIFaultSequencesToBeAdded(api, gatewayAPIDTO, extractedPath, apidto);
setCustomSequencesToBeAdded(api, gatewayAPIDTO, extractedPath, apidto);
setClientCertificatesToBeAdded(tenantDomain, gatewayAPIDTO, clientCertificatesDTOList);
boolean isWsApi = APIConstants.APITransportType.WS.toString().equals(api.getType());
if (isWsApi) {
addWebsocketTopicMappings(api, apidto);
}
// Add the API
if (APIConstants.IMPLEMENTATION_TYPE_INLINE.equalsIgnoreCase(api.getImplementation())) {
String prototypeScriptAPI = builder.getConfigStringForPrototypeScriptAPI(environment);
gatewayAPIDTO.setApiDefinition(prototypeScriptAPI);
} else if (APIConstants.IMPLEMENTATION_TYPE_ENDPOINT.equalsIgnoreCase(api.getImplementation())) {
String apiConfig = builder.getConfigStringForTemplate(environment);
gatewayAPIDTO.setApiDefinition(apiConfig);
org.json.JSONObject endpointConfig = new org.json.JSONObject(api.getEndpointConfig());
if (!endpointConfig.get(APIConstants.API_ENDPOINT_CONFIG_PROTOCOL_TYPE).equals(APIConstants.ENDPOINT_TYPE_AWSLAMBDA)) {
if (!isWsApi) {
addEndpoints(api, builder, gatewayAPIDTO);
}
if (isWsApi || isGraphQLSubscriptionAPI) {
addWebSocketResourceEndpoints(api, builder, gatewayAPIDTO);
}
}
}
setSecureVaultPropertyToBeAdded(null, api, gatewayAPIDTO);
return gatewayAPIDTO;
}
use of org.wso2.carbon.apimgt.api.gateway.GatewayContentDTO in project carbon-apimgt by wso2.
the class TemplateBuilderUtil method setCustomSequencesToBeAdded.
private static void setCustomSequencesToBeAdded(API api, GatewayAPIDTO gatewayAPIDTO, String extractedPath, APIDTO apidto) throws APIManagementException {
if (APIConstants.APITransportType.HTTP.toString().equals(api.getType())) {
GatewayContentDTO gatewayInContentDTO = retrieveOperationPolicySequence(extractedPath, api, APIConstants.OPERATION_SEQUENCE_TYPE_REQUEST);
if (gatewayInContentDTO != null) {
gatewayAPIDTO.setSequenceToBeAdd(addGatewayContentToList(gatewayInContentDTO, gatewayAPIDTO.getSequenceToBeAdd()));
}
GatewayContentDTO gatewayOutContentDTO = retrieveOperationPolicySequence(extractedPath, api, APIConstants.OPERATION_SEQUENCE_TYPE_RESPONSE);
if (gatewayOutContentDTO != null) {
gatewayAPIDTO.setSequenceToBeAdd(addGatewayContentToList(gatewayOutContentDTO, gatewayAPIDTO.getSequenceToBeAdd()));
}
GatewayContentDTO gatewayFaultContentDTO = retrieveOperationPolicySequence(extractedPath, api, APIConstants.OPERATION_SEQUENCE_TYPE_FAULT);
if (gatewayFaultContentDTO != null) {
gatewayAPIDTO.setSequenceToBeAdd(addGatewayContentToList(gatewayFaultContentDTO, gatewayAPIDTO.getSequenceToBeAdd()));
}
} else {
GatewayContentDTO gatewayInContentDTO = retrieveSequence(extractedPath, apidto.getMediationPolicies(), APIConstants.API_CUSTOM_SEQUENCE_TYPE_IN, api);
if (gatewayInContentDTO != null) {
gatewayAPIDTO.setSequenceToBeAdd(addGatewayContentToList(gatewayInContentDTO, gatewayAPIDTO.getSequenceToBeAdd()));
}
GatewayContentDTO gatewayOutContentDTO = retrieveSequence(extractedPath, apidto.getMediationPolicies(), APIConstants.API_CUSTOM_SEQUENCE_TYPE_OUT, api);
if (gatewayOutContentDTO != null) {
gatewayAPIDTO.setSequenceToBeAdd(addGatewayContentToList(gatewayOutContentDTO, gatewayAPIDTO.getSequenceToBeAdd()));
}
}
}
use of org.wso2.carbon.apimgt.api.gateway.GatewayContentDTO in project carbon-apimgt by wso2.
the class TemplateBuilderUtil method retrieveOperationPolicySequenceForProducts.
private static GatewayContentDTO retrieveOperationPolicySequenceForProducts(APIProduct apiProduct, API api, String extractedLocation, String flow) throws APIManagementException {
Set<URITemplate> applicableURITemplates = new HashSet<>();
for (APIProductResource productResource : apiProduct.getProductResources()) {
if (productResource.getApiIdentifier().equals(api.getId())) {
applicableURITemplates.add(productResource.getUriTemplate());
}
}
String policySequence = null;
APIProductIdentifier apiProductIdentifier = apiProduct.getId();
String seqExt = APIUtil.getSequenceExtensionName(apiProductIdentifier.getName(), apiProductIdentifier.getVersion()).concat("--").concat(api.getUuid()).concat(SynapsePolicyAggregator.getSequenceExtensionFlow(flow));
try {
policySequence = SynapsePolicyAggregator.generatePolicySequenceForUriTemplateSet(applicableURITemplates, seqExt, flow, extractedLocation);
} catch (IOException e) {
throw new APIManagementException(e);
}
GatewayContentDTO operationPolicySequenceContentDto = new GatewayContentDTO();
if (StringUtils.isNotEmpty(policySequence)) {
try {
OMElement omElement = APIUtil.buildOMElement(new ByteArrayInputStream(policySequence.getBytes()));
if (omElement != null) {
if (omElement.getAttribute(new QName("name")) != null) {
omElement.getAttribute(new QName("name")).setAttributeValue(seqExt);
}
operationPolicySequenceContentDto.setName(seqExt);
operationPolicySequenceContentDto.setContent(APIUtil.convertOMtoString(omElement));
for (APIProductResource productResource : apiProduct.getProductResources()) {
if (productResource.getApiIdentifier().equals(api.getId())) {
switch(flow) {
case APIConstants.OPERATION_SEQUENCE_TYPE_REQUEST:
productResource.setInSequenceName(seqExt);
break;
case APIConstants.OPERATION_SEQUENCE_TYPE_RESPONSE:
productResource.setOutSequenceName(seqExt);
break;
case APIConstants.OPERATION_SEQUENCE_TYPE_FAULT:
productResource.setFaultSequenceName(seqExt);
break;
}
}
}
return operationPolicySequenceContentDto;
}
} catch (Exception e) {
throw new APIManagementException(e);
}
}
return null;
}
use of org.wso2.carbon.apimgt.api.gateway.GatewayContentDTO in project carbon-apimgt by wso2.
the class TemplateBuilderUtil method setClientCertificatesToBeAdded.
/**
* To deploy client certificate in given API environment.
*
* @param tenantDomain Tenant domain.
* @param clientCertificatesDTOList
*/
private static void setClientCertificatesToBeAdded(String tenantDomain, GatewayAPIDTO gatewayAPIDTO, List<ClientCertificateDTO> clientCertificatesDTOList) {
int tenantId = APIUtil.getTenantIdFromTenantDomain(tenantDomain);
if (clientCertificatesDTOList != null) {
for (ClientCertificateDTO clientCertificateDTO : clientCertificatesDTOList) {
GatewayContentDTO clientCertificate = new GatewayContentDTO();
clientCertificate.setName(clientCertificateDTO.getAlias() + "_" + tenantId);
clientCertificate.setContent(clientCertificateDTO.getCertificate());
gatewayAPIDTO.setClientCertificatesToBeAdd(addGatewayContentToList(clientCertificate, gatewayAPIDTO.getClientCertificatesToBeAdd()));
}
}
}
Aggregations