Search in sources :

Example 1 with APIMediationFlowPoint

use of org.apache.synapse.debug.constructs.APIMediationFlowPoint in project wso2-synapse by wso2.

the class APIDebugUtil method registerAPISequenceMediationFlowBreakPoint.

/**
 * Registers/Un-registers a breakpoint, point where mediation flow get suspended
 *
 * @param synCfg Synapse configuration
 * @param mapping either resource url-mapping or uri-template
 * @param method resource http method
 * @param sequenceType Synapse sequence type
 * @param apiKey name of the API
 * @param position array of integers that uniquely specifies a point in mediation route
 * @param registerMode specify whether register or un register
 */
public static void registerAPISequenceMediationFlowBreakPoint(SynapseConfiguration synCfg, String mapping, String method, String sequenceType, String apiKey, int[] position, boolean registerMode) {
    SynapseSequenceType synapseSequenceType = SynapseSequenceType.valueOf(sequenceType.toUpperCase());
    APIMediationFlowPoint breakPoint = new APIMediationFlowPoint();
    breakPoint.setSynapseMediationComponent(SynapseMediationComponent.SEQUENCE);
    breakPoint.setKey(apiKey);
    breakPoint.setMediatorPosition(position);
    breakPoint.setSynapseSequenceType(synapseSequenceType);
    breakPoint.setSequenceBaseType(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE_API);
    breakPoint.setResourceMapping(mapping);
    breakPoint.setResourceHTTPMethod(method);
    Mediator seqMediator = null;
    Resource api_resource = null;
    API api = synCfg.getAPI(apiKey);
    if (api == null) {
        if (log.isDebugEnabled()) {
            log.debug("Non existing API for the key " + breakPoint.getKey());
        }
        debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_API_NOT_FOUND).toString());
        return;
    }
    Resource[] resource_array = api.getResources();
    for (int counter = 0; counter < resource_array.length; counter++) {
        if (resource_array[counter].getDispatcherHelper() != null && mapping != null) {
            if (mapping.equals(resource_array[counter].getDispatcherHelper().getString())) {
                for (String m1 : resource_array[counter].getMethods()) {
                    if (m1.equals(method)) {
                        api_resource = resource_array[counter];
                        break;
                    }
                }
                if (api_resource != null) {
                    break;
                }
            }
        } else if (resource_array[counter].getDispatcherHelper() == null && mapping == null) {
            for (String m1 : resource_array[counter].getMethods()) {
                if (m1.equals(method)) {
                    api_resource = resource_array[counter];
                    break;
                }
            }
            if (api_resource != null) {
                break;
            }
        }
    }
    if (api_resource != null) {
        if (synapseSequenceType.equals(SynapseSequenceType.API_INSEQ)) {
            seqMediator = api_resource.getInSequence();
        } else if (synapseSequenceType.equals(SynapseSequenceType.API_OUTSEQ)) {
            seqMediator = api_resource.getOutSequence();
        } else if (synapseSequenceType.equals(SynapseSequenceType.API_FAULTSEQ)) {
            seqMediator = api_resource.getFaultSequence();
        }
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Resource not found for the API key " + breakPoint.getKey() + " resource mapping " + breakPoint.getResourceMapping() + " resource HTTP method " + breakPoint.getResourceHTTPMethod());
        }
        debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_API_RESOURCE_NOT_FOUND).toString());
        return;
    }
    if (seqMediator != null) {
        Mediator current_mediator = null;
        current_mediator = MediatorTreeTraverseUtil.getMediatorReference(synCfg, seqMediator, position);
        if (current_mediator != null) {
            breakPoint.setMediatorReference(current_mediator);
            if (registerMode) {
                if (!((AbstractMediator) current_mediator).isBreakPoint()) {
                    ((AbstractMediator) current_mediator).setBreakPoint(true);
                    ((AbstractMediator) current_mediator).registerMediationFlowPoint(breakPoint);
                    if (log.isDebugEnabled()) {
                        log.info("Registered breakpoint at mediator position " + logMediatorPosition(breakPoint) + " for API key " + breakPoint.getKey() + " resource mapping " + breakPoint.getResourceMapping() + " resource HTTP method " + breakPoint.getResourceHTTPMethod() + " sequence type " + breakPoint.getSynapseSequenceType().toString());
                    }
                    debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(true, null).toString());
                } else {
                    if (log.isDebugEnabled()) {
                        log.debug("Failed register breakpoint. Already breakpoint enabled at mediator position " + logMediatorPosition(breakPoint) + " for API key " + breakPoint.getKey() + " resource mapping " + breakPoint.getResourceMapping() + " resource HTTP method " + breakPoint.getResourceHTTPMethod() + " sequence type " + breakPoint.getSynapseSequenceType().toString());
                    }
                    debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_ALREADY_BREAKPOINT_ENABLED).toString());
                }
            } else {
                if (((AbstractMediator) current_mediator).isBreakPoint()) {
                    ((AbstractMediator) current_mediator).unregisterMediationFlowPoint();
                    ((AbstractMediator) current_mediator).setBreakPoint(false);
                    if (log.isDebugEnabled()) {
                        log.debug("Unregistered breakpoint at mediator position " + logMediatorPosition(breakPoint) + " for API key " + breakPoint.getKey() + " resource mapping " + breakPoint.getResourceMapping() + " resource HTTP method " + breakPoint.getResourceHTTPMethod() + " sequence type " + breakPoint.getSynapseSequenceType().toString());
                    }
                    debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(true, null).toString());
                } else {
                    if (log.isDebugEnabled()) {
                        log.debug("Failed unregister breakpoint. Already breakpoint disabled at mediator position " + logMediatorPosition(breakPoint) + " for API key " + breakPoint.getKey() + " resource mapping " + breakPoint.getResourceMapping() + " resource HTTP method " + breakPoint.getResourceHTTPMethod() + " sequence type " + breakPoint.getSynapseSequenceType().toString());
                    }
                    debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_ALREADY_BREAKPOINT_DISABLED).toString());
                }
            }
        } else {
            if (registerMode) {
                if (log.isDebugEnabled()) {
                    log.debug("Failed register breakpoint. Non existing mediator position at " + logMediatorPosition(breakPoint) + " for API key " + breakPoint.getKey() + " resource mapping " + breakPoint.getResourceMapping() + " resource HTTP method " + breakPoint.getResourceHTTPMethod() + " sequence type " + breakPoint.getSynapseSequenceType().toString());
                }
                debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_NON_EXISTING_MEDIATOR_POSITION).toString());
            } else {
                if (log.isDebugEnabled()) {
                    log.debug("Failed unregister breakpoint. Non existing mediator position at " + logMediatorPosition(breakPoint) + " for API key " + breakPoint.getKey() + " resource mapping " + breakPoint.getResourceMapping() + " resource HTTP method " + breakPoint.getResourceHTTPMethod() + " sequence type " + breakPoint.getSynapseSequenceType().toString());
                }
                debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_NON_EXISTING_MEDIATOR_POSITION).toString());
            }
        }
    } else {
        if (registerMode) {
            if (log.isDebugEnabled()) {
                log.debug("Failed register breakpoint. Non existing sequence " + breakPoint.getSynapseSequenceType().toString() + " for API key " + breakPoint.getKey() + " resource mapping " + breakPoint.getResourceMapping() + " resource HTTP method " + breakPoint.getResourceHTTPMethod());
            }
            debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_NON_EXISTING_SEQUENCE).toString());
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Failed unregister breakpoint. Non existing sequence " + breakPoint.getSynapseSequenceType().toString() + " for API key " + breakPoint.getKey() + " resource mapping " + breakPoint.getResourceMapping() + " resource HTTP method " + breakPoint.getResourceHTTPMethod());
            }
            debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_NON_EXISTING_SEQUENCE).toString());
        }
    }
}
Also used : SynapseSequenceType(org.apache.synapse.debug.constructs.SynapseSequenceType) APIMediationFlowPoint(org.apache.synapse.debug.constructs.APIMediationFlowPoint) Resource(org.apache.synapse.rest.Resource) AbstractMediator(org.apache.synapse.mediators.AbstractMediator) Mediator(org.apache.synapse.Mediator) API(org.apache.synapse.rest.API) AbstractMediator(org.apache.synapse.mediators.AbstractMediator) APIMediationFlowPoint(org.apache.synapse.debug.constructs.APIMediationFlowPoint) SynapseMediationFlowPoint(org.apache.synapse.debug.constructs.SynapseMediationFlowPoint)

