use of org.apache.synapse.config.SynapseConfiguration in project wso2-synapse by wso2.
the class IndirectEndpoint method reLoadAndInitEndpoint.
/**
* Reload as needed , either from registry , local entries or predefined endpoints
* @param cc ConfigurationContext
*/
private synchronized void reLoadAndInitEndpoint(ConfigurationContext cc) {
Parameter parameter = cc.getAxisConfiguration().getParameter(SynapseConstants.SYNAPSE_CONFIG);
Parameter synEnvParameter = cc.getAxisConfiguration().getParameter(SynapseConstants.SYNAPSE_ENV);
if (parameter.getValue() instanceof SynapseConfiguration && synEnvParameter.getValue() instanceof SynapseEnvironment) {
SynapseConfiguration synCfg = (SynapseConfiguration) parameter.getValue();
SynapseEnvironment synapseEnvironment = (SynapseEnvironment) synEnvParameter.getValue();
boolean reLoad = (realEndpoint == null);
if (!reLoad) {
Entry entry = synCfg.getEntryDefinition(key);
if (entry != null && entry.isDynamic()) {
if (!entry.isCached() || entry.isExpired()) {
reLoad = true;
}
} else {
// If the endpoint is static we should reload it from the Synapse config
reLoad = true;
}
}
if (reLoad) {
if (log.isDebugEnabled()) {
log.debug("Loading real endpoint with key : " + key);
}
realEndpoint = synCfg.getEndpoint(key);
if (realEndpoint != null && !realEndpoint.isInitialized()) {
realEndpoint.init(synapseEnvironment);
}
} else {
Endpoint epr = synCfg.getEndpoint(key);
if (epr != realEndpoint) {
realEndpoint = epr;
if (realEndpoint != null && !realEndpoint.isInitialized() && realEndpoint instanceof ManagedLifecycle) {
realEndpoint.init(synapseEnvironment);
}
}
}
}
}
use of org.apache.synapse.config.SynapseConfiguration in project wso2-synapse by wso2.
the class SynapseEventSource method receive.
/**
* Override the Message receiver method to accept subscriptions and events
*
* @param mc message context
* @throws AxisFault
*/
public void receive(MessageContext mc) throws AxisFault {
// Create synapse message context from the axis2 message context
SynapseConfiguration synCfg = (SynapseConfiguration) mc.getConfigurationContext().getAxisConfiguration().getParameter(SynapseConstants.SYNAPSE_CONFIG).getValue();
SynapseEnvironment synEnv = (SynapseEnvironment) mc.getConfigurationContext().getAxisConfiguration().getParameter(SynapseConstants.SYNAPSE_ENV).getValue();
org.apache.synapse.MessageContext smc = new Axis2MessageContext(mc, synCfg, synEnv);
// initialize the response message builder using the message context
ResponseMessageBuilder messageBuilder = new ResponseMessageBuilder(mc);
try {
if (EventingConstants.WSE_SUBSCRIBE.equals(mc.getWSAAction())) {
// add new subscription to the SynapseSubscription store through subscription manager
processSubscriptionRequest(mc, messageBuilder);
} else if (EventingConstants.WSE_UNSUBSCRIBE.equals(mc.getWSAAction())) {
// Unsubscribe the matching subscription
processUnSubscribeRequest(mc, messageBuilder);
} else if (EventingConstants.WSE_GET_STATUS.equals(mc.getWSAAction())) {
// Response with the status of the subscription
processGetStatusRequest(mc, messageBuilder);
} else if (EventingConstants.WSE_RENEW.equals(mc.getWSAAction())) {
// Renew subscription
processReNewRequest(mc, messageBuilder);
} else {
// Treat as an Event
if (log.isDebugEnabled()) {
log.debug("Event received");
}
dispatchEvents(smc);
}
} catch (EventException e) {
handleException("Subscription manager processing error", e);
}
}
use of org.apache.synapse.config.SynapseConfiguration in project wso2-synapse by wso2.
the class TemplateEndpoint method reLoadAndInitEndpoint.
/**
* Reload as needed , either from registry , local entries or predefined endpoints
* @param se synapse environment
*/
private synchronized void reLoadAndInitEndpoint(SynapseEnvironment se) {
SynapseConfiguration synCfg = se.getSynapseConfiguration();
// used to keep track of template changes in registry
long previousEntryVersion = -1;
// always do reloading at init
boolean reLoad = (realEndpoint == null);
Entry entry = synCfg.getEntryDefinition(template);
if (!reLoad) {
if (entry != null && entry.isDynamic()) {
// get previous entry version to track template changes
previousEntryVersion = entry.getVersion();
if (!entry.isCached() || entry.isExpired()) {
MBeanRegistrar.getInstance().unRegisterMBean("Endpoint", this.getName());
reLoad = true;
}
} else {
// this endpoint is static -->
// since template-endpoint is static, should ONLY be loaded at initialization to prevent
// reloading every single time this endpoint is executed..
// incase tempalate config has changed this endpoint should be redeployed
reLoad = false;
}
}
if (reLoad) {
if (log.isDebugEnabled()) {
log.debug("Loading template endpoint with key : " + template);
}
Template eprTemplate = synCfg.getEndpointTemplate(template);
if (eprTemplate != null) {
// create real EP if not already created or if there is any change in template
if (realEndpoint == null || previousEntryVersion != entry.getVersion()) {
realEndpoint = eprTemplate.create(this, synCfg.getProperties());
}
} else {
log.warn("Couldn't retrieve the endpoint template with the key:" + template);
}
if (realEndpoint != null && !realEndpoint.isInitialized()) {
realEndpoint.init(se);
}
}
}
use of org.apache.synapse.config.SynapseConfiguration 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.config.SynapseConfiguration in project wso2-synapse by wso2.
the class JmsMessageStoreTest method testProducer.
/**
* Testing whether jms producer is storing the message to the store
* @throws Exception
*/
@Test
public void testProducer() 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("TestJmsStore");
SynapseConfiguration synapseConfiguration = new SynapseConfiguration();
synapseConfiguration.addMessageStore("JMSStore", jmsStore);
SynapseEnvironment synapseEnvironment = new Axis2SynapseEnvironment(synapseConfiguration);
Axis2MessageContext axis2MessageContext = new Axis2MessageContext(new org.apache.axis2.context.MessageContext(), synapseConfiguration, synapseEnvironment);
MessageContext messageContext = axis2MessageContext;
SOAP11Factory factory = new SOAP11Factory();
SOAPEnvelope envelope = factory.createSOAPEnvelope();
messageContext.setEnvelope(envelope);
jmsStore.init(synapseEnvironment);
JmsProducer jmsProducer = (JmsProducer) jmsStore.getProducer();
boolean response = jmsProducer.storeMessage(messageContext);
Assert.assertTrue("Message not stored!", response);
}
Aggregations