Search in sources :

Example 1 with MessageProcessor

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

the class MessageProcessorDeployer method updateSynapseArtifact.

@Override
public String updateSynapseArtifact(OMElement artifactConfig, String fileName, String existingArtifactName, Properties properties) {
    if (log.isDebugEnabled()) {
        log.debug("Message Processor update from file : " + fileName + " has started");
    }
    try {
        MessageProcessor mp = MessageProcessorFactory.createMessageProcessor(artifactConfig);
        if (mp == null) {
            handleSynapseArtifactDeploymentError("Message Processor update failed. The artifact " + "defined in the file: " + fileName + " is not valid");
            return null;
        }
        mp.setFileName(new File(fileName).getName());
        if (log.isDebugEnabled()) {
            log.debug("MessageProcessor: " + mp.getName() + " has been built from the file: " + fileName);
        }
        MessageProcessor existingMp = getSynapseConfiguration().getMessageProcessors().get(existingArtifactName);
        if (existingMp instanceof AbstractMessageProcessor) {
            ((AbstractMessageProcessor) existingMp).destroy(true);
        } else {
            existingMp.destroy();
        }
        // We should add the updated MessageProcessor as a new MessageProcessor
        // and remove the old one
        mp.init(getSynapseEnvironment());
        getSynapseConfiguration().removeMessageProcessor(existingArtifactName);
        log.info("MessageProcessor: " + existingArtifactName + " has been undeployed");
        getSynapseConfiguration().addMessageProcessor(mp.getName(), mp);
        log.info("MessageProcessor: " + mp.getName() + " has been updated from the file: " + fileName);
        waitForCompletion();
        return mp.getName();
    } catch (DeploymentException e) {
        handleSynapseArtifactDeploymentError("Error while updating the MessageProcessor from the " + "file: " + fileName);
    }
    return null;
}
Also used : MessageProcessor(org.apache.synapse.message.processor.MessageProcessor) AbstractMessageProcessor(org.apache.synapse.message.processor.impl.AbstractMessageProcessor) AbstractMessageProcessor(org.apache.synapse.message.processor.impl.AbstractMessageProcessor) DeploymentException(org.apache.axis2.deployment.DeploymentException) File(java.io.File)

Example 2 with MessageProcessor

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

the class MessageProcessorDeployer method deploySynapseArtifact.

@Override
public String deploySynapseArtifact(OMElement artifactConfig, String fileName, Properties properties) {
    if (log.isDebugEnabled()) {
        log.debug("Message Processor Deployment from file : " + fileName + " : Started");
    }
    try {
        MessageProcessor mp = MessageProcessorFactory.createMessageProcessor(artifactConfig);
        if (mp != null) {
            mp.setFileName((new File(fileName)).getName());
            /**
             * Set the name of the artifact container from which the message processor deployed
             */
            mp.setArtifactContainerName(customLogContent);
            if (log.isDebugEnabled()) {
                log.debug("Message Processor named '" + mp.getName() + "' has been built from the file " + fileName);
            }
            mp.init(getSynapseEnvironment());
            if (log.isDebugEnabled()) {
                log.debug("Initialized the Message Processor : " + mp.getName());
            }
            getSynapseConfiguration().addMessageProcessor(mp.getName(), mp);
            if (log.isDebugEnabled()) {
                log.debug("Message Processor Deployment from file : " + fileName + " : Completed");
            }
            log.info("Message Processor named '" + mp.getName() + "' has been deployed from file : " + fileName);
            return mp.getName();
        } else {
            handleSynapseArtifactDeploymentError("Message Processor Deployment from the file : " + fileName + " : Failed. The artifact " + "described in the file  is not a Message Processor");
        }
    } catch (Exception e) {
        handleSynapseArtifactDeploymentError("Message Processor Deployment from the file : " + fileName + " : Failed.", e);
    }
    return null;
}
Also used : MessageProcessor(org.apache.synapse.message.processor.MessageProcessor) AbstractMessageProcessor(org.apache.synapse.message.processor.impl.AbstractMessageProcessor) File(java.io.File) DeploymentException(org.apache.axis2.deployment.DeploymentException)

Example 3 with MessageProcessor

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

the class FailoverForwardingServiceTest method test.

/**
 * Testing whether the failover forwarding service is successfully storing
 * the message in the queue
 *
 * @throws Exception
 */