Example 2 with APIMediationFlowPoint

use of org.apache.synapse.debug.constructs.APIMediationFlowPoint in project wso2-synapse by wso2.

the class SynapseDebugManager method createDebugMediationFlowPointJSONForWireLogs.

/**
 * This method is to generate json string which can be used to identify mediator position for wire logs
 *
 * @param point
 * @return
 */
public JSONObject createDebugMediationFlowPointJSONForWireLogs(SynapseMediationFlowPoint point) {
    JSONObject flowPointJson = null;
    try {
        flowPointJson = new JSONObject();
        JSONObject parameters = new JSONObject();
        if (point.getSynapseMediationComponent().equals(SynapseMediationComponent.SEQUENCE)) {
            flowPointJson.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT, SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE);
            if (((SequenceMediationFlowPoint) point).getSequenceBaseType().equals(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE)) {
                parameters.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE_KEY, point.getKey());
                parameters.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE_TYPE, ((SequenceMediationFlowPoint) point).getSynapseSequenceType().toString().toLowerCase());
                parameters.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_MEDIATOR_POSITION, toString(point.getMediatorPosition()));
                flowPointJson.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE, parameters);
            } else if (((SequenceMediationFlowPoint) point).getSequenceBaseType().equals(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE_PROXY)) {
                JSONObject proxy_parameters = new JSONObject();
                proxy_parameters.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE_PROXY_KEY, point.getKey());
                proxy_parameters.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE_TYPE, ((SequenceMediationFlowPoint) point).getSynapseSequenceType().toString().toLowerCase());
                proxy_parameters.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_MEDIATOR_POSITION, toString(point.getMediatorPosition()));
                parameters.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE_PROXY, proxy_parameters);
                flowPointJson.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE, parameters);
            } else if (((SequenceMediationFlowPoint) point).getSequenceBaseType().equals(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE_INBOUND)) {
                JSONObject inbound_parameters = new JSONObject();
                inbound_parameters.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE_INBOUND_KEY, point.getKey());
                inbound_parameters.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE_TYPE, ((SequenceMediationFlowPoint) point).getSynapseSequenceType().toString().toLowerCase());
                inbound_parameters.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_MEDIATOR_POSITION, toString(point.getMediatorPosition()));
                parameters.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE_INBOUND, inbound_parameters);
                flowPointJson.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE, parameters);
            } else if (((SequenceMediationFlowPoint) point).getSequenceBaseType().equals(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE_API)) {
                JSONObject api_parameters = new JSONObject();
                api_parameters.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE_API_KEY, point.getKey());
                JSONObject resource = new JSONObject();
                resource.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE_API_RESOURCE_MAPPING, ((APIMediationFlowPoint) point).getResourceMapping());
                resource.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE_API_RESOURCE_METHOD, ((APIMediationFlowPoint) point).getResourceHTTPMethod());
                api_parameters.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE_API_RESOURCE, resource);
                api_parameters.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE_TYPE, ((SequenceMediationFlowPoint) point).getSynapseSequenceType().toString().toLowerCase());
                api_parameters.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_MEDIATOR_POSITION, toString(point.getMediatorPosition()));
                parameters.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE_API, api_parameters);
                flowPointJson.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE, parameters);
            }
        } else if (point.getSynapseMediationComponent().equals(SynapseMediationComponent.TEMPLATE)) {
            flowPointJson.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT, SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_TEMPLATE);
            parameters.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_TEMPLATE_KEY, point.getKey());
            parameters.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_MEDIATOR_POSITION, toString(point.getMediatorPosition()));
            flowPointJson.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_TEMPLATE, parameters);
        } else if (point.getSynapseMediationComponent().equals(SynapseMediationComponent.CONNECTOR)) {
            flowPointJson.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT, SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_CONNECTOR);
            parameters.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_CONNECTOR_KEY, point.getKey());
            parameters.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_CONNECTOR_METHOD, ((ConnectorMediationFlowPoint) point).getConnectorMediationComponentMethod());
            parameters.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_MEDIATOR_POSITION, toString(point.getMediatorPosition()));
            flowPointJson.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_CONNECTOR, parameters);
        }
    } catch (JSONException ex) {
        log.error("Failed to create debug flowPointJson in JSON format", ex);
    }
    return flowPointJson;
}
Also used : SequenceMediationFlowPoint(org.apache.synapse.debug.constructs.SequenceMediationFlowPoint) JSONObject(org.codehaus.jettison.json.JSONObject) APIMediationFlowPoint(org.apache.synapse.debug.constructs.APIMediationFlowPoint) JSONException(org.codehaus.jettison.json.JSONException)

