use of org.wso2.carbon.apimgt.api.gateway.GatewayContentDTO in project carbon-apimgt by wso2.
the class TemplateBuilderUtil method retrieveSequence.
private static GatewayContentDTO retrieveSequence(APIProduct apiProduct, String pathToAchieve, List<MediationPolicyDTO> mediationPolicies, String type, API api) throws APIManagementException {
APIProductIdentifier apiProductIdentifier = apiProduct.getId();
MediationPolicyDTO mediationPolicyDTO = null;
for (MediationPolicyDTO mediationPolicy : mediationPolicies) {
if (type.equalsIgnoreCase(mediationPolicy.getType())) {
mediationPolicyDTO = mediationPolicy;
break;
}
}
if (mediationPolicyDTO != null) {
GatewayContentDTO sequenceContentDto = new GatewayContentDTO();
String sequenceContent = ImportUtils.retrieveSequenceContent(pathToAchieve, !mediationPolicyDTO.isShared(), type.toLowerCase(), mediationPolicyDTO.getName());
if (StringUtils.isNotEmpty(sequenceContent)) {
try {
OMElement omElement = APIUtil.buildOMElement(new ByteArrayInputStream(sequenceContent.getBytes()));
if (omElement != null) {
String seqExt = APIUtil.getSequenceExtensionName(apiProductIdentifier.getName(), apiProductIdentifier.getVersion()).concat("--").concat(api.getUuid());
if (APIConstants.API_CUSTOM_SEQUENCE_TYPE_FAULT.equalsIgnoreCase(type)) {
seqExt = seqExt + APIConstants.API_CUSTOM_SEQ_FAULT_EXT;
} else if (APIConstants.API_CUSTOM_SEQUENCE_TYPE_OUT.equalsIgnoreCase(type)) {
seqExt = seqExt + APIConstants.API_CUSTOM_SEQ_OUT_EXT;
} else if (APIConstants.API_CUSTOM_SEQUENCE_TYPE_IN.equalsIgnoreCase(type)) {
seqExt = seqExt + APIConstants.API_CUSTOM_SEQ_IN_EXT;
}
if (omElement.getAttribute(new QName("name")) != null) {
omElement.getAttribute(new QName("name")).setAttributeValue(seqExt);
}
sequenceContentDto.setName(seqExt);
sequenceContentDto.setContent(APIUtil.convertOMtoString(omElement));
return sequenceContentDto;
}
} 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 addWebSocketResourceEndpoints.
public static void addWebSocketResourceEndpoints(API api, APITemplateBuilder builder, GatewayAPIDTO gatewayAPIDTO) throws APITemplateException, XMLStreamException {
Set<URITemplate> uriTemplates = api.getUriTemplates();
Map<String, Map<String, String>> topicMappings = api.getWebSocketTopicMappingConfiguration().getMappings();
List<GatewayContentDTO> endpointsToAdd = new ArrayList<>();
for (URITemplate resource : uriTemplates) {
String topic = resource.getUriTemplate();
Map<String, String> endpoints = topicMappings.get(topic);
// Production and Sandbox endpoints
for (Map.Entry<String, String> endpointData : endpoints.entrySet()) {
if (!"resourceKey".equals(endpointData.getKey())) {
String endpointType = endpointData.getKey();
String endpointUrl = endpointData.getValue();
String endpointConfigContext = builder.getConfigStringForWebSocketEndpointTemplate(endpointType, getWebsocketResourceKey(topic), endpointUrl);
GatewayContentDTO endpoint = new GatewayContentDTO();
// For WS APIs, resource type is not applicable,
// so we can just use the uriTemplate/uriMapping to identify the resource
endpoint.setName(getEndpointName(endpointConfigContext));
endpoint.setContent(endpointConfigContext);
endpointsToAdd.add(endpoint);
}
}
// once through resources is enough.
if (APIConstants.GRAPHQL_API.equals(api.getType())) {
break;
}
}
gatewayAPIDTO.setEndpointEntriesToBeAdd(addGatewayContentsToList(endpointsToAdd, gatewayAPIDTO.getEndpointEntriesToBeAdd()));
}
use of org.wso2.carbon.apimgt.api.gateway.GatewayContentDTO in project carbon-apimgt by wso2.
the class TemplateBuilderUtil method setAPIFaultSequencesToBeAdded.
private static void setAPIFaultSequencesToBeAdded(API api, GatewayAPIDTO gatewayAPIDTO, String extractedPath, APIDTO apidto) throws APIManagementException {
String faultSeqExt = APIUtil.getSequenceExtensionName(api) + APIConstants.API_CUSTOM_SEQ_FAULT_EXT;
if (!APIConstants.APITransportType.HTTP.toString().equals(api.getType())) {
gatewayAPIDTO.setSequencesToBeRemove(GatewayUtils.addStringToList(faultSeqExt, gatewayAPIDTO.getSequencesToBeRemove()));
List<MediationPolicyDTO> mediationPolicies = apidto.getMediationPolicies();
GatewayContentDTO faultSequenceContent = retrieveSequence(extractedPath, mediationPolicies, APIConstants.API_CUSTOM_SEQUENCE_TYPE_FAULT, api);
if (faultSequenceContent != null) {
gatewayAPIDTO.setSequenceToBeAdd(addGatewayContentToList(faultSequenceContent, gatewayAPIDTO.getSequenceToBeAdd()));
}
}
gatewayAPIDTO.setSequencesToBeRemove(GatewayUtils.addStringToList(faultSeqExt, gatewayAPIDTO.getSequencesToBeRemove()));
}
use of org.wso2.carbon.apimgt.api.gateway.GatewayContentDTO in project carbon-apimgt by wso2.
the class TemplateBuilderUtil method setCustomSequencesToBeAdded.
private static void setCustomSequencesToBeAdded(APIProduct apiProduct, API api, GatewayAPIDTO gatewayAPIDTO, String extractedPath, APIDTO apidto) throws APIManagementException {
if (APIConstants.APITransportType.HTTP.toString().equals(api.getType())) {
GatewayContentDTO gatewayInContentDTO = retrieveOperationPolicySequenceForProducts(apiProduct, api, extractedPath, APIConstants.OPERATION_SEQUENCE_TYPE_REQUEST);
if (gatewayInContentDTO != null) {
gatewayAPIDTO.setSequenceToBeAdd(addGatewayContentToList(gatewayInContentDTO, gatewayAPIDTO.getSequenceToBeAdd()));
}
GatewayContentDTO gatewayOutContentDTO = retrieveOperationPolicySequenceForProducts(apiProduct, api, extractedPath, APIConstants.OPERATION_SEQUENCE_TYPE_RESPONSE);
if (gatewayOutContentDTO != null) {
gatewayAPIDTO.setSequenceToBeAdd(addGatewayContentToList(gatewayOutContentDTO, gatewayAPIDTO.getSequenceToBeAdd()));
}
GatewayContentDTO gatewayFaultContentDTO = retrieveOperationPolicySequenceForProducts(apiProduct, api, extractedPath, APIConstants.OPERATION_SEQUENCE_TYPE_FAULT);
if (gatewayFaultContentDTO != null) {
gatewayAPIDTO.setSequenceToBeAdd(addGatewayContentToList(gatewayFaultContentDTO, gatewayAPIDTO.getSequenceToBeAdd()));
}
} else {
GatewayContentDTO gatewayInContentDTO = retrieveSequence(apiProduct, extractedPath, apidto.getMediationPolicies(), APIConstants.API_CUSTOM_SEQUENCE_TYPE_IN, api);
if (gatewayInContentDTO != null) {
gatewayAPIDTO.setSequenceToBeAdd(addGatewayContentToList(gatewayInContentDTO, gatewayAPIDTO.getSequenceToBeAdd()));
}
GatewayContentDTO gatewayOutContentDTO = retrieveSequence(apiProduct, 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 retrieveSequence.
private static GatewayContentDTO retrieveSequence(String pathToAchieve, List<MediationPolicyDTO> mediationPolicies, String type, API api) throws APIManagementException {
MediationPolicyDTO mediationPolicyDTO = null;
for (MediationPolicyDTO mediationPolicy : mediationPolicies) {
if (type.equalsIgnoreCase(mediationPolicy.getType())) {
mediationPolicyDTO = mediationPolicy;
break;
}
}
if (mediationPolicyDTO != null) {
GatewayContentDTO sequenceContentDto = new GatewayContentDTO();
String sequenceContent = ImportUtils.retrieveSequenceContent(pathToAchieve, !mediationPolicyDTO.isShared(), type.toLowerCase(), mediationPolicyDTO.getName());
if (StringUtils.isNotEmpty(sequenceContent)) {
try {
OMElement omElement = APIUtil.buildOMElement(new ByteArrayInputStream(sequenceContent.getBytes()));
if (omElement != null) {
String seqExt = APIUtil.getSequenceExtensionName(api);
if (APIConstants.API_CUSTOM_SEQUENCE_TYPE_FAULT.equalsIgnoreCase(type)) {
seqExt = seqExt + APIConstants.API_CUSTOM_SEQ_FAULT_EXT;
} else if (APIConstants.API_CUSTOM_SEQUENCE_TYPE_OUT.equalsIgnoreCase(type)) {
seqExt = seqExt + APIConstants.API_CUSTOM_SEQ_OUT_EXT;
} else if (APIConstants.API_CUSTOM_SEQUENCE_TYPE_IN.equalsIgnoreCase(type)) {
seqExt = seqExt + APIConstants.API_CUSTOM_SEQ_IN_EXT;
}
if (omElement.getAttribute(new QName("name")) != null) {
omElement.getAttribute(new QName("name")).setAttributeValue(seqExt);
}
sequenceContentDto.setName(seqExt);
sequenceContentDto.setContent(APIUtil.convertOMtoString(omElement));
return sequenceContentDto;
}
} catch (Exception e) {
throw new APIManagementException(e);
}
}
}
return null;
}
Aggregations