use of org.apache.synapse.core.axis2.Axis2MessageContext in project wso2-synapse by wso2.
the class RESTMediationTestCase method getMessageContext.
protected MessageContext getMessageContext(SynapseConfiguration synapseConfig, boolean https, String url, String method) throws Exception {
MessageContext synCtx = TestUtils.createSynapseMessageContext("<foo/>", synapseConfig);
org.apache.axis2.context.MessageContext msgCtx = ((Axis2MessageContext) synCtx).getAxis2MessageContext();
if (https) {
msgCtx.setIncomingTransportName("https");
} else {
msgCtx.setIncomingTransportName("http");
}
msgCtx.setProperty(Constants.Configuration.HTTP_METHOD, method);
msgCtx.setProperty(Constants.Configuration.TRANSPORT_IN_URL, url);
msgCtx.setProperty(NhttpConstants.REST_URL_POSTFIX, url.substring(1));
return synCtx;
}
use of org.apache.synapse.core.axis2.Axis2MessageContext in project wso2-synapse by wso2.
the class RESTMediationTestCase method addHttpHeader.
protected void addHttpHeader(String name, String value, MessageContext synCtx) {
org.apache.axis2.context.MessageContext msgCtx = ((Axis2MessageContext) synCtx).getAxis2MessageContext();
Object obj = msgCtx.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
if (obj != null) {
((Map) obj).put(name, value);
} else {
Map map = new HashMap();
map.put(name, value);
msgCtx.setProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS, map);
}
}
use of org.apache.synapse.core.axis2.Axis2MessageContext in project wso2-synapse by wso2.
the class SynapseXPathTest method testTransportHeaders.
public void testTransportHeaders() throws Exception {
Axis2MessageContext synCtx = TestUtils.getAxis2MessageContext("<test/>", null);
org.apache.axis2.context.MessageContext axis2MessageCtx = synCtx.getAxis2MessageContext();
Object headers = axis2MessageCtx.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
String name = "MyHeader";
String resultValue = "TestValue";
if (headers != null && headers instanceof Map) {
Map headersMap = (Map) headers;
headersMap.put(name, resultValue);
}
if (headers == null) {
Map headersMap = new HashMap();
headersMap.put(name, resultValue);
axis2MessageCtx.setProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS, headersMap);
}
assertEquals(resultValue, new SynapseXPath("$trp:" + name).evaluate(synCtx));
}
use of org.apache.synapse.core.axis2.Axis2MessageContext in project wso2-synapse by wso2.
the class NashornJavaScriptMessageContext method removeProperty.
/**
* Remove property from the message.
*
* @param key unique identifier of property
* @param scope scope of the property
*/
public void removeProperty(String key, String scope) {
if (scope == null || XMLConfigConstants.SCOPE_DEFAULT.equals(scope)) {
Set pros = mc.getPropertyKeySet();
if (pros != null) {
pros.remove(key);
}
} else if (XMLConfigConstants.SCOPE_AXIS2.equals(scope)) {
// Removing property from the Axis2 Message Context
Axis2MessageContext axis2smc = (Axis2MessageContext) mc;
org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext();
axis2MessageCtx.removeProperty(key);
} else if (XMLConfigConstants.SCOPE_TRANSPORT.equals(scope)) {
// Removing transport headers
Axis2MessageContext axis2smc = (Axis2MessageContext) mc;
org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext();
Object headers = axis2MessageCtx.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
if (headers != null && headers instanceof Map) {
Map headersMap = (Map) headers;
headersMap.remove(key);
}
} else if (XMLConfigConstants.SCOPE_OPERATION.equals(scope)) {
// Removing operation scope headers
Axis2MessageContext axis2smc = (Axis2MessageContext) mc;
org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext();
OperationContext axis2oc = axis2MessageCtx.getOperationContext();
axis2oc.removeProperty(key);
}
}
use of org.apache.synapse.core.axis2.Axis2MessageContext in project wso2-synapse by wso2.
the class DynamicLoadBalanceEndpointTest method testSend.
/**
* Test sending a message to a load balance EP
*
* @throws AxisFault on an issue sending message to DynamicLoadBalanceEndpoint
*/
@Test
public void testSend() throws AxisFault {
DynamicLoadbalanceEndpoint dynamicLoadbalanceEndpoint = new DynamicLoadbalanceEndpoint();
SynapseEnvironment synapseEnvironment = getMockedSynapseEnvironment();
dynamicLoadbalanceEndpoint.init(synapseEnvironment);
MessageContext messageContext = createMessageContext();
// Mock a LoadBalanceMembershipHandler and set
LoadBalanceMembershipHandler loadBalanceMembershipHandler = PowerMockito.mock(LoadBalanceMembershipHandler.class);
Member member1 = new Member("localhost", 9000);
Mockito.when(loadBalanceMembershipHandler.getNextApplicationMember(any(AlgorithmContext.class))).thenReturn(member1);
dynamicLoadbalanceEndpoint.setLoadBalanceMembershipHandler(loadBalanceMembershipHandler);
// set mocked SynapseEnvironment to message context
((Axis2MessageContext) messageContext).getAxis2MessageContext().getConfigurationContext().getAxisConfiguration().addParameter(SynapseConstants.SYNAPSE_ENV, synapseEnvironment);
messageContext.setEnvironment(synapseEnvironment);
// send message
dynamicLoadbalanceEndpoint.send(messageContext);
Assert.assertNotNull("SynapseConstants.LAST_ENDPOINT should return a not null value", messageContext.getProperty(SynapseConstants.LAST_ENDPOINT));
}
Aggregations