Java Code Examples for org.wso2.carbon.apimgt.impl.utils.APIUtil#getCustomSequence()

The following examples show how to use org.wso2.carbon.apimgt.impl.utils.APIUtil#getCustomSequence() . 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: APIGatewayManager.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
private void addSequence(API api, int tenantId, GatewayAPIDTO gatewayAPIDTO, String sequenceType,
                         String sequenceExtension,String sequenceName) throws APIManagementException, XMLStreamException {

    OMElement inSequence = APIUtil.getCustomSequence(sequenceName, tenantId, sequenceType, api.getId());

    if (inSequence != null) {
        String inSeqExt = APIUtil.getSequenceExtensionName(api) + sequenceExtension;
        if (inSequence.getAttribute(new QName("name")) != null) {
            inSequence.getAttribute(new QName("name")).setAttributeValue(inSeqExt);
        }
        GatewayContentDTO sequenceDto = new GatewayContentDTO();
        sequenceDto.setName(inSeqExt);
        sequenceDto.setContent(APIUtil.convertOMtoString(inSequence));
        gatewayAPIDTO.setSequenceToBeAdd(addGatewayContentToList(sequenceDto, gatewayAPIDTO.getSequenceToBeAdd()));
    }

}
 
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();
        }
    }
}