use of org.apache.synapse.core.axis2.Axis2MessageContext in project wso2-synapse by wso2.
the class CommonScriptMessageContext method removeProperty.
/**
* Remove property from the message.
*
* @param key unique identifier of property
* @param scope scope of the property
*/
@Override
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 CommonScriptMessageContext method setProperty.
/**
* Add a new property to the message.
*
* @param key unique identifier of property
* @param value value of property
* @param scope scope of the property
*/
@Override
public void setProperty(String key, Object value, String scope) {
if (scope == null || XMLConfigConstants.SCOPE_DEFAULT.equals(scope)) {
setProperty(key, value);
} else if (XMLConfigConstants.SCOPE_AXIS2.equals(scope)) {
// Setting property into the Axis2 Message Context
Axis2MessageContext axis2smc = (Axis2MessageContext) mc;
org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext();
axis2MessageCtx.setProperty(key, value);
handleSpecialProperties(key, value, axis2MessageCtx);
} else if (XMLConfigConstants.SCOPE_TRANSPORT.equals(scope)) {
// Setting 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.put(key, value);
}
if (headers == null) {
Map headersMap = new HashMap();
headersMap.put(key, value);
axis2MessageCtx.setProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS, headersMap);
}
} else if (XMLConfigConstants.SCOPE_OPERATION.equals(scope)) {
Axis2MessageContext axis2smc = (Axis2MessageContext) mc;
org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext();
axis2smc.getAxis2MessageContext().getOperationContext().setProperty(key, value);
}
}
use of org.apache.synapse.core.axis2.Axis2MessageContext in project wso2-synapse by wso2.
the class BasicAPIMediationTest method testRestURLPostfix3.
public void testRestURLPostfix3() throws Exception {
API api = new API(TEST_API, "/services/Foo");
SynapseConfiguration synapseConfig = new SynapseConfiguration();
synapseConfig.addAPI(TEST_API, api);
RESTRequestHandler handler = new RESTRequestHandler();
MessageContext synCtx = getMessageContext(synapseConfig, false, "/services/Foo/test", "GET");
// When the service path is in the URL, NHTTP transport removes that portion
// from the postfix
((Axis2MessageContext) synCtx).getAxis2MessageContext().setProperty(NhttpConstants.REST_URL_POSTFIX, "/test");
handler.process(synCtx);
checkRestURLPostfix(synCtx, "/test");
}
use of org.apache.synapse.core.axis2.Axis2MessageContext in project wso2-synapse by wso2.
the class ResourceTest method testFaultSequence.
public void testFaultSequence() throws Exception {
API api = new API("TestAPI", "/test");
Resource resource = new Resource();
resource.setDispatcherHelper(new URITemplateHelper("/~{user}"));
SequenceMediator inSequence = getTestSequence("seq.in", "seq.in.value");
((PropertyMediator) inSequence.getChild(0)).setScope("axis2");
XSLTMediator xsltMediator = new XSLTMediator();
xsltMediator.setXsltKey(new Value("/bogus/key"));
inSequence.addChild(xsltMediator);
resource.setInSequence(inSequence);
SequenceMediator faultSequence = getTestSequence("seq.fault", "seq.fault.value");
((PropertyMediator) faultSequence.getChild(0)).setScope("axis2");
resource.setFaultSequence(faultSequence);
api.addResource(resource);
SynapseConfiguration synapseConfig = new SynapseConfiguration();
synapseConfig.addAPI(api.getName(), api);
synapseConfig.addSequence("main", getTestSequence("main.in", "main.value"));
MessageContext synCtx = getMessageContext(synapseConfig, false, "/test/~foo", "GET");
MessageContextCreatorForAxis2.setSynConfig(synapseConfig);
MessageContextCreatorForAxis2.setSynEnv(synCtx.getEnvironment());
org.apache.axis2.context.MessageContext mc = ((Axis2MessageContext) synCtx).getAxis2MessageContext();
mc.setConfigurationContext(((Axis2SynapseEnvironment) synCtx.getEnvironment()).getAxis2ConfigurationContext());
new SynapseMessageReceiver().receive(mc);
assertEquals("seq.in.value", mc.getProperty("seq.in"));
assertEquals("seq.fault.value", mc.getProperty("seq.fault"));
}
use of org.apache.synapse.core.axis2.Axis2MessageContext in project wso2-synapse by wso2.
the class SynapseXPathTest method testAxis2ContextProperties.
public void testAxis2ContextProperties() throws Exception {
Axis2MessageContext synCtx = TestUtils.getAxis2MessageContext("<test/>", null);
synCtx.getAxis2MessageContext().setProperty("test", message);
synCtx.getAxis2MessageContext().setProperty("test2", "1234");
assertEquals(message, new SynapseXPath("$axis2:test").evaluate(synCtx));
assertEquals(1234, new SynapseXPath("$axis2:test2").numberValueOf(synCtx).intValue());
assertTrue(new SynapseXPath("$axis2:test2 = 1234").booleanValueOf(synCtx));
}
Aggregations