Search in sources :

Example 16 with InboundEndpoint

use of org.apache.synapse.inbound.InboundEndpoint in project wso2-synapse by wso2.

the class Axis2SynapseEnvironment method injectMessage.

public boolean injectMessage(MessageContext smc, SequenceMediator seq) {
    AspectConfiguration inboundAspectConfiguration = null;
    String inboundName = null;
    boolean isStatisticsEnabled = RuntimeStatisticCollector.isStatisticsEnabled();
    Integer statisticReportingIndex = null;
    /*
         * If the method is invoked by the inbound endpoint
         * Then check for the endpoint name and then set the Log Appender Content
         */
    if (smc.getProperty(SynapseConstants.INBOUND_ENDPOINT_NAME) != null) {
        InboundEndpoint inboundEndpoint = smc.getConfiguration().getInboundEndpoint((String) smc.getProperty(SynapseConstants.INBOUND_ENDPOINT_NAME));
        if (inboundEndpoint != null) {
            CustomLogSetter.getInstance().setLogAppender(inboundEndpoint.getArtifactContainerName());
            inboundName = (String) smc.getProperty(SynapseConstants.INBOUND_ENDPOINT_NAME);
            if (inboundEndpoint.getAspectConfiguration() != null) {
                inboundAspectConfiguration = inboundEndpoint.getAspectConfiguration();
            }
        }
    }
    if (seq == null) {
        log.error("Please provide existing sequence");
        return false;
    }
    if (log.isDebugEnabled()) {
        log.debug("Injecting MessageContext for asynchronous mediation using the : " + (seq.getName() == null ? "Anonymous" : seq.getName()) + " Sequence");
    }
    smc.setEnvironment(this);
    if (!invokeHandlers(smc)) {
        return false;
    }
    try {
        if (isStatisticsEnabled && inboundName != null) {
            statisticReportingIndex = OpenEventCollector.reportEntryEvent(smc, inboundName, inboundAspectConfiguration, ComponentType.INBOUNDENDPOINT);
        }
        seq.mediate(smc);
        return true;
    } catch (SynapseException syne) {
        if (!smc.getFaultStack().isEmpty()) {
            warn(false, "Executing fault handler due to exception encountered", smc);
            smc.getFaultStack().pop().handleFault(smc, syne);
        } else {
            warn(false, "Exception encountered but no fault handler found - " + "message dropped", smc);
        }
        return false;
    } catch (Exception e) {
        String msg = "Unexpected error executing  injecting message to sequence ," + seq;
        log.error(msg, e);
        if (smc.getServiceLog() != null) {
            smc.getServiceLog().error(msg, e);
        }
        if (!smc.getFaultStack().isEmpty()) {
            warn(false, "Executing fault handler due to exception encountered", smc);
            smc.getFaultStack().pop().handleFault(smc, e);
        } else {
            warn(false, "Exception encountered but no fault handler found - " + "message dropped", smc);
        }
        return false;
    } catch (Throwable e) {
        String msg = "Unexpected error executing  injecting message to sequence ," + seq + " message dropped";
        log.error(msg, e);
        if (smc.getServiceLog() != null) {
            smc.getServiceLog().error(msg, e);
        }
        return false;
    } finally {
        if (isStatisticsEnabled && inboundName != null) {
            CloseEventCollector.tryEndFlow(smc, inboundName, ComponentType.INBOUNDENDPOINT, statisticReportingIndex, false);
        }
    }
}
Also used : InboundEndpoint(org.apache.synapse.inbound.InboundEndpoint) SynapseException(org.apache.synapse.SynapseException) AspectConfiguration(org.apache.synapse.aspects.AspectConfiguration) SynapseException(org.apache.synapse.SynapseException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 17 with InboundEndpoint

use of org.apache.synapse.inbound.InboundEndpoint in project wso2-synapse by wso2.

the class InboundEndpointDeployer method updateSynapseArtifact.

@Override
public String updateSynapseArtifact(OMElement artifactConfig, String fileName, String existingArtifactName, Properties properties) {
    if (log.isDebugEnabled()) {
        log.debug("Inbound Endpoint update from file : " + fileName + " has started");
    }
    try {
        /*properties are ignored*/
        InboundEndpoint inboundEndpoint = InboundEndpointFactory.createInboundEndpoint(artifactConfig, getSynapseConfiguration());
        if (inboundEndpoint == null) {
            handleSynapseArtifactDeploymentError("Inbound Endpoint update failed. The artifact " + "defined in the file: " + fileName + " is not a valid Inbound Endpoint.");
            return null;
        }
        CustomLogSetter.getInstance().setLogAppender(inboundEndpoint.getArtifactContainerName());
        inboundEndpoint.setFileName(new File(fileName).getName());
        inboundEndpoint.setArtifactContainerName(customLogContent);
        if (log.isDebugEnabled()) {
            log.debug("Inbound Endpoint: " + inboundEndpoint.getName() + " has been built from the file: " + fileName);
        }
        InboundEndpoint existingInboundEndpoint = getSynapseConfiguration().getInboundEndpoint(existingArtifactName);
        existingInboundEndpoint.destroy();
        inboundEndpoint.init(getSynapseEnvironment());
        if (existingArtifactName.equals(inboundEndpoint.getName())) {
            getSynapseConfiguration().updateInboundEndpoint(existingArtifactName, inboundEndpoint);
        } else {
            // The user has changed the name of the Inbound Endpoint
            // We should add the updated Inbound Endpoint as a new Inbound Endpoint and remove the old one
            getSynapseConfiguration().addInboundEndpoint(inboundEndpoint.getName(), inboundEndpoint);
            getSynapseConfiguration().removeInboundEndpoint(existingArtifactName);
            log.info("Inbound Endpoint: " + existingArtifactName + " has been undeployed");
        }
        log.info("Inbound Endpoint: " + inboundEndpoint.getName() + " has been updated from the file: " + fileName);
        waitForCompletion();
        return inboundEndpoint.getName();
    } catch (DeploymentException e) {
        handleSynapseArtifactDeploymentError("Error while updating the Inbound Endpoint from the " + "file: " + fileName);
    }
    return null;
}
Also used : InboundEndpoint(org.apache.synapse.inbound.InboundEndpoint) DeploymentException(org.apache.axis2.deployment.DeploymentException) File(java.io.File)

Example 18 with InboundEndpoint

use of org.apache.synapse.inbound.InboundEndpoint in project wso2-synapse by wso2.

the class InboundEndpointDeployer method undeploySynapseArtifact.

public void undeploySynapseArtifact(String artifactName) {
    if (log.isDebugEnabled()) {
        log.debug("Undeployment of the Inbound Endpoint named : " + artifactName + " : Started");
    }
    try {
        InboundEndpoint inboundEndpoint = getSynapseConfiguration().getInboundEndpoint(artifactName);
        if (inboundEndpoint != null) {
            CustomLogSetter.getInstance().setLogAppender(inboundEndpoint.getArtifactContainerName());
            inboundEndpoint.destroy();
            getSynapseConfiguration().removeInboundEndpoint(artifactName);
            if (log.isDebugEnabled()) {
                log.debug("Undeployment of the Inbound Endpoint named : " + artifactName + " : Completed");
            }
            log.info("Inbound Endpoint named '" + inboundEndpoint.getName() + "' has been undeployed");
        } else if (log.isDebugEnabled()) {
            log.debug("Inbound Endpoint " + artifactName + " has already been undeployed");
        }
    } catch (Exception e) {
        handleSynapseArtifactDeploymentError("Undeployment of Inbound Endpoint named : " + artifactName + " : Failed", e);
    }
}
Also used : InboundEndpoint(org.apache.synapse.inbound.InboundEndpoint) DeploymentException(org.apache.axis2.deployment.DeploymentException)

Example 19 with InboundEndpoint

use of org.apache.synapse.inbound.InboundEndpoint in project wso2-synapse by wso2.

the class InboundEndpointDebugUtil method registerInboundSequenceMediationFlowSkip.

/**
 * Registers/Un-registers a skip, point where mediator disables from mediation flow
 *
 * @param synCfg Synapse configuration
 * @param seqType Synapse sequence type
 * @param inboundKey name of the Inbound Endpoint
 * @param position array of integers that uniquely specifies a point in mediation route
 * @param registerMode specify whether register or un register
 */
public static void registerInboundSequenceMediationFlowSkip(SynapseConfiguration synCfg, String seqType, String inboundKey, int[] position, boolean registerMode) {
    SynapseSequenceType synapseSequenceType = SynapseSequenceType.valueOf(seqType.toUpperCase());
    SequenceMediationFlowPoint skipPoint = new SequenceMediationFlowPoint();
    skipPoint.setSynapseMediationComponent(SynapseMediationComponent.SEQUENCE);
    skipPoint.setKey(inboundKey);
    skipPoint.setMediatorPosition(position);
    skipPoint.setSequenceBaseType(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE_INBOUND);
    skipPoint.setSynapseSequenceType(synapseSequenceType);
    Mediator seqMediator = null;
    InboundEndpoint inbound = null;
    inbound = synCfg.getInboundEndpoint(inboundKey);
    if (inbound != null) {
        if (synapseSequenceType.equals(SynapseSequenceType.INBOUND_SEQ)) {
            seqMediator = synCfg.getSequence(inbound.getInjectingSeq());
        } else if (synapseSequenceType.equals(SynapseSequenceType.INBOUND_FAULTSEQ)) {
            seqMediator = synCfg.getSequence(inbound.getOnErrorSeq());
        }
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Non existing Inbound Endpoint for key " + skipPoint.getKey());
        }
        debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_INBOUND_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 Inbound Endpoint key " + skipPoint.getKey() + " sequence " + 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 Inbound Endpoint key " + skipPoint.getKey() + " sequence " + 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 Inbound Endpoint key " + skipPoint.getKey() + " sequence " + 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 Inbound Endpoint key " + skipPoint.getKey() + " sequence " + 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 Inbound Endpoint key " + skipPoint.getKey() + " sequence " + 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 Inbound Endpoint key " + skipPoint.getKey() + " sequence " + 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 Inbound Endpoint key " + skipPoint.getKey());
            }
            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 Inbound Endpoint key " + skipPoint.getKey());
            }
            debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_NON_EXISTING_SEQUENCE).toString());
        }
    }
}
Also used : SequenceMediationFlowPoint(org.apache.synapse.debug.constructs.SequenceMediationFlowPoint) InboundEndpoint(org.apache.synapse.inbound.InboundEndpoint) SynapseSequenceType(org.apache.synapse.debug.constructs.SynapseSequenceType) AbstractMediator(org.apache.synapse.mediators.AbstractMediator) Mediator(org.apache.synapse.Mediator) AbstractMediator(org.apache.synapse.mediators.AbstractMediator)