Example 3 with APIMediationFlowPoint

use of org.apache.synapse.debug.constructs.APIMediationFlowPoint in project wso2-synapse by wso2.

the class SynapseDebugManager method createDebugMediationFlowPointHitEvent.

public JSONObject createDebugMediationFlowPointHitEvent(boolean isBreakpoint, SynapseMediationFlowPoint point) {
    JSONObject event = null;
    try {
        event = new JSONObject();
        if (isBreakpoint) {
            event.put(SynapseDebugEventConstants.DEBUG_EVENT, SynapseDebugEventConstants.DEBUG_EVENT_BREAKPOINT);
        } else {
            event.put(SynapseDebugEventConstants.DEBUG_EVENT, SynapseDebugEventConstants.DEBUG_EVENT_SKIP);
        }
        JSONObject parameters = new JSONObject();
        if (point.getSynapseMediationComponent().equals(SynapseMediationComponent.SEQUENCE)) {
            event.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT, SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE);
            if (((SequenceMediationFlowPoint) point).getSequenceBaseType().equals(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE)) {
                parameters.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE_KEY, point.getKey());
                parameters.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE_TYPE, ((SequenceMediationFlowPoint) point).getSynapseSequenceType().toString().toLowerCase());
                parameters.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_MEDIATOR_POSITION, toString(point.getMediatorPosition()));
                event.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE, parameters);
            } else if (((SequenceMediationFlowPoint) point).getSequenceBaseType().equals(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE_PROXY)) {
                JSONObject proxy_parameters = new JSONObject();
                proxy_parameters.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE_PROXY_KEY, point.getKey());
                proxy_parameters.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE_TYPE, ((SequenceMediationFlowPoint) point).getSynapseSequenceType().toString().toLowerCase());
                proxy_parameters.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_MEDIATOR_POSITION, toString(point.getMediatorPosition()));
                parameters.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE_PROXY, proxy_parameters);
                event.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE, parameters);
            } else if (((SequenceMediationFlowPoint) point).getSequenceBaseType().equals(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE_INBOUND)) {
                JSONObject inbound_parameters = new JSONObject();
                inbound_parameters.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE_INBOUND_KEY, point.getKey());
                inbound_parameters.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE_TYPE, ((SequenceMediationFlowPoint) point).getSynapseSequenceType().toString().toLowerCase());
                inbound_parameters.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_MEDIATOR_POSITION, toString(point.getMediatorPosition()));
                parameters.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE_INBOUND, inbound_parameters);
                event.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE, parameters);
            } else if (((SequenceMediationFlowPoint) point).getSequenceBaseType().equals(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE_API)) {
                JSONObject api_parameters = new JSONObject();
                api_parameters.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE_API_KEY, point.getKey());
                JSONObject resource = new JSONObject();
                resource.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE_API_RESOURCE_MAPPING, ((APIMediationFlowPoint) point).getResourceMapping());
                resource.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE_API_RESOURCE_METHOD, ((APIMediationFlowPoint) point).getResourceHTTPMethod());
                api_parameters.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE_API_RESOURCE, resource);
                api_parameters.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE_TYPE, ((SequenceMediationFlowPoint) point).getSynapseSequenceType().toString().toLowerCase());
                api_parameters.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_MEDIATOR_POSITION, toString(point.getMediatorPosition()));
                parameters.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE_API, api_parameters);
                event.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE, parameters);
            }
        } else if (point.getSynapseMediationComponent().equals(SynapseMediationComponent.TEMPLATE)) {
            event.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT, SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_TEMPLATE);
            parameters.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_TEMPLATE_KEY, point.getKey());
            parameters.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_MEDIATOR_POSITION, toString(point.getMediatorPosition()));
            event.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_TEMPLATE, parameters);
        } else if (point.getSynapseMediationComponent().equals(SynapseMediationComponent.CONNECTOR)) {
            event.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT, SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_CONNECTOR);
            parameters.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_CONNECTOR_KEY, point.getKey());
            parameters.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_CONNECTOR_METHOD, ((ConnectorMediationFlowPoint) point).getConnectorMediationComponentMethod());
            parameters.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_MEDIATOR_POSITION, toString(point.getMediatorPosition()));
            event.put(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_CONNECTOR, parameters);
        }
    } catch (JSONException ex) {
        log.error("Failed to create debug event in JSON format", ex);
    }
    return event;
}
Also used : SequenceMediationFlowPoint(org.apache.synapse.debug.constructs.SequenceMediationFlowPoint) JSONObject(org.codehaus.jettison.json.JSONObject) APIMediationFlowPoint(org.apache.synapse.debug.constructs.APIMediationFlowPoint) JSONException(org.codehaus.jettison.json.JSONException)