@Test
public void test() throws Exception {
    JmsStore jmsStore = new JmsStore();
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
    parameters.put("java.naming.provider.url", "tcp://127.0.0.1:61616");
    jmsStore.setParameters(parameters);
    jmsStore.setName("JMSStore");
    MessageProcessor messageProcessor = new FailoverScheduledMessageForwardingProcessor();
    Map<String, Object> parametersPro = new HashMap<>();
    parametersPro.put("message.target.store.name", jmsStore.getName());
    parametersPro.put("interval", "5000");
    messageProcessor.setName("FailoverProcessor");
    messageProcessor.setParameters(parametersPro);
    messageProcessor.setMessageStoreName("JMSStore");
    SynapseConfiguration synapseConfiguration = new SynapseConfiguration();
    ConfigurationContext cfgCtx = new ConfigurationContext(synapseConfiguration.getAxisConfiguration());
    SynapseEnvironment synapseEnvironment = new Axis2SynapseEnvironment(cfgCtx, synapseConfiguration);
    synapseConfiguration.addMessageStore("JMSStore", jmsStore);
    synapseConfiguration.addMessageProcessor("FailoverProcessor", messageProcessor);
    jmsStore.init(synapseEnvironment);
    FailoverForwardingService failoverForwardingService = new FailoverForwardingService(messageProcessor, synapseEnvironment, 5000, false);
    failoverForwardingService.init(synapseEnvironment);
    Axis2MessageContext axis2MessageContext = new Axis2MessageContext(new org.apache.axis2.context.MessageContext(), synapseConfiguration, synapseEnvironment);
    MessageContext messageContext = axis2MessageContext;
    SOAP11Factory factory = new SOAP11Factory();
    SOAPEnvelope envelope = factory.getDefaultEnvelope();
    OMElement element = AXIOMUtil.stringToOM("<name><value>Test</value></name>");
    envelope.getBody().addChild(element);
    messageContext.setEnvelope(envelope);
    Assert.assertEquals("Queue is not empty!", 0, broker.getAdminView().getTotalMessageCount());
    failoverForwardingService.dispatch(messageContext);
    Assert.assertEquals("Message not forwarded!", 1, broker.getAdminView().getTotalMessageCount());
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) HashMap(java.util.HashMap) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) MessageProcessor(org.apache.synapse.message.processor.MessageProcessor) OMElement(org.apache.axiom.om.OMElement) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) JmsStore(org.apache.synapse.message.store.impl.jms.JmsStore) SOAP11Factory(org.apache.axiom.soap.impl.llom.soap11.SOAP11Factory) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) Test(org.junit.Test)

Example 4 with MessageProcessor

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

the class MessageProcessorSerializerTest method testSerializeMessageProcessor2.

/**
 * test serializeMessageProcessor and assert the OMElement is created.
 */
@Test
public void testSerializeMessageProcessor2() {
    MessageProcessor messageProcessor = new SamplingProcessor();
    messageProcessor.setName("testStore");
    OMElement element = MessageProcessorSerializer.serializeMessageProcessor(null, messageProcessor);
    Assert.assertNotNull("OMElement is not returned", element);
}
Also used : MessageProcessor(org.apache.synapse.message.processor.MessageProcessor) SamplingProcessor(org.apache.synapse.message.processor.impl.sampler.SamplingProcessor) OMElement(org.apache.axiom.om.OMElement) Test(org.junit.Test)

Example 5 with MessageProcessor

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

the class MessageProcessorSerializerTest method testSerializeMessageProcessor3.

/**
 * test serializeMessageProcessor with parameters and assert the OMElement is created.
 */
@Test
public void testSerializeMessageProcessor3() {
    Map<String, Object> parameters = new HashMap<>();
    MessageProcessor messageProcessor = new ScheduledMessageForwardingProcessor();
    messageProcessor.setName("testStore");
    parameters.put("interval", "1000");
    messageProcessor.setParameters(parameters);
    messageProcessor.setDescription("testMessageProcessor");
    messageProcessor.setTargetEndpoint("target");
    messageProcessor.setMessageStoreName("testMessageStore");
    OMElement element = MessageProcessorSerializer.serializeMessageProcessor(null, messageProcessor);
    Assert.assertNotNull("OMElement is not returned", element);
}
Also used : HashMap(java.util.HashMap) MessageProcessor(org.apache.synapse.message.processor.MessageProcessor) ScheduledMessageForwardingProcessor(org.apache.synapse.message.processor.impl.forwarder.ScheduledMessageForwardingProcessor) OMElement(org.apache.axiom.om.OMElement) Test(org.junit.Test)

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