Search in sources :

Example 1 with SynapseConfiguration

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);
                }
            }
        }
    }
}
Also used : Entry(org.apache.synapse.config.Entry) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) Parameter(org.apache.axis2.description.Parameter) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) ManagedLifecycle(org.apache.synapse.ManagedLifecycle)

Example 2 with SynapseConfiguration

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);
    }
}
Also used : EventException(org.wso2.eventing.exceptions.EventException) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) ResponseMessageBuilder(org.apache.synapse.eventing.builders.ResponseMessageBuilder) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext)

Example 3 with SynapseConfiguration

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);
        }
    }
}
Also used : Entry(org.apache.synapse.config.Entry) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Example 4 with SynapseConfiguration

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());
}
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 5 with SynapseConfiguration

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);
}
Also used : HashMap(java.util.HashMap) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) 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)

Aggregations

SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)145 Axis2SynapseEnvironment (org.apache.synapse.core.axis2.Axis2SynapseEnvironment)64 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)59 MessageContext (org.apache.synapse.MessageContext)56 Test (org.junit.Test)56 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)50 SynapseEnvironment (org.apache.synapse.core.SynapseEnvironment)49 OMElement (org.apache.axiom.om.OMElement)41 Parameter (org.apache.axis2.description.Parameter)29 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)27 TestMessageContext (org.apache.synapse.TestMessageContext)16 Properties (java.util.Properties)15 SynapseException (org.apache.synapse.SynapseException)13 Mediator (org.apache.synapse.Mediator)12 AddressEndpoint (org.apache.synapse.endpoints.AddressEndpoint)11 File (java.io.File)10 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)9 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)7 Endpoint (org.apache.synapse.endpoints.Endpoint)7