Example 20 with InboundEndpoint

use of org.apache.synapse.inbound.InboundEndpoint in project wso2-synapse by wso2.

the class SynapseConfiguration method init.

/**
 * This method will be called in the startup of Synapse or in an initiation
 * and will initialize all the managed parts of the Synapse Configuration
 *
 * @param se SynapseEnvironment specifying the env to be initialized
 */
public synchronized void init(SynapseEnvironment se) {
    SynapseConfiguration previouseConfiguration = null;
    if (log.isDebugEnabled()) {
        log.debug("Initializing the Synapse Configuration using the SynapseEnvironment");
    }
    // initialize registry
    if (registry != null && registry instanceof ManagedLifecycle) {
        ((ManagedLifecycle) registry).init(se);
    }
    // we initialize xpath extensions here since synapse environment is available
    initXpathExtensions(se);
    initCarbonTenantConfigurator(se);
    // initialize endpoints
    for (Endpoint endpoint : getDefinedEndpoints().values()) {
        try {
            endpoint.init(se);
        } catch (Exception e) {
            log.error(" Error in initializing endpoint [" + endpoint.getName() + "] " + e.getMessage());
        }
    }
    // initialize sequence templates
    for (TemplateMediator seqTemplate : getSequenceTemplates().values()) {
        try {
            seqTemplate.init(se);
        } catch (Exception e) {
            log.error(" Error in initializing Sequence Template [" + seqTemplate.getName() + "] " + e.getMessage());
        }
    }
    String tenantDomain = getTenantDomain(se);
    if (tenantDomain != null) {
        previouseConfiguration = SynapseConfigUtils.getSynapseConfiguration(tenantDomain);
        SynapseConfigUtils.addSynapseConfiguration(tenantDomain, this);
    }
    if (previouseConfiguration != null) {
        destroyExistingInbounds(previouseConfiguration);
    }
    for (InboundEndpoint endpoint : getInboundEndpoints()) {
        try {
            endpoint.init(se);
        } catch (Exception e) {
            inboundEndpointMap.remove(endpoint.getName());
            log.error(" Error in initializing inbound endpoint [" + endpoint.getName() + "] " + e.getMessage());
        }
    }
    // initialize managed mediators
    for (ManagedLifecycle seq : getDefinedSequences().values()) {
        if (seq != null) {
            try {
                seq.init(se);
            } catch (Exception e) {
                log.error(" Error in initializing Sequence " + e.getMessage());
            }
        }
    }
    // initialize all the proxy services
    for (ProxyService proxy : getProxyServices()) {
        try {
            if (proxy.getTargetInLineEndpoint() != null) {
                proxy.getTargetInLineEndpoint().init(se);
            }
            if (proxy.getTargetInLineInSequence() != null) {
                proxy.getTargetInLineInSequence().init(se);
            }
            if (proxy.getTargetInLineOutSequence() != null) {
                proxy.getTargetInLineOutSequence().init(se);
            }
            if (proxy.getTargetInLineFaultSequence() != null) {
                proxy.getTargetInLineFaultSequence().init(se);
            }
        } catch (Exception e) {
            log.error(" Error in initializing Proxy Service [ " + proxy.getName() + "] " + e.getMessage());
        }
    }
    // initialize the startups
    for (ManagedLifecycle stp : getStartups()) {
        if (stp != null) {
            try {
                stp.init(se);
            } catch (Exception e) {
                log.error(" Error in initializing Stratups " + e.getMessage());
            }
        }
    }
    // initialize sequence executors
    for (PriorityExecutor executor : getPriorityExecutors().values()) {
        try {
            executor.init();
        } catch (Exception e) {
            log.error(" Error in initializing Executor [ " + executor.getName() + "] " + e.getMessage());
        }
    }
    // initialize message stores
    for (MessageStore messageStore : messageStores.values()) {
        try {
            messageStore.init(se);
        } catch (Exception e) {
            log.error(" Error in initializing Message Store [ " + messageStore.getName() + "] " + e.getMessage());
        }
    }
    // initialize message processors
    for (MessageProcessor messageProcessor : messageProcessors.values()) {
        try {
            messageProcessor.init(se);
        } catch (Exception e) {
            log.error(" Error in initializing Message Processor [ " + messageProcessor.getName() + "] " + e.getMessage());
        }
    }
    for (API api : apiTable.values()) {
        try {
            api.init(se);
        } catch (Exception e) {
            log.error(" Error in initializing API [ " + api.getName() + "] " + e.getMessage());
        }
    }
    initImportedLibraries(se);
}
Also used : InboundEndpoint(org.apache.synapse.inbound.InboundEndpoint) MessageStore(org.apache.synapse.message.store.MessageStore) InboundEndpoint(org.apache.synapse.inbound.InboundEndpoint) Endpoint(org.apache.synapse.endpoints.Endpoint) TemplateMediator(org.apache.synapse.mediators.template.TemplateMediator) ProxyService(org.apache.synapse.core.axis2.ProxyService) AbstractMessageProcessor(org.apache.synapse.message.processor.impl.AbstractMessageProcessor) MessageProcessor(org.apache.synapse.message.processor.MessageProcessor) API(org.apache.synapse.rest.API) PriorityExecutor(org.apache.synapse.commons.executors.PriorityExecutor) ManagedLifecycle(org.apache.synapse.ManagedLifecycle) SynapseException(org.apache.synapse.SynapseException) IOException(java.io.IOException)

Aggregations

InboundEndpoint (org.apache.synapse.inbound.InboundEndpoint)21 SynapseException (org.apache.synapse.SynapseException)6 SequenceMediator (org.apache.synapse.mediators.base.SequenceMediator)6 OMElement (org.apache.axiom.om.OMElement)5 DeploymentException (org.apache.axis2.deployment.DeploymentException)4 ProxyService (org.apache.synapse.core.axis2.ProxyService)4 TestMediator (org.apache.synapse.mediators.TestMediator)4 TemplateMediator (org.apache.synapse.mediators.template.TemplateMediator)4 AspectConfiguration (org.apache.synapse.aspects.AspectConfiguration)3 PriorityExecutor (org.apache.synapse.commons.executors.PriorityExecutor)3 Endpoint (org.apache.synapse.endpoints.Endpoint)3 MessageProcessor (org.apache.synapse.message.processor.MessageProcessor)3 MessageStore (org.apache.synapse.message.store.MessageStore)3 API (org.apache.synapse.rest.API)3 File (java.io.File)2 Iterator (java.util.Iterator)2 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)2 ManagedLifecycle (org.apache.synapse.ManagedLifecycle)2 Mediator (org.apache.synapse.Mediator)2 Entry (org.apache.synapse.config.Entry)2