Java Code Examples for org.wso2.carbon.apimgt.api.model.API#getFaultSequence()

The following examples show how to use org.wso2.carbon.apimgt.api.model.API#getFaultSequence() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: APIImportUtil.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
/**
 * This method adds API sequences to the imported API. If the sequence is a newly defined one, it is added.
 *
 * @param pathToArchive location of the extracted folder of the API
 * @param importedApi   the imported API object
 */
private static void addAPISequences(String pathToArchive, API importedApi, Registry registry) {

    String inSequenceFileName = importedApi.getInSequence() + APIConstants.XML_EXTENSION;
    String inSequenceFileLocation = pathToArchive + APIImportExportConstants.IN_SEQUENCE_LOCATION
            + inSequenceFileName;
    String regResourcePath;

    //Adding in-sequence, if any
    if (CommonUtil.checkFileExistence(inSequenceFileLocation)) {
        regResourcePath = APIConstants.API_CUSTOM_INSEQUENCE_LOCATION + inSequenceFileName;
        addSequenceToRegistry(false, registry, inSequenceFileLocation, regResourcePath);
    }

    String outSequenceFileName = importedApi.getOutSequence() + APIConstants.XML_EXTENSION;
    String outSequenceFileLocation = pathToArchive + APIImportExportConstants.OUT_SEQUENCE_LOCATION
            + outSequenceFileName;

    //Adding out-sequence, if any
    if (CommonUtil.checkFileExistence(outSequenceFileLocation)) {
        regResourcePath = APIConstants.API_CUSTOM_OUTSEQUENCE_LOCATION + outSequenceFileName;
        addSequenceToRegistry(false, registry, outSequenceFileLocation, regResourcePath);
    }

    String faultSequenceFileName = importedApi.getFaultSequence() + APIConstants.XML_EXTENSION;
    String faultSequenceFileLocation = pathToArchive + APIImportExportConstants.FAULT_SEQUENCE_LOCATION
            + faultSequenceFileName;

    //Adding fault-sequence, if any
    if (CommonUtil.checkFileExistence(faultSequenceFileLocation)) {
        regResourcePath = APIConstants.API_CUSTOM_FAULTSEQUENCE_LOCATION + faultSequenceFileName;
        addSequenceToRegistry(false, registry, faultSequenceFileLocation, regResourcePath);
    }
}
 
Example 2
Source File: APIGatewayManager.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
private void setAPIFaultSequencesToBeAdded(API api, String tenantDomain, GatewayAPIDTO gatewayAPIDTO)
        throws APIManagementException {

    String faultSequenceName = api.getFaultSequence();
    String faultSeqExt = APIUtil.getSequenceExtensionName(api) + APIConstants.API_CUSTOM_SEQ_FAULT_EXT;
    boolean isTenantFlowStarted = false;
    try {
        PrivilegedCarbonContext.startTenantFlow();
        isTenantFlowStarted = true;
        if (!StringUtils.isEmpty(tenantDomain)) {
            PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
        } else {
            PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain
                    (MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, true);
        }

        //If a fault sequence has be defined.
        if (APIUtil.isSequenceDefined(faultSequenceName)) {
            int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
            gatewayAPIDTO
                    .setSequencesToBeRemove(addStringToList(faultSeqExt, gatewayAPIDTO.getSequencesToBeRemove()));

            //Get the fault sequence xml
            OMElement faultSequence = APIUtil.getCustomSequence(faultSequenceName, tenantId,
                    APIConstants.API_CUSTOM_SEQUENCE_TYPE_FAULT, api.getId());

            if (faultSequence != null) {
                if (APIUtil.isPerAPISequence(faultSequenceName, tenantId, api.getId(),
                        APIConstants.API_CUSTOM_SEQUENCE_TYPE_FAULT)) {
                    if (faultSequence.getAttribute(new QName("name")) != null) {
                        faultSequence.getAttribute(new QName("name")).setAttributeValue(faultSeqExt);
                    }
                } else {
                    gatewayAPIDTO.setSequencesToBeRemove(addStringToList(faultSequenceName,
                            gatewayAPIDTO.getSequencesToBeRemove()));
                    faultSeqExt = faultSequenceName;
                }
                GatewayContentDTO faultSequenceContent = new GatewayContentDTO();
                faultSequenceContent.setName(faultSeqExt);
                faultSequenceContent.setContent(APIUtil.convertOMtoString(faultSequence));
                gatewayAPIDTO.setSequenceToBeAdd(addGatewayContentToList(faultSequenceContent,
                        gatewayAPIDTO.getSequenceToBeAdd()));
            }
        } else {
            gatewayAPIDTO
                    .setSequencesToBeRemove(addStringToList(faultSeqExt, gatewayAPIDTO.getSequencesToBeRemove()));
        }
    } catch (XMLStreamException e) {
        throw new APIManagementException("Error while updating the fault sequence at the Gateway", e);
    } finally {
        if (isTenantFlowStarted) {
            PrivilegedCarbonContext.endTenantFlow();
        }
    }
}
 
Example 3
Source File: APIExportUtil.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
/**
 * Retrieve available custom sequences and API specific sequences for API export.
 *
 * @param api      exporting API
 * @param registry current tenant registry
 * @throws APIImportExportException If an error occurs while exporting sequences
 */
