Search in sources :

Example 6 with SynapseEnvironment

use of org.apache.synapse.core.SynapseEnvironment 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 7 with SynapseEnvironment

use of org.apache.synapse.core.SynapseEnvironment 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)

Example 8 with SynapseEnvironment

use of org.apache.synapse.core.SynapseEnvironment in project wso2-synapse by wso2.

the class ProxyServiceTest method testRegisterFaultHandler.

/**
 * Tests if the correct fault handler is set when a fault handler is not explicitly set, and when set by using
 * targetFaultSequence and targetInlineFaultSequence properties of the proxy.
 */
public void testRegisterFaultHandler() {
    ProxyService proxyService = new ProxyService("TestRegisterFaultHandlerProxy");
    MessageContext messageContext = new TestMessageContext();
    SynapseConfiguration synCfg = new SynapseConfiguration();
    messageContext.setConfiguration(synCfg);
    SequenceMediator faultMediator = new SequenceMediator();
    synCfg.addSequence("fault", faultMediator);
    // test if the default fault proxy set in the message context is returned when a fault sequence is not
    // explicitly set
    faultMediator.setName("defaultFault");
    proxyService.registerFaultHandler(messageContext);
    String faultMediatorName = ((SequenceMediator) ((MediatorFaultHandler) messageContext.getFaultStack().pop()).getFaultMediator()).getName();
    Assert.assertEquals("Incorrect fault handler set: " + faultMediatorName, "defaultFault", faultMediatorName);
    // tests the functionality when the fault sequence is set in line in the target
    faultMediator.setName("targetInLineFaultSequenceMediator");
    proxyService.setTargetInLineFaultSequence(faultMediator);
    proxyService.registerFaultHandler(messageContext);
    faultMediatorName = ((SequenceMediator) ((MediatorFaultHandler) messageContext.getFaultStack().pop()).getFaultMediator()).getName();
    Assert.assertEquals("Incorrect fault handler set: " + faultMediatorName, "targetInLineFaultSequenceMediator", faultMediatorName);
    // tests the functionality when the fault sequence is set separately in the target
    AxisConfiguration axisCfg = new AxisConfiguration();
    SynapseEnvironment synEnv = new Axis2SynapseEnvironment(new ConfigurationContext(axisCfg), synCfg);
    messageContext.setEnvironment(synEnv);
    proxyService.setTargetFaultSequence("targetFaultSequence");
    // when the message context does not have the correct fault sequence specified as the target fault sequence
    faultMediator.setName("defaultFaultMediator");
    proxyService.registerFaultHandler(messageContext);
    faultMediatorName = ((SequenceMediator) ((MediatorFaultHandler) messageContext.getFaultStack().pop()).getFaultMediator()).getName();
    Assert.assertEquals("Incorrect fault handler set: " + faultMediatorName, "defaultFaultMediator", faultMediatorName);
    // when the message context has the correct fault sequence specified as the target fault sequence
    faultMediator.setName("targetFaultSequenceMediator");
    synCfg.addSequence("targetFaultSequence", faultMediator);
    proxyService.registerFaultHandler(messageContext);
    faultMediatorName = ((SequenceMediator) ((MediatorFaultHandler) messageContext.getFaultStack().pop()).getFaultMediator()).getName();
    Assert.assertEquals("Incorrect fault handler set: " + faultMediatorName, "targetFaultSequenceMediator", faultMediatorName);
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) MediatorFaultHandler(org.apache.synapse.mediators.MediatorFaultHandler) TestMessageContext(org.apache.synapse.TestMessageContext) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) MessageContext(org.apache.synapse.MessageContext) TestMessageContext(org.apache.synapse.TestMessageContext) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Example 9 with SynapseEnvironment

use of org.apache.synapse.core.SynapseEnvironment in project wso2-synapse by wso2.

the class APIDeployerTest method testUpdate.

/**
 * Test updating an API
 *
 * @throws Exception
 */
