use of org.apache.synapse.core.axis2.Axis2SynapseEnvironment in project wso2-synapse by wso2.
the class DynamicLoadbalanceEndpoint method init.
@Override
public void init(SynapseEnvironment synapseEnvironment) {
ConfigurationContext cc = ((Axis2SynapseEnvironment) synapseEnvironment).getAxis2ConfigurationContext();
if (!initialized) {
super.init(synapseEnvironment);
if (algorithmContext == null) {
algorithmContext = new AlgorithmContext(isClusteringEnabled, cc, getName());
}
// Initialize the SAL Sessions if already has not been initialized.
SALSessions salSessions = SALSessions.getInstance();
if (!salSessions.isInitialized()) {
salSessions.initialize(isClusteringEnabled, cc);
}
}
log.info("Dynamic load balance endpoint initialized");
}
use of org.apache.synapse.core.axis2.Axis2SynapseEnvironment 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.core.axis2.Axis2SynapseEnvironment 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);
}
use of org.apache.synapse.core.axis2.Axis2SynapseEnvironment in project wso2-synapse by wso2.
the class DBReportMediatorTest method suite.
public static Test suite() {
return new TestSetup(new TestSuite(DBReportMediatorTest.class)) {
@Override
protected void setUp() throws Exception {
String baseDir = System.getProperty("basedir");
if (baseDir == null) {
baseDir = ".";
}
report = (DBReportMediator) new DBReportMediatorFactory().createMediator(createOMElement("<dblookup xmlns=\"http://ws.apache.org/ns/synapse\">\n" + " <connection>\n" + " <pool>\n" + " <driver>org.apache.derby.jdbc.EmbeddedDriver</driver>\n" + " <url>jdbc:derby:" + baseDir + "/target/derbyDB;create=true</url>\n" + " <user>user</user>\n" + " <password>pass</password>\n" + " <property name=\"initialsize\" value=\"2\"/>\n" + " <property name=\"isolation\" value=\"Connection.TRANSACTION_SERIALIZABLE\"/>\n" + " </pool>\n" + " </connection>\n" + " <statement>\n" + " <sql>insert into audit values(?, ?, ?, ?)</sql>\n" + " <parameter expression=\"//from\" type=\"VARCHAR\"/>\n" + " <parameter expression=\"//count\" type=\"INTEGER\"/>\n" + " <parameter expression=\"//to\" type=\"VARCHAR\"/>\n" + " <parameter value=\"GOLD\" type=\"VARCHAR\"/>\n" + " </statement>\n" + "</dblookup>"), new Properties());
report.init(new Axis2SynapseEnvironment(new SynapseConfiguration()));
java.sql.Statement s = report.getDataSource().getConnection().createStatement();
try {
s.execute("drop table audit");
} catch (SQLException ignore) {
}
s.execute("create table audit(fromepr varchar(10), cnt int, toepr varchar(10), category varchar(10))");
s.close();
}
@Override
protected void tearDown() throws Exception {
}
};
}
use of org.apache.synapse.core.axis2.Axis2SynapseEnvironment in project wso2-synapse by wso2.
the class POJOCommandMediatorTest method testPojoWithPropertiesCommandImpl.
public void testPojoWithPropertiesCommandImpl() throws Exception {
Mediator pcm = MediatorFactoryFinder.getInstance().getMediator(createOMElement("<pojoCommand name='org.apache.synapse.mediators.ext.POJOCommandTestImplementedMediator' " + "xmlns='http://ws.apache.org/ns/synapse'><property name=\"testProp\" " + "expression=\"fn:concat('XPATH ', 'FUNC')\" action=\"ReadMessage\"/></pojoCommand>"), new Properties());
POJOCommandTestHelper.reset();
TestMessageContext msgContext = new TestMessageContext();
msgContext.setEnvironment(new Axis2SynapseEnvironment(new SynapseConfiguration()));
pcm.mediate(msgContext);
assertEquals("XPATH FUNC", POJOCommandTestHelper.getInstance().getChangedProperty());
assertTrue(POJOCommandTestHelper.getInstance().isExecuted());
}
Aggregations