Search in sources :

Example 56 with Axis2MessageContext

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);
    }
}
Also used : OperationContext(org.apache.axis2.context.OperationContext) Set(java.util.Set) XMLObject(org.mozilla.javascript.xml.XMLObject) NativeObject(org.mozilla.javascript.NativeObject) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) HashMap(java.util.HashMap) Map(java.util.Map) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext)

Example 57 with Axis2MessageContext

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);
    }
}
Also used : HashMap(java.util.HashMap) XMLObject(org.mozilla.javascript.xml.XMLObject) NativeObject(org.mozilla.javascript.NativeObject) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) HashMap(java.util.HashMap) Map(java.util.Map) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext)

Example 58 with Axis2MessageContext

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");
}
Also used : MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Example 59 with Axis2MessageContext

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"));
}
Also used : SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) URITemplateHelper(org.apache.synapse.rest.dispatch.URITemplateHelper) XSLTMediator(org.apache.synapse.mediators.transform.XSLTMediator) PropertyMediator(org.apache.synapse.mediators.builtin.PropertyMediator) Value(org.apache.synapse.mediators.Value) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) SynapseMessageReceiver(org.apache.synapse.core.axis2.SynapseMessageReceiver) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext)

Example 60 with Axis2MessageContext

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));
}
Also used : SynapseXPath(org.apache.synapse.util.xpath.SynapseXPath) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext)

Aggregations

Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)92 MessageContext (org.apache.synapse.MessageContext)50 Axis2SynapseEnvironment (org.apache.synapse.core.axis2.Axis2SynapseEnvironment)24 Map (java.util.Map)23 HashMap (java.util.HashMap)20 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)19 SynapseEnvironment (org.apache.synapse.core.SynapseEnvironment)18 Test (org.junit.Test)16 OMElement (org.apache.axiom.om.OMElement)15 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)14 SynapseException (org.apache.synapse.SynapseException)14 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)13 ArrayList (java.util.ArrayList)12 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)11 EndpointReference (org.apache.axis2.addressing.EndpointReference)10 SynapseLog (org.apache.synapse.SynapseLog)9 Endpoint (org.apache.synapse.endpoints.Endpoint)9 OperationContext (org.apache.axis2.context.OperationContext)8 AxisFault (org.apache.axis2.AxisFault)7 Entry (org.apache.synapse.config.Entry)7