Search in sources :

Example 91 with MessageContext

use of org.apache.axis2.context.MessageContext in project wso2-synapse by wso2.

the class AbstractEndpoint method prepareForEndpointStatistics.

/**
 * Process statistics for this message
 * @param synCtx the current message
 */
protected void prepareForEndpointStatistics(MessageContext synCtx) {
    // Setting Required property to reportForComponent the End Point aspects
    if (definition != null && definition.isStatisticsEnable()) {
        String opName = null;
        if (synCtx.getProperty(SynapseConstants.ENDPOINT_OPERATION) != null) {
            opName = synCtx.getProperty(SynapseConstants.ENDPOINT_OPERATION).toString();
        } else if (synCtx instanceof Axis2MessageContext) {
            AxisOperation operation = ((Axis2MessageContext) synCtx).getAxis2MessageContext().getAxisOperation();
            if (operation != null) {
                opName = operation.getName().getLocalPart();
            }
            if (opName == null || SynapseConstants.SYNAPSE_OPERATION_NAME.getLocalPart().equals(opName)) {
                String soapAction = synCtx.getSoapAction();
                opName = null;
                if (soapAction != null) {
                    int index = soapAction.indexOf("urn:");
                    if (index >= 0) {
                        opName = soapAction.substring("urn:".length());
                    } else {
                        opName = soapAction;
                    }
                }
            }
        }
        AspectConfiguration oldConfiguration = definition.getAspectConfiguration();
        if (opName != null) {
            AspectConfiguration newConfiguration = new AspectConfiguration(oldConfiguration.getId() + SynapseConstants.STATISTICS_KEY_SEPARATOR + opName);
            if (oldConfiguration.isStatisticsEnable()) {
                newConfiguration.enableStatistics();
            }
            if (oldConfiguration.isTracingEnabled()) {
                newConfiguration.enableTracing();
            }
        }
    }
}
Also used : AxisOperation(org.apache.axis2.description.AxisOperation) AspectConfiguration(org.apache.synapse.aspects.AspectConfiguration) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext)

Example 92 with MessageContext

use of org.apache.axis2.context.MessageContext in project wso2-synapse by wso2.

the class SALSessions method updateSession.

/**
 * Update or establish a session
 *
 * @param synCtx
 *            Synapse MessageContext
 * @param sessionID
 *            session id
 */
public void updateSession(MessageContext synCtx, SessionCookie cookie) {
    if (cookie == null || "".equals(cookie.getSessionId())) {
        if (log.isDebugEnabled()) {
            log.debug("Cannot find Session ID from the cookie.");
        }
        return;
    }
    String sessionId = cookie.getSessionId();
    String path = cookie.getPath();
    boolean createSession = false;
    if (log.isDebugEnabled()) {
        log.debug("Starting to update the session for : " + cookie);
    }
    // if this is related to the already established session
    SessionInformation oldSession = (SessionInformation) synCtx.getProperty(SynapseConstants.PROP_SAL_CURRENT_SESSION_INFORMATION);
    List<Endpoint> endpoints = null;
    Member currentMember = null;
    if (oldSession == null) {
        if (log.isDebugEnabled()) {
            log.debug("Going to create a New session with corresponds to: " + cookie);
        }
        endpoints = (List<Endpoint>) synCtx.getProperty(SynapseConstants.PROP_SAL_ENDPOINT_ENDPOINT_LIST);
        currentMember = (Member) synCtx.getProperty(SynapseConstants.PROP_SAL_ENDPOINT_CURRENT_MEMBER);
        createSession = true;
    } else {
        String oldSessionID = oldSession.getId();
        // This assumes that there can only be one path
        if (!sessionId.equals(oldSessionID) && pathMatches(path, oldSession.getPath())) {
            if (log.isDebugEnabled()) {
                log.debug("Renew the session : previous session id :" + oldSessionID + " new session :" + cookie);
            }
            removeSession(oldSessionID);
            endpoints = oldSession.getEndpointList();
            currentMember = oldSession.getMember();
            createSession = true;
        } else {
            SessionInformation information = getSessionInformation(oldSessionID);
            if (information == null) {
                // the message context
                if (log.isDebugEnabled()) {
                    log.debug("Recovering lost session information for session id " + sessionId);
                }
                endpoints = oldSession.getEndpointList();
                currentMember = oldSession.getMember();
                createSession = true;
            } else {
                if (log.isDebugEnabled()) {
                    log.debug("Session with id : " + sessionId + " is still live.");
                }
            }
        }
    }
    if (createSession) {
        SessionInformation newInformation;
        List<String> paths = new ArrayList<String>();
        // add the new path
        paths.add(path);
        if (currentMember == null) {
            newInformation = createSessionInformation(synCtx, sessionId, endpoints, paths);
        } else {
            newInformation = createSessionInformation(synCtx, sessionId, currentMember, paths);
        }
        if (log.isDebugEnabled()) {
            log.debug("Establishing a session for :" + cookie + " and it's endpoint sequence : " + endpoints);
        }
        if (isClustered) {
            Replicator.setAndReplicateState(SESSION_IDS + sessionId, newInformation, configCtx);
        } else {
            establishedSessions.put(sessionId, newInformation);
        }
    }
}
Also used : SALoadbalanceEndpoint(org.apache.synapse.endpoints.SALoadbalanceEndpoint) IndirectEndpoint(org.apache.synapse.endpoints.IndirectEndpoint) Endpoint(org.apache.synapse.endpoints.Endpoint) DynamicLoadbalanceEndpoint(org.apache.synapse.endpoints.DynamicLoadbalanceEndpoint) Member(org.apache.axis2.clustering.Member)

