use of org.apache.synapse.message.store.impl.jms.JmsStore in project wso2-synapse by wso2.
the class MessageStoreMediator method mediate.
public boolean mediate(MessageContext synCtx) {
boolean produceStatus;
if (synCtx.getEnvironment().isDebuggerEnabled()) {
if (super.divertMediationRoute(synCtx)) {
return true;
}
}
if (synCtx != null) {
MessageStore messageStore;
if (messageStoreExp != null) {
messageStore = synCtx.getConfiguration().getMessageStore(messageStoreExp.stringValueOf(synCtx));
} else {
messageStore = synCtx.getConfiguration().getMessageStore(messageStoreName);
}
if (messageStore != null) {
if (messageStore.getParameters().get(PRODUCER_GUARANTEED_DELIVERY) != null) {
isGuaranteedDeliveryEnabled = Boolean.parseBoolean(messageStore.getParameters().get(PRODUCER_GUARANTEED_DELIVERY).toString());
}
if (messageStore.getParameters().get(FAILOVER_MESSAGE_STORE_NAME) != null) {
failoverMessageStoreName = (String) messageStore.getParameters().get(FAILOVER_MESSAGE_STORE_NAME);
}
if (onStoreSequence != null) {
Mediator sequence = synCtx.getSequence(onStoreSequence);
if (sequence != null) {
sequence.mediate(synCtx);
}
}
if (log.isDebugEnabled()) {
log.debug("Message Store mediator storing the message : \n " + synCtx.getEnvelope());
}
// Ensure that the message is fully read
synCtx.getEnvelope().buildWithAttachments();
// Clone the message before sending to the producer
// Fix ESBJAVA-3650
MessageContext newCtx = null;
try {
newCtx = MessageHelper.cloneMessageContext(synCtx);
ContinuationStackManager.clearStack(newCtx);
} catch (AxisFault af) {
handleException("Error when cloning the message context", af, synCtx);
}
synchronized (storeMessageLock) {
produceStatus = messageStore.getProducer().storeMessage(newCtx);
}
if (!produceStatus) {
// Fix ESBJAVA-5011, since connection is already null need to nullify producer also
if (messageStore instanceof JmsStore) {
((JmsStore) messageStore).setProducer(null);
}
if (isGuaranteedDeliveryEnabled && failoverMessageStoreName != null && !failoverMessageStoreName.isEmpty()) {
MessageStore failoverMessageStore = synCtx.getConfiguration().getMessageStore(failoverMessageStoreName);
boolean failoverProduceStatus = failoverMessageStore.getProducer().storeMessage(newCtx);
if (!failoverProduceStatus) {
synCtx.setProperty(NhttpConstants.HTTP_SC, 500);
synCtx.setProperty(NhttpConstants.ERROR_DETAIL, "Failed to store message.");
synCtx.setProperty(NhttpConstants.ERROR_MESSAGE, "Failed to store message [" + synCtx.getMessageID() + "] in store [" + messageStore.getName() + "].");
handleException("Failed to store message [" + synCtx.getMessageID() + "] in failover store [" + failoverMessageStoreName + "].", synCtx);
}
if (shouldTrace(synCtx)) {
trace.error("Message [" + synCtx.getMessageID() + "] store in the failover message store [" + failoverMessageStoreName + "]");
}
} else {
synCtx.setProperty(NhttpConstants.HTTP_SC, 500);
synCtx.setProperty(NhttpConstants.ERROR_DETAIL, "Failed to store message.");
synCtx.setProperty(NhttpConstants.ERROR_MESSAGE, "Failed to store message [" + synCtx.getMessageID() + "] in store [" + messageStore.getName() + "].");
handleException("Failed to store message [" + synCtx.getMessageID() + "] in store [" + messageStore.getName() + "].", synCtx);
}
}
// with the nio transport, this causes the listener not to write a 202
// Accepted response, as this implies that Synapse does not yet know if
// a 202 or 200 response would be written back.
Axis2MessageContext msgCtx = (Axis2MessageContext) synCtx;
if (null != msgCtx.getAxis2MessageContext() && null != msgCtx.getAxis2MessageContext().getOperationContext()) {
msgCtx.getAxis2MessageContext().getOperationContext().setProperty(org.apache.axis2.Constants.RESPONSE_WRITTEN, "SKIP");
}
return true;
} else {
handleException("Message Store does not exist.", synCtx);
}
}
return false;
}
use of org.apache.synapse.message.store.impl.jms.JmsStore 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.store.impl.jms.JmsStore in project wso2-synapse by wso2.
the class SynapseXMLConfigurationSerializerTest method testSerializeConfiguration9.
/**
* Test serializeConfigurationMethod with messageStore added for SynapseConfiguration and assert OMElement returned
*/
@Test
public void testSerializeConfiguration9() {
SynapseXMLConfigurationSerializer serializer = new SynapseXMLConfigurationSerializer();
SynapseConfiguration synapseConfiguration = new SynapseConfiguration();
MessageStore messageStore = 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");
messageStore.setName("testMessageStore");
messageStore.setParameters(parameters);
synapseConfiguration.addMessageStore(messageStore.getName(), messageStore);
OMElement element = serializer.serializeConfiguration(synapseConfiguration);
Assert.assertNotNull("OMElement is not returned", element);
Assert.assertEquals("definitions", element.getLocalName());
Assert.assertTrue("MessageStore added is not serialized.", element.getChildren().next().toString().contains("name=\"testMessageStore\""));
}
Aggregations