Search in sources :

Example 11 with MessageProcessor

use of org.apache.synapse.message.processor.MessageProcessor in project wso2-synapse by wso2.

the class MultiXMLConfigurationBuilder method createMessageProcessors.

private static void createMessageProcessors(SynapseConfiguration synapseConfig, String rootDirPath, Properties properties) {
    File messageProcessorDir = new File(rootDirPath, MESSAGE_PROCESSOR_DIR);
    if (messageProcessorDir.exists()) {
        if (log.isDebugEnabled()) {
            log.debug("Loading Message Processors from :" + messageProcessorDir.getPath());
        }
        Iterator messageProcessors = FileUtils.iterateFiles(messageProcessorDir, extensions, false);
        while (messageProcessors.hasNext()) {
            File file = (File) messageProcessors.next();
            try {
                OMElement document = getOMElement(file);
                MessageProcessor messageProcessor = SynapseXMLConfigurationFactory.defineMessageProcessor(synapseConfig, document, properties);
                if (messageProcessor != null) {
                    messageProcessor.setFileName(file.getName());
                    synapseConfig.getArtifactDeploymentStore().addArtifact(file.getAbsolutePath(), messageProcessor.getName());
                }
            } catch (Exception e) {
                String msg = "Message processor configuration cannot be built from : " + file.getName();
                handleConfigurationError(SynapseConstants.FAIL_SAFE_MODE_MESSAGE_PROCESSORS, msg, e);
            }
        }
    }
}
Also used : MessageProcessor(org.apache.synapse.message.processor.MessageProcessor) Iterator(java.util.Iterator) OMElement(org.apache.axiom.om.OMElement) XMLStreamException(javax.xml.stream.XMLStreamException) SynapseException(org.apache.synapse.SynapseException)

Example 12 with MessageProcessor

use of org.apache.synapse.message.processor.MessageProcessor in project wso2-synapse by wso2.

the class MessageProcessorDeployer method restoreSynapseArtifact.

@Override
public void restoreSynapseArtifact(String artifactName) {
    if (log.isDebugEnabled()) {
        log.debug("Restoring the MessageProcessor with name : " + artifactName + " : Started");
    }
    try {
        MessageProcessor mp = getSynapseConfiguration().getMessageProcessors().get(artifactName);
        OMElement msElem = MessageProcessorSerializer.serializeMessageProcessor(null, mp);
        if (mp.getFileName() != null) {
            String fileName = getServerConfigurationInformation().getSynapseXMLLocation() + File.separator + MultiXMLConfigurationBuilder.MESSAGE_PROCESSOR_DIR + File.separator + mp.getFileName();
            writeToFile(msElem, fileName);
            if (log.isDebugEnabled()) {
                log.debug("Restoring the MessageProcessor with name : " + artifactName + " : Completed");
            }
            log.info("MessageProcessor named '" + artifactName + "' has been restored");
        } else {
            handleSynapseArtifactDeploymentError("Couldn't restore the MessageProcessor named '" + artifactName + "', filename cannot be found");
        }
    } catch (Exception e) {
        handleSynapseArtifactDeploymentError("Restoring of the MessageProcessor named '" + artifactName + "' has failed", e);
    }
}
Also used : MessageProcessor(org.apache.synapse.message.processor.MessageProcessor) AbstractMessageProcessor(org.apache.synapse.message.processor.impl.AbstractMessageProcessor) OMElement(org.apache.axiom.om.OMElement) DeploymentException(org.apache.axis2.deployment.DeploymentException)

Example 13 with MessageProcessor

use of org.apache.synapse.message.processor.MessageProcessor in project wso2-synapse by wso2.

the class MessageProcessorDeployer method undeploySynapseArtifact.

@Override
public void undeploySynapseArtifact(String artifactName) {
    if (log.isDebugEnabled()) {
        log.debug("MessageProcessor Undeployment of the MessageProcessor named : " + artifactName + " : Started");
    }
    try {
        MessageProcessor mp = getSynapseConfiguration().getMessageProcessors().get(artifactName);
        if (mp != null) {
            mp.destroy();
            getSynapseConfiguration().removeMessageProcessor(artifactName);
            if (log.isDebugEnabled()) {
                log.debug("Destroying the MessageProcessor named : " + artifactName);
            }
            if (log.isDebugEnabled()) {
                log.debug("MessageProcessor Undeployment of the endpoint named : " + artifactName + " : Completed");
            }
            log.info("MessageProcessor named '" + mp.getName() + "' has been undeployed");
        } else if (log.isDebugEnabled()) {
            log.debug("MessageProcessor " + artifactName + " has already been undeployed");
        }
    } catch (Exception e) {
        handleSynapseArtifactDeploymentError("MessageProcessor Undeployement of MessageProcessor named : " + artifactName + " : Failed", e);
    }
}
Also used : MessageProcessor(org.apache.synapse.message.processor.MessageProcessor) AbstractMessageProcessor(org.apache.synapse.message.processor.impl.AbstractMessageProcessor) DeploymentException(org.apache.axis2.deployment.DeploymentException)