@Test
public void testUpdate() throws Exception {
    String inputXML = "<api name=\"TestAPI\" context=\"/order\" xmlns=\"http://ws.apache.org/ns/synapse\">" + "<resource url-mapping=\"/list\" inSequence=\"seq1\" outSequence=\"seq2\" xmlns=\"http://ws.apache.org/ns/synapse\"/>" + "</api>";
    OMElement inputElement = AXIOMUtil.stringToOM(inputXML);
    APIDeployer apiDeployer = new APIDeployer();
    SynapseConfiguration synapseConfiguration = new SynapseConfiguration();
    AxisConfiguration axisConfiguration = synapseConfiguration.getAxisConfiguration();
    ConfigurationContext cfgCtx = new ConfigurationContext(axisConfiguration);
    SynapseEnvironment synapseEnvironment = new Axis2SynapseEnvironment(cfgCtx, synapseConfiguration);
    axisConfiguration.addParameter(new Parameter(SynapseConstants.SYNAPSE_ENV, synapseEnvironment));
    axisConfiguration.addParameter(new Parameter(SynapseConstants.SYNAPSE_CONFIG, synapseConfiguration));
    cfgCtx.setAxisConfiguration(axisConfiguration);
    apiDeployer.init(cfgCtx);
    apiDeployer.deploySynapseArtifact(inputElement, "sampleFile", null);
    String inputUpdatedXML = "<api name=\"TestAPIUpdated\" context=\"/orderUpdated\" xmlns=\"http://ws.apache.org/ns/synapse\">" + "<resource url-mapping=\"/list\" inSequence=\"seq1\" outSequence=\"seq2\" xmlns=\"http://ws.apache.org/ns/synapse\"/>" + "</api>";
    OMElement inputUpdatedElement = AXIOMUtil.stringToOM(inputUpdatedXML);
    String response = apiDeployer.updateSynapseArtifact(inputUpdatedElement, "sampleUpdatedFile", "TestAPI", null);
    Assert.assertEquals("API not updated!", "TestAPIUpdated", response);
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) Parameter(org.apache.axis2.description.Parameter) OMElement(org.apache.axiom.om.OMElement) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) Test(org.junit.Test)

Example 10 with SynapseEnvironment

use of org.apache.synapse.core.SynapseEnvironment in project wso2-synapse by wso2.

the class EndpointDeployerTest method testDeploy.

/**
 * Testing the deployment of an endpoint
 *
 * @throws Exception
 */
@Test
public void testDeploy() throws Exception {
    String inputXML = "<endpoint name = \"sampleEP\" xmlns=\"http://ws.apache.org/ns/synapse\">" + "<address uri=\"http://localhost:9000/services/SimpleStockQuoteService\" >" + "</address>" + "</endpoint>";
    OMElement inputElement = AXIOMUtil.stringToOM(inputXML);
    EndpointDeployer endpointDeployer = new EndpointDeployer();
    SynapseConfiguration synapseConfiguration = new SynapseConfiguration();
    AxisConfiguration axisConfiguration = synapseConfiguration.getAxisConfiguration();
    ConfigurationContext cfgCtx = new ConfigurationContext(axisConfiguration);
    SynapseEnvironment synapseEnvironment = new Axis2SynapseEnvironment(cfgCtx, synapseConfiguration);
    axisConfiguration.addParameter(new Parameter(SynapseConstants.SYNAPSE_ENV, synapseEnvironment));
    axisConfiguration.addParameter(new Parameter(SynapseConstants.SYNAPSE_CONFIG, synapseConfiguration));
    cfgCtx.setAxisConfiguration(axisConfiguration);
    endpointDeployer.init(cfgCtx);
    String response = endpointDeployer.deploySynapseArtifact(inputElement, "sampleFile", null);
    Assert.assertEquals("Endpoint not deployed!", "sampleEP", response);
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) Parameter(org.apache.axis2.description.Parameter) OMElement(org.apache.axiom.om.OMElement) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) Test(org.junit.Test)

Aggregations

SynapseEnvironment (org.apache.synapse.core.SynapseEnvironment)67 Axis2SynapseEnvironment (org.apache.synapse.core.axis2.Axis2SynapseEnvironment)50 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)49 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)44 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)43 Test (org.junit.Test)40 OMElement (org.apache.axiom.om.OMElement)35 Parameter (org.apache.axis2.description.Parameter)29 MessageContext (org.apache.synapse.MessageContext)18 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)18 ArrayList (java.util.ArrayList)8 AddressEndpoint (org.apache.synapse.endpoints.AddressEndpoint)8 Endpoint (org.apache.synapse.endpoints.Endpoint)8 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)6 HashMap (java.util.HashMap)5 OMDocument (org.apache.axiom.om.OMDocument)4 SynapseException (org.apache.synapse.SynapseException)4 TestMessageContext (org.apache.synapse.TestMessageContext)4 IOException (java.io.IOException)3 ManagedLifecycle (org.apache.synapse.ManagedLifecycle)3