use of org.apache.synapse.MessageContext in project wso2-synapse by wso2.
the class EndpointViewTest method createEndPointView.
/**
* Creates a basic EndpointView with a given number of children added to the endpoint.
*
* @param numberOfChildren the child endpoints inside the endpoint attached to the end point view. If
* specified as 0, the children list will be null
* @return the created end point view
*/
private EndpointView createEndPointView(int numberOfChildren) {
AbstractEndpoint endpoint = new AddressEndpoint();
MessageContext synCtx = new TestMessageContext();
synCtx.setConfiguration(new SynapseConfiguration());
SynapseEnvironment environment = new Axis2SynapseEnvironment(new ConfigurationContext(new AxisConfiguration()), synCtx.getConfiguration());
if (numberOfChildren > 0) {
List<Endpoint> children = new ArrayList<>(numberOfChildren);
for (int i = 0; i < numberOfChildren; i++) {
AbstractEndpoint child = new AddressEndpoint();
child.init(environment);
child.setEnableMBeanStats(true);
child.setName("endpoint" + i);
children.add(child);
}
endpoint.setChildren(children);
}
endpoint.init(environment);
return new EndpointView("endpoint", endpoint);
}
use of org.apache.synapse.MessageContext in project wso2-synapse by wso2.
the class HttpEndpointTest method testQueryParamsAsUnreservedChars.
/**
* Tests sending sample characters that may be unreserved (@,: etc) as query parameter content
*/
@Test
public void testQueryParamsAsUnreservedChars() throws AxisFault, XMLStreamException {
HTTPEndpointFactory factory = new HTTPEndpointFactory();
OMElement em = AXIOMUtil.stringToOM("<endpoint><http method=\"GET\" uri-template=\"http://abc.com?symbol={+query.param.symbol}&user={+query.param.user}\"/></endpoint>");
EndpointDefinition ep1 = factory.createEndpointDefinition(em);
HTTPEndpoint httpEndpoint = new HTTPEndpoint();
httpEndpoint.setHttpMethod("GET");
httpEndpoint.setDefinition(ep1);
httpEndpoint.setUriTemplate(UriTemplate.fromTemplate("http://abc.com?symbol={+query.param.symbol}&user={+query.param.user}"));
SynapseEnvironment synapseEnvironment = getMockedSynapseEnvironment();
httpEndpoint.init(getMockedSynapseEnvironment());
MessageContext messageContext = createMessageContext();
messageContext.setProperty("query.param.symbol", "US:123");
messageContext.setProperty("query.param.user", "john@gmail");
// set mocked SynapseEnvironment to message context
((Axis2MessageContext) messageContext).getAxis2MessageContext().getConfigurationContext().getAxisConfiguration().addParameter(SynapseConstants.SYNAPSE_ENV, synapseEnvironment);
messageContext.setEnvironment(synapseEnvironment);
httpEndpoint.executeEpTypeSpecificFunctions(messageContext);
Assert.assertEquals("Reserved characters need to be sent in default format without encoding", "http://abc.com?symbol=US:123&user=john@gmail", messageContext.getTo().getAddress().toString());
}
use of org.apache.synapse.MessageContext in project wso2-synapse by wso2.
the class HttpEndpointTest method testQueryParamsAsReservedChars.
/**
* Tests sending sample reserved characters(@,:) as query parameter content
* @throws AxisFault
* @throws XMLStreamException
*/
@Test
public void testQueryParamsAsReservedChars() throws AxisFault, XMLStreamException {
HTTPEndpointFactory factory = new HTTPEndpointFactory();
OMElement em = AXIOMUtil.stringToOM("<endpoint><http method=\"GET\" uri-template=\"http://abc.com?symbol={query.param.symbol}&user={query.param.user}\"/></endpoint>");
EndpointDefinition ep1 = factory.createEndpointDefinition(em);
HTTPEndpoint httpEndpoint = new HTTPEndpoint();
httpEndpoint.setHttpMethod("GET");
httpEndpoint.setDefinition(ep1);
httpEndpoint.setUriTemplate(UriTemplate.fromTemplate("http://abc.com?symbol={query.param.symbol}&user={query.param.user}"));
SynapseEnvironment synapseEnvironment = getMockedSynapseEnvironment();
httpEndpoint.init(getMockedSynapseEnvironment());
MessageContext messageContext = createMessageContext();
messageContext.setProperty("query.param.symbol", "US:123");
messageContext.setProperty("query.param.user", "john@gmail");
// set mocked SynapseEnvironment to message context
((Axis2MessageContext) messageContext).getAxis2MessageContext().getConfigurationContext().getAxisConfiguration().addParameter(SynapseConstants.SYNAPSE_ENV, synapseEnvironment);
messageContext.setEnvironment(synapseEnvironment);
httpEndpoint.executeEpTypeSpecificFunctions(messageContext);
Assert.assertEquals("Reserved characters need to be encoded", "http://abc.com?symbol=US%3A123&user=john%40gmail", messageContext.getTo().getAddress().toString());
}
use of org.apache.synapse.MessageContext in project wso2-synapse by wso2.
the class WeightedRRLCAlgorithmTest method testNextEndpoint.
public void testNextEndpoint() {
MessageContext messageContext = createMessageContext();
LoadbalanceEndpoint endpoint = createLoadBalanceEndpoint();
String[] firstTwoRoundsExpected = { "6", "6", "6", "6", "6", "6", "5", "5", "5", "5", "5", "3", "3", "3", "2", "2", "1", "6", "6", "6", "6", "6", "6", "5", "5", "5", "5", "5", "3", "3", "3", "2", "2", "1" };
LoadbalanceAlgorithm algo = endpoint.getAlgorithm();
String[] firstTwoRoundsResults = new String[34];
for (int i = 0; i < 34; i++) {
Endpoint epr = algo.getNextEndpoint(messageContext, null);
if (epr instanceof AddressEndpoint) {
firstTwoRoundsResults[i] = ((AddressEndpoint) epr).getProperty(WeightedRRLCAlgorithm.LB_WEIGHTED_RRLC_WEIGHT).getValue();
}
}
for (int i = 0; i < 34; i++) {
assertEquals(firstTwoRoundsExpected[i], firstTwoRoundsResults[i]);
}
String[] secondTwoRoundsExpected = { "6", "6", "6", "6", "5", "5", "5", "5", "5", "5", "5", "3", "3", "3", "3", "2", "2", "2", "2", "1", "1", "6", "6", "6", "6", "5", "5", "5", "5", "5", "5", "5", "3", "3" };
String[] secondTwoRoundsResults = new String[34];
for (int i = 0; i < 34; i++) {
Endpoint epr = algo.getNextEndpoint(messageContext, null);
if (epr instanceof AddressEndpoint) {
secondTwoRoundsResults[i] = ((AddressEndpoint) epr).getProperty(WeightedRRLCAlgorithm.LB_WEIGHTED_RRLC_WEIGHT).getValue();
}
}
for (int i = 0; i < 34; i++) {
assertEquals(secondTwoRoundsExpected[i], secondTwoRoundsResults[i]);
}
}
use of org.apache.synapse.MessageContext in project wso2-synapse by wso2.
the class SALSessionsTest method testUpdateWithOldSessionSameName.
/**
* Test updating session with session id and old session where the old session id is same as current session id
* @throws Exception
*/
@Test
public void testUpdateWithOldSessionSameName() 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("testSession3", endpoints, 30000);
messageContext.setProperty(SynapseConstants.PROP_SAL_CURRENT_SESSION_INFORMATION, oldSessionInfo);
salSessions.updateSession(messageContext, "testSession3");
SessionInformation sessionInformation = salSessions.getSession("testSession3");
Assert.assertEquals("Session not updated!", "testSession3", sessionInformation.getId());
}
Aggregations