Example 14 with MessageProcessor

use of org.apache.synapse.message.processor.MessageProcessor 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)

Example 15 with MessageProcessor

use of org.apache.synapse.message.processor.MessageProcessor in project wso2-synapse by wso2.

the class SynapseConfiguration method destroy.

public synchronized void destroy(boolean preserverState) {
    if (log.isDebugEnabled()) {
        log.debug("Destroying the Synapse Configuration");
    }
    // clear the timer tasks of Synapse
    synapseTimer.cancel();
    synapseTimer = null;
    // stop and shutdown all the proxy services
    for (ProxyService p : getProxyServices()) {
        if (p.getTargetInLineInSequence() != null) {
            p.getTargetInLineInSequence().destroy();
        }
        if (p.getTargetInLineOutSequence() != null) {
            p.getTargetInLineOutSequence().destroy();
        }
    }
    // destroy the managed mediators
    for (ManagedLifecycle seq : getDefinedSequences().values()) {
        seq.destroy();
    }
    // destroy sequence templates
    for (TemplateMediator seqTemplate : getSequenceTemplates().values()) {
        seqTemplate.destroy();
    }
    // destroy inbound endpoint
    for (InboundEndpoint endpoint : getInboundEndpoints()) {
        // This path trigger from server shutdown hook. So we don't want to remove scheduled inbound tasks
        // from registry. Only un-deployment should remove task from registry. Ref product-ei#1206
        endpoint.destroy(false);
    }
    // destroy the managed endpoints
    for (Endpoint endpoint : getDefinedEndpoints().values()) {
        endpoint.destroy();
    }
    // destroy the startups
    for (ManagedLifecycle stp : startups.values()) {
        stp.destroy();
    }
    // clear session information used for SA load balancing
    try {
        SALSessions.getInstance().reset();
        DataSourceRepositoryHolder.getInstance().getDataSourceRepositoryManager().clear();
    } catch (Throwable ignored) {
    }
    // destroy the priority executors.
    for (PriorityExecutor pe : executors.values()) {
        pe.destroy();
    }
    // destroy the Message Stores
    for (MessageStore ms : messageStores.values()) {
        if (ms instanceof AbstractMessageProcessor) {
            ((AbstractMessageProcessor) ms).destroy(preserverState);
        } else {
            ms.destroy();
        }
    }
    // destroy the Message processors
    for (MessageProcessor mp : messageProcessors.values()) {
        mp.destroy();
    }
    for (API api : apiTable.values()) {
        api.destroy();
    }
}
Also used : InboundEndpoint(org.apache.synapse.inbound.InboundEndpoint) MessageStore(org.apache.synapse.message.store.MessageStore) TemplateMediator(org.apache.synapse.mediators.template.TemplateMediator) InboundEndpoint(org.apache.synapse.inbound.InboundEndpoint) Endpoint(org.apache.synapse.endpoints.Endpoint) ProxyService(org.apache.synapse.core.axis2.ProxyService) AbstractMessageProcessor(org.apache.synapse.message.processor.impl.AbstractMessageProcessor) MessageProcessor(org.apache.synapse.message.processor.MessageProcessor) AbstractMessageProcessor(org.apache.synapse.message.processor.impl.AbstractMessageProcessor) API(org.apache.synapse.rest.API) PriorityExecutor(org.apache.synapse.commons.executors.PriorityExecutor) ManagedLifecycle(org.apache.synapse.ManagedLifecycle)

Aggregations

MessageProcessor (org.apache.synapse.message.processor.MessageProcessor)15 OMElement (org.apache.axiom.om.OMElement)8 AbstractMessageProcessor (org.apache.synapse.message.processor.impl.AbstractMessageProcessor)6 Test (org.junit.Test)5 DeploymentException (org.apache.axis2.deployment.DeploymentException)4 SynapseException (org.apache.synapse.SynapseException)4 PriorityExecutor (org.apache.synapse.commons.executors.PriorityExecutor)3 ProxyService (org.apache.synapse.core.axis2.ProxyService)3 InboundEndpoint (org.apache.synapse.inbound.InboundEndpoint)3 TemplateMediator (org.apache.synapse.mediators.template.TemplateMediator)3 MessageStore (org.apache.synapse.message.store.MessageStore)3 API (org.apache.synapse.rest.API)3 File (java.io.File)2 HashMap (java.util.HashMap)2 ManagedLifecycle (org.apache.synapse.ManagedLifecycle)2 Endpoint (org.apache.synapse.endpoints.Endpoint)2 ScheduledMessageForwardingProcessor (org.apache.synapse.message.processor.impl.forwarder.ScheduledMessageForwardingProcessor)2 SamplingProcessor (org.apache.synapse.message.processor.impl.sampler.SamplingProcessor)2 IOException (java.io.IOException)1 Collection (java.util.Collection)1