private static void exportSequences(String archivePath, API api, Registry registry) throws APIImportExportException {

    Map<String, String> sequences = new HashMap<>();
    APIIdentifier apiIdentifier = api.getId();
    String seqArchivePath = archivePath.concat(File.separator + "Sequences");

    if (api.getInSequence() != null) {
        sequences.put(APIConstants.API_CUSTOM_SEQUENCE_TYPE_IN, api.getInSequence());
    }

    if (api.getOutSequence() != null) {
        sequences.put(APIConstants.API_CUSTOM_SEQUENCE_TYPE_OUT, api.getOutSequence());
    }

    if (api.getFaultSequence() != null) {
        sequences.put(APIConstants.API_CUSTOM_SEQUENCE_TYPE_FAULT, api.getFaultSequence());
    }

    if (!sequences.isEmpty()) {
        CommonUtil.createDirectory(seqArchivePath);
        for (Map.Entry<String, String> sequence : sequences.entrySet()) {
            AbstractMap.SimpleEntry<String, OMElement> sequenceDetails;
            String sequenceName = sequence.getValue();
            String direction = sequence.getKey();
            String pathToExportedSequence = seqArchivePath + File.separator + direction + "-sequence" + File.separator;
            if (sequenceName != null) {
                sequenceDetails = getCustomSequence(sequenceName, direction, registry);
                if (sequenceDetails == null) {
                    //If sequence doesn't exist in 'apimgt/customsequences/{in/out/fault}' directory check in API
                    //specific registry path
                    sequenceDetails = getAPISpecificSequence(api.getId(), sequenceName, direction, registry);
                    pathToExportedSequence += APIImportExportConstants.CUSTOM_TYPE + File.separator;
                }
                writeSequenceToFile(pathToExportedSequence, sequenceDetails, apiIdentifier);
            }
        }
    } else if (log.isDebugEnabled()) {
        log.debug("No custom sequences available for API: " + apiIdentifier.getApiName() + StringUtils.SPACE
                + APIConstants.API_DATA_VERSION + ": " + apiIdentifier.getVersion()
                + ". Skipping custom sequence export.");
    }
}
 
Example 4
Source File: APIImportUtil.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
/**
 * This method adds API Specific sequences added through the Publisher to the imported API. If the specific
 * sequence already exists, it is updated.
 *
 * @param pathToArchive location of the extracted folder of the API
 * @param importedApi   the imported API object
 */
private static void addAPISpecificSequences(String pathToArchive, API importedApi, Registry registry) {

    String regResourcePath = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR
            + importedApi.getId().getProviderName() + RegistryConstants.PATH_SEPARATOR
            + importedApi.getId().getApiName() + RegistryConstants.PATH_SEPARATOR
            + importedApi.getId().getVersion() + RegistryConstants.PATH_SEPARATOR;

    String inSequenceFileName = importedApi.getInSequence();
    String inSequenceFileLocation = pathToArchive + APIImportExportConstants.IN_SEQUENCE_LOCATION
            + APIImportExportConstants.CUSTOM_TYPE + File.separator + inSequenceFileName;

    //Adding in-sequence, if any
    if (CommonUtil.checkFileExistence(inSequenceFileLocation + APIConstants.XML_EXTENSION)) {
        String inSequencePath = APIConstants.API_CUSTOM_SEQUENCE_TYPE_IN + RegistryConstants.PATH_SEPARATOR
                + inSequenceFileName;
        addSequenceToRegistry(true, registry, inSequenceFileLocation + APIConstants.XML_EXTENSION, regResourcePath + inSequencePath);
    }

    String outSequenceFileName = importedApi.getOutSequence() + APIConstants.XML_EXTENSION;
    String outSequenceFileLocation = pathToArchive + APIImportExportConstants.OUT_SEQUENCE_LOCATION
            + APIImportExportConstants.CUSTOM_TYPE + File.separator + outSequenceFileName;

    //Adding out-sequence, if any
    if (CommonUtil.checkFileExistence(outSequenceFileLocation)) {
        String outSequencePath = APIConstants.API_CUSTOM_SEQUENCE_TYPE_OUT + RegistryConstants.PATH_SEPARATOR
                + outSequenceFileName;
        addSequenceToRegistry(true, registry, outSequenceFileLocation, regResourcePath + outSequencePath);
    }

    String faultSequenceFileName = importedApi.getFaultSequence() + APIConstants.XML_EXTENSION;
    String faultSequenceFileLocation = pathToArchive + APIImportExportConstants.FAULT_SEQUENCE_LOCATION
            + APIImportExportConstants.CUSTOM_TYPE + File.separator + faultSequenceFileName;

    //Adding fault-sequence, if any
    if (CommonUtil.checkFileExistence(faultSequenceFileLocation)) {
        String faultSequencePath = APIConstants.API_CUSTOM_SEQUENCE_TYPE_FAULT + RegistryConstants.PATH_SEPARATOR
                + faultSequenceFileName;
        addSequenceToRegistry(true, registry, faultSequenceFileLocation, regResourcePath + faultSequencePath);
    }
}