Example 4 with APIMediationFlowPoint

use of org.apache.synapse.debug.constructs.APIMediationFlowPoint in project wso2-synapse by wso2.

the class APIDebugUtil method registerAPISequenceMediationFlowSkip.

/**
 * Registers/Un-registers a skip, point where mediator disables from the mediation flow
 *
 * @param synCfg Synapse configuration
 * @param mapping either resource url-mapping or uri-template
 * @param method resource http method
 * @param seqType Synapse sequence type
 * @param apiKey name of the API
 * @param position array of integers that uniquely specifies a point in mediation route
 * @param registerMode specify whether register or un register
 */
public static void registerAPISequenceMediationFlowSkip(SynapseConfiguration synCfg, String mapping, String method, String seqType, String apiKey, int[] position, boolean registerMode) {
    SynapseSequenceType synapseSequenceType = SynapseSequenceType.valueOf(seqType.toUpperCase());
    APIMediationFlowPoint skipPoint = new APIMediationFlowPoint();
    skipPoint.setSynapseMediationComponent(SynapseMediationComponent.SEQUENCE);
    skipPoint.setKey(apiKey);
    skipPoint.setMediatorPosition(position);
    skipPoint.setSynapseSequenceType(synapseSequenceType);
    skipPoint.setSequenceBaseType(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE_API);
    skipPoint.setResourceMapping(mapping);
    skipPoint.setResourceHTTPMethod(method);
    Mediator seqMediator = null;
    Resource api_resource = null;
    API api = synCfg.getAPI(apiKey);
    if (api == null) {
        if (log.isDebugEnabled()) {
            log.debug("Non existing API for the key " + skipPoint.getKey());
        }
        debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_API_NOT_FOUND).toString());
        return;
    }
    Resource[] resource_array = api.getResources();
    for (int counter = 0; counter < resource_array.length; counter++) {
        if (resource_array[counter].getDispatcherHelper() != null && mapping != null) {
            if (mapping.equals(resource_array[counter].getDispatcherHelper().getString())) {
                for (String m1 : resource_array[counter].getMethods()) {
                    if (m1.equals(method)) {
                        api_resource = resource_array[counter];
                        break;
                    }
                }
                if (api_resource != null) {
                    break;
                }
            }
        } else if (resource_array[counter].getDispatcherHelper() == null && mapping == null) {
            for (String m1 : resource_array[counter].getMethods()) {
                if (m1.equals(method)) {
                    api_resource = resource_array[counter];
                    break;
                }
            }
            if (api_resource != null) {
                break;
            }
        }
    }
    if (api_resource != null) {
        if (synapseSequenceType.equals(SynapseSequenceType.API_INSEQ)) {
            seqMediator = api_resource.getInSequence();
        } else if (synapseSequenceType.equals(SynapseSequenceType.API_OUTSEQ)) {
            seqMediator = api_resource.getOutSequence();
        } else if (synapseSequenceType.equals(SynapseSequenceType.API_FAULTSEQ)) {
            seqMediator = api_resource.getFaultSequence();
        }
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Resource not found for the API key " + skipPoint.getKey() + " resource mapping " + skipPoint.getResourceMapping() + " resource HTTP method " + skipPoint.getResourceHTTPMethod());
        }
        debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_API_RESOURCE_NOT_FOUND).toString());
        return;
    }
    if (seqMediator != null) {
        Mediator current_mediator = null;
        current_mediator = MediatorTreeTraverseUtil.getMediatorReference(synCfg, seqMediator, position);
        if (current_mediator != null) {
            skipPoint.setMediatorReference(current_mediator);
            if (registerMode) {
                if (!((AbstractMediator) current_mediator).isSkipEnabled()) {
                    ((AbstractMediator) current_mediator).setSkipEnabled(true);
                    ((AbstractMediator) current_mediator).registerMediationFlowPoint(skipPoint);
                    if (log.isDebugEnabled()) {
                        log.debug("Registered skip at mediator position " + logMediatorPosition(skipPoint) + " for API key " + skipPoint.getKey() + " resource mapping " + skipPoint.getResourceMapping() + " resource HTTP method " + skipPoint.getResourceHTTPMethod() + " sequence type " + skipPoint.getSynapseSequenceType().toString());
                    }
                    debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(true, null).toString());
                } else {
                    if (log.isDebugEnabled()) {
                        log.debug("Failed register skip. Already skip enabled at mediator position " + logMediatorPosition(skipPoint) + " for API key " + skipPoint.getKey() + " resource mapping " + skipPoint.getResourceMapping() + " resource HTTP method " + skipPoint.getResourceHTTPMethod() + " sequence type " + skipPoint.getSynapseSequenceType().toString());
                    }
                    debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_ALREADY_SKIP_ENABLED).toString());
                }
            } else {
                if (((AbstractMediator) current_mediator).isSkipEnabled()) {
                    ((AbstractMediator) current_mediator).unregisterMediationFlowPoint();
                    ((AbstractMediator) current_mediator).setSkipEnabled(false);
                    if (log.isDebugEnabled()) {
                        log.debug("Unregistered skip at mediator position " + logMediatorPosition(skipPoint) + " for API key " + skipPoint.getKey() + " resource mapping " + skipPoint.getResourceMapping() + " resource HTTP method " + skipPoint.getResourceHTTPMethod() + " sequence type " + skipPoint.getSynapseSequenceType().toString());
                    }
                    debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(true, null).toString());
                } else {
                    if (log.isDebugEnabled()) {
                        log.debug("Failed unregister skip. Already skip disabled at mediator position " + logMediatorPosition(skipPoint) + " for API key " + skipPoint.getKey() + " resource mapping " + skipPoint.getResourceMapping() + " resource HTTP method " + skipPoint.getResourceHTTPMethod() + " sequence type " + skipPoint.getSynapseSequenceType().toString());
                    }
                    debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_ALREADY_SKIP_DISABLED).toString());
                }
            }
        } else {
            if (registerMode) {
                if (log.isDebugEnabled()) {
                    log.debug("Failed register skip. Non existing mediator position at " + logMediatorPosition(skipPoint) + " for API key " + skipPoint.getKey() + " resource mapping " + skipPoint.getResourceMapping() + " resource HTTP method " + skipPoint.getResourceHTTPMethod() + " sequence type " + skipPoint.getSynapseSequenceType().toString());
                }
                debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_NON_EXISTING_MEDIATOR_POSITION).toString());
            } else {
                if (log.isDebugEnabled()) {
                    log.debug("Failed unregister skip. Non existing mediator position at " + logMediatorPosition(skipPoint) + " for API key " + skipPoint.getKey() + " resource mapping " + skipPoint.getResourceMapping() + " resource HTTP method " + skipPoint.getResourceHTTPMethod() + " sequence type " + skipPoint.getSynapseSequenceType().toString());
                }
                debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_NON_EXISTING_MEDIATOR_POSITION).toString());
            }
        }
    } else {
        if (registerMode) {
            if (log.isDebugEnabled()) {
                log.debug("Failed register skip. Non existing sequence " + skipPoint.getSynapseSequenceType().toString() + " for API key " + skipPoint.getKey() + " resource mapping " + skipPoint.getResourceMapping() + " resource HTTP method " + skipPoint.getResourceHTTPMethod());
            }
            debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_NON_EXISTING_SEQUENCE).toString());
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Failed unregister skip. Non existing sequence " + skipPoint.getSynapseSequenceType().toString() + " for API key " + skipPoint.getKey() + " resource mapping " + skipPoint.getResourceMapping() + " resource HTTP method " + skipPoint.getResourceHTTPMethod());
            }
            debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_NON_EXISTING_SEQUENCE).toString());
        }
    }
}
Also used : SynapseSequenceType(org.apache.synapse.debug.constructs.SynapseSequenceType) APIMediationFlowPoint(org.apache.synapse.debug.constructs.APIMediationFlowPoint) Resource(org.apache.synapse.rest.Resource) AbstractMediator(org.apache.synapse.mediators.AbstractMediator) Mediator(org.apache.synapse.Mediator) API(org.apache.synapse.rest.API) AbstractMediator(org.apache.synapse.mediators.AbstractMediator) APIMediationFlowPoint(org.apache.synapse.debug.constructs.APIMediationFlowPoint) SynapseMediationFlowPoint(org.apache.synapse.debug.constructs.SynapseMediationFlowPoint)

Aggregations

APIMediationFlowPoint (org.apache.synapse.debug.constructs.APIMediationFlowPoint)4 Mediator (org.apache.synapse.Mediator)2 SequenceMediationFlowPoint (org.apache.synapse.debug.constructs.SequenceMediationFlowPoint)2 SynapseMediationFlowPoint (org.apache.synapse.debug.constructs.SynapseMediationFlowPoint)2 SynapseSequenceType (org.apache.synapse.debug.constructs.SynapseSequenceType)2 AbstractMediator (org.apache.synapse.mediators.AbstractMediator)2 API (org.apache.synapse.rest.API)2 Resource (org.apache.synapse.rest.Resource)2 JSONException (org.codehaus.jettison.json.JSONException)2 JSONObject (org.codehaus.jettison.json.JSONObject)2