use of org.apache.synapse.core.SynapseEnvironment in project wso2-synapse by wso2.
the class EndpointDeployerTest method testUpdate.
/**
* Test updating an endpoint
*
* @throws Exception
*/
@Test
public void testUpdate() 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);
endpointDeployer.deploySynapseArtifact(inputElement, "sampleFile", null);
String inputUpdateXML = "<endpoint name = \"sampleUpdatedEP\" xmlns=\"http://ws.apache.org/ns/synapse\">" + "<address uri=\"http://localhost:9000/services/SimpleStockQuoteService\" >" + "</address>" + "</endpoint>";
OMElement updatedElement = AXIOMUtil.stringToOM(inputUpdateXML);
String response = endpointDeployer.updateSynapseArtifact(updatedElement, "sampleUpdateFile", "sampleEP", null);
Assert.assertEquals("Endpoint not updated!", "sampleUpdatedEP", response);
}
use of org.apache.synapse.core.SynapseEnvironment in project wso2-synapse by wso2.
the class WeightedRRLCAlgorithmTest method createLoadBalanceEndpoint.
private LoadbalanceEndpoint createLoadBalanceEndpoint() {
LoadbalanceEndpoint loadbalanceEndpoint = new LoadbalanceEndpoint();
List<Endpoint> endpoints = createEndpoints();
WeightedRRLCAlgorithm algorithm = new WeightedRRLCAlgorithm();
MediatorProperty property = new MediatorProperty();
property.setName(WeightedRRLCAlgorithm.LB_WEIGHTED_RRLC_ROUNDS_PER_RECAL);
property.setValue("2");
loadbalanceEndpoint.addProperty(property);
algorithm.setEndpoints(endpoints);
algorithm.setLoadBalanceEndpoint(loadbalanceEndpoint);
loadbalanceEndpoint.setChildren(endpoints);
loadbalanceEndpoint.setAlgorithm(algorithm);
SynapseEnvironment env = new Axis2SynapseEnvironment(new ConfigurationContext(new AxisConfiguration()), new SynapseConfiguration());
loadbalanceEndpoint.init(env);
return loadbalanceEndpoint;
}
use of org.apache.synapse.core.SynapseEnvironment in project wso2-synapse by wso2.
the class SALSessionsTest method testUpdateCookieWithOldSession.
/**
* Test updating session with cookie and old session
* @throws Exception
*/
@Test
public void testUpdateCookieWithOldSession() throws Exception {
BasicConfigurator.configure();
SynapseConfiguration synapseConfiguration = new SynapseConfiguration();
AxisConfiguration axisConfiguration = synapseConfiguration.getAxisConfiguration();
ConfigurationContext cfgCtx = new ConfigurationContext(axisConfiguration);
SynapseEnvironment synapseEnvironment = new Axis2SynapseEnvironment(cfgCtx, synapseConfiguration);
Axis2MessageContext axis2MessageContext = new Axis2MessageContext(new org.apache.axis2.context.MessageContext(), synapseConfiguration, synapseEnvironment);
MessageContext messageContext = axis2MessageContext;
Endpoint endpoint = new AddressEndpoint();
List<Endpoint> endpoints = new ArrayList<>();
endpoints.add(endpoint);
SALSessions salSessions = SALSessions.getInstance();
salSessions.initialize(false, cfgCtx);
SessionInformation oldSessionInfo = new SessionInformation("oldTestSession", endpoints, 30000);
List<String> path = new ArrayList<>();
path.add("samplePath");
oldSessionInfo.setPath(path);
messageContext.setProperty(SynapseConstants.PROP_SAL_CURRENT_SESSION_INFORMATION, oldSessionInfo);
SessionCookie sessionCookie = new SessionCookie();
sessionCookie.setSessionId("testCookie2");
sessionCookie.setPath("samplePath");
salSessions.updateSession(messageContext, sessionCookie);
SessionInformation sessionInformation = salSessions.getSession("testCookie2");
Assert.assertEquals("Session not updated!", "testCookie2", sessionInformation.getId());
}
use of org.apache.synapse.core.SynapseEnvironment in project wso2-synapse by wso2.
the class SALSessionsTest method testUpdateCookieWithOldSessionSameName.
/**
* Test updating session with cookie and old session where the old session id is same as current session id
* @throws Exception
*/
@Test
public void testUpdateCookieWithOldSessionSameName() throws Exception {
BasicConfigurator.configure();
SynapseConfiguration synapseConfiguration = new SynapseConfiguration();
AxisConfiguration axisConfiguration = synapseConfiguration.getAxisConfiguration();
ConfigurationContext cfgCtx = new ConfigurationContext(axisConfiguration);
SynapseEnvironment synapseEnvironment = new Axis2SynapseEnvironment(cfgCtx, synapseConfiguration);
Axis2MessageContext axis2MessageContext = new Axis2MessageContext(new org.apache.axis2.context.MessageContext(), synapseConfiguration, synapseEnvironment);
MessageContext messageContext = axis2MessageContext;
Endpoint endpoint = new AddressEndpoint();
List<Endpoint> endpoints = new ArrayList<>();
endpoints.add(endpoint);
messageContext.setProperty(SynapseConstants.PROP_SAL_ENDPOINT_ENDPOINT_LIST, endpoints);
SALSessions salSessions = SALSessions.getInstance();
salSessions.initialize(false, cfgCtx);
SessionInformation oldSessionInfo = new SessionInformation("testCookie3", endpoints, 30000);
List<String> path = new ArrayList<>();
path.add("samplePath");
oldSessionInfo.setPath(path);
messageContext.setProperty(SynapseConstants.PROP_SAL_CURRENT_SESSION_INFORMATION, oldSessionInfo);
SessionCookie sessionCookie = new SessionCookie();
sessionCookie.setSessionId("testCookie3");
sessionCookie.setPath("samplePath");
salSessions.updateSession(messageContext, sessionCookie);
SessionInformation sessionInformation = salSessions.getSession("testCookie3");
Assert.assertEquals("Session not updated!", "testCookie3", sessionInformation.getId());
}
use of org.apache.synapse.core.SynapseEnvironment in project wso2-synapse by wso2.
the class SALSessionsTest method testUpdateWithCookie.
/**
* Test updating session with cookie
* @throws Exception
*/
@Test
public void testUpdateWithCookie() throws Exception {
BasicConfigurator.configure();
SynapseConfiguration synapseConfiguration = new SynapseConfiguration();
AxisConfiguration axisConfiguration = synapseConfiguration.getAxisConfiguration();
ConfigurationContext cfgCtx = new ConfigurationContext(axisConfiguration);
SynapseEnvironment synapseEnvironment = new Axis2SynapseEnvironment(cfgCtx, synapseConfiguration);
Axis2MessageContext axis2MessageContext = new Axis2MessageContext(new org.apache.axis2.context.MessageContext(), synapseConfiguration, synapseEnvironment);
MessageContext messageContext = axis2MessageContext;
Endpoint endpoint = new AddressEndpoint();
List<Endpoint> endpoints = new ArrayList<>();
endpoints.add(endpoint);
messageContext.setProperty(SynapseConstants.PROP_SAL_ENDPOINT_ENDPOINT_LIST, endpoints);
SALSessions salSessions = SALSessions.getInstance();
salSessions.initialize(false, cfgCtx);
SessionCookie sessionCookie = new SessionCookie();
sessionCookie.setSessionId("testCookie");
salSessions.updateSession(messageContext, sessionCookie);
SessionInformation sessionInformation = salSessions.getSession("testCookie");
Assert.assertEquals("Session not updated!", "testCookie", sessionInformation.getId());
}
Aggregations