Example 93 with MessageContext

use of org.apache.axis2.context.MessageContext in project wso2-synapse by wso2.

the class URLRewriteMediatorTest method testUnconditionalRewriteScenario3.

public void testUnconditionalRewriteScenario3() throws Exception {
    URLRewriteMediator mediator = new URLRewriteMediator();
    mediator.setOutputProperty("outURL");
    RewriteAction action1 = new RewriteAction();
    action1.setValue(targetURL);
    RewriteRule rule1 = new RewriteRule();
    rule1.addRewriteAction(action1);
    mediator.addRule(rule1);
    RewriteAction action2 = new RewriteAction();
    action2.setValue("/services/SimpleStockQuoteService");
    action2.setFragmentIndex(URIFragments.PATH);
    RewriteAction action3 = new RewriteAction();
    action3.setXpath(new SynapseXPath("get-property('port')"));
    action3.setFragmentIndex(URIFragments.PORT);
    RewriteRule rule2 = new RewriteRule();
    rule2.addRewriteAction(action2);
    rule2.addRewriteAction(action3);
    mediator.addRule(rule2);
    MessageContext msgCtx = TestUtils.createLightweightSynapseMessageContext("<empty/>");
    msgCtx.setTo(new EndpointReference("http://localhost:8280"));
    msgCtx.setProperty("port", 9000);
    mediator.mediate(msgCtx);
    assertEquals(targetURL, msgCtx.getProperty("outURL"));
}
Also used : SynapseXPath(org.apache.synapse.util.xpath.SynapseXPath) MessageContext(org.apache.synapse.MessageContext) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 94 with MessageContext

use of org.apache.axis2.context.MessageContext in project wso2-synapse by wso2.

the class URLRewriteMediatorTest method testConditionalRewriteScenario4.

public void testConditionalRewriteScenario4() throws Exception {
    URLRewriteMediator mediator = new URLRewriteMediator();
    mediator.setOutputProperty("outURL");
    RewriteAction action1 = new RewriteAction();
    action1.setRegex("MyService");
    action1.setValue("SimpleStockQuoteService");
    action1.setFragmentIndex(URIFragments.PATH);
    action1.setActionType(RewriteAction.ACTION_REPLACE);
    RewriteRule rule1 = new RewriteRule();
    rule1.addRewriteAction(action1);
    EqualEvaluator eval1 = new EqualEvaluator();
    SOAPEnvelopeTextRetriever txtRtvr1 = new SOAPEnvelopeTextRetriever("//symbol");
    eval1.setTextRetriever(txtRtvr1);
    eval1.setValue("IBM");
    rule1.setCondition(eval1);
    mediator.addRule(rule1);
    MessageContext msgCtx = TestUtils.createLightweightSynapseMessageContext("<getQuote><symbol>IBM</symbol></getQuote>");
    msgCtx.setTo(new EndpointReference("http://localhost:9000/services/MyService"));
    mediator.mediate(msgCtx);
    assertEquals(targetURL, msgCtx.getProperty("outURL"));
}
Also used : SOAPEnvelopeTextRetriever(org.apache.synapse.commons.evaluators.source.SOAPEnvelopeTextRetriever) MessageContext(org.apache.synapse.MessageContext) EqualEvaluator(org.apache.synapse.commons.evaluators.EqualEvaluator) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 95 with MessageContext

use of org.apache.axis2.context.MessageContext in project wso2-synapse by wso2.

the class URLRewriteMediatorTest method testConditionalRewriteScenario1.

public void testConditionalRewriteScenario1() throws Exception {
    URLRewriteMediator mediator = new URLRewriteMediator();
    RewriteAction action = new RewriteAction();
    action.setValue(targetURL);
    RewriteRule rule = new RewriteRule();
    EqualEvaluator eval = new EqualEvaluator();
    URLTextRetriever txtRtvr = new URLTextRetriever();
    txtRtvr.setSource(EvaluatorConstants.URI_FRAGMENTS.port.name());
    eval.setTextRetriever(txtRtvr);
    eval.setValue("8280");
    rule.setCondition(eval);
    rule.addRewriteAction(action);
    mediator.addRule(rule);
    MessageContext msgCtx = TestUtils.createLightweightSynapseMessageContext("<empty/>");
    msgCtx.setTo(new EndpointReference("http://localhost:8280"));
    mediator.mediate(msgCtx);
    assertEquals(targetURL, msgCtx.getTo().getAddress());
}
Also used : URLTextRetriever(org.apache.synapse.commons.evaluators.source.URLTextRetriever) MessageContext(org.apache.synapse.MessageContext) EqualEvaluator(org.apache.synapse.commons.evaluators.EqualEvaluator) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Aggregations

MessageContext (org.apache.axis2.context.MessageContext)218 AxisFault (org.apache.axis2.AxisFault)126 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)84 EndpointReference (org.apache.axis2.addressing.EndpointReference)79 OMElement (org.apache.axiom.om.OMElement)75 MessageContext (org.apache.synapse.MessageContext)71 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)62 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)56 IOException (java.io.IOException)55 Map (java.util.Map)52 Test (org.junit.Test)45 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)44 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)36 MessageFormatter (org.apache.axis2.transport.MessageFormatter)35 OMOutputFormat (org.apache.axiom.om.OMOutputFormat)34 Options (org.apache.axis2.client.Options)30 HashMap (java.util.HashMap)29 AxisService (org.apache.axis2.description.AxisService)29 QName (javax.xml.namespace.QName)28 Axis2SynapseEnvironment (org.apache.synapse.core.axis2.Axis2SynapseEnvironment)28