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