Search in sources :

Example 1 with SessionInformation

use of org.apache.synapse.endpoints.dispatch.SessionInformation in project wso2-synapse by wso2.

the class DynamicLoadbalanceEndpoint method sendMessage.

private void sendMessage(MessageContext synCtx) {
    logSetter();
    SessionInformation sessionInformation = null;
    Member currentMember = null;
    // TODO Temp hack: ESB removes the session id from request in a random manner.
    setCookieHeader(synCtx);
    ConfigurationContext configCtx = ((Axis2MessageContext) synCtx).getAxis2MessageContext().getConfigurationContext();
    if (lbMembershipHandler.getConfigurationContext() == null) {
        lbMembershipHandler.setConfigurationContext(configCtx);
    }
    if (isSessionAffinityBasedLB()) {
        // first check if this session is associated with a session. if so, get the endpoint
        // associated for that session.
        sessionInformation = (SessionInformation) synCtx.getProperty(SynapseConstants.PROP_SAL_CURRENT_SESSION_INFORMATION);
        currentMember = (Member) synCtx.getProperty(SynapseConstants.PROP_SAL_ENDPOINT_CURRENT_MEMBER);
        if (sessionInformation == null && currentMember == null) {
            sessionInformation = dispatcher.getSession(synCtx);
            if (sessionInformation != null) {
                if (log.isDebugEnabled()) {
                    log.debug("Current session id : " + sessionInformation.getId());
                }
                currentMember = sessionInformation.getMember();
                synCtx.setProperty(SynapseConstants.PROP_SAL_ENDPOINT_CURRENT_MEMBER, currentMember);
                // This is for reliably recovery any session information if while response is getting ,
                // session information has been removed by cleaner.
                // This will not be a cost as  session information a not heavy data structure
                synCtx.setProperty(SynapseConstants.PROP_SAL_CURRENT_SESSION_INFORMATION, sessionInformation);
            }
        }
    }
    DynamicLoadbalanceFaultHandlerImpl faultHandler = new DynamicLoadbalanceFaultHandlerImpl();
    if (sessionInformation != null && currentMember != null) {
        // send message on current session
        sessionInformation.updateExpiryTime();
        sendToApplicationMember(synCtx, currentMember, faultHandler, false);
    } else {
        // prepare for a new session
        currentMember = lbMembershipHandler.getNextApplicationMember(algorithmContext);
        if (currentMember == null) {
            String msg = "No application members available";
            log.error(msg);
            throw new SynapseException(msg);
        }
        sendToApplicationMember(synCtx, currentMember, faultHandler, true);
    }
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) SessionInformation(org.apache.synapse.endpoints.dispatch.SessionInformation) SynapseException(org.apache.synapse.SynapseException) Member(org.apache.axis2.clustering.Member)

Example 2 with SessionInformation

use of org.apache.synapse.endpoints.dispatch.SessionInformation in project wso2-synapse by wso2.

the class ServiceDynamicLoadbalanceEndpoint method sendMessage.

private void sendMessage(MessageContext synCtx) {
    logSetter();
    setCookieHeader(synCtx);
    // TODO: Refactor Session Aware LB dispatching code
    // Check whether a valid session for session aware dispatching is available
    Member currentMember = null;
    SessionInformation sessionInformation = null;
    if (isSessionAffinityBasedLB()) {
        // first check if this session is associated with a session. if so, get the endpoint
        // associated for that session.
        sessionInformation = (SessionInformation) synCtx.getProperty(SynapseConstants.PROP_SAL_CURRENT_SESSION_INFORMATION);
        currentMember = (Member) synCtx.getProperty(SynapseConstants.PROP_SAL_ENDPOINT_CURRENT_MEMBER);
        if (sessionInformation == null && currentMember == null) {
            sessionInformation = dispatcher.getSession(synCtx);
            if (sessionInformation != null) {
                if (log.isDebugEnabled()) {
                    log.debug("Current session id : " + sessionInformation.getId());
                }
                currentMember = sessionInformation.getMember();
                synCtx.setProperty(SynapseConstants.PROP_SAL_ENDPOINT_CURRENT_MEMBER, currentMember);
                // This is for reliably recovery any session information if while response is getting ,
                // session information has been removed by cleaner.
                // This will not be a cost as  session information a not heavy data structure
                synCtx.setProperty(SynapseConstants.PROP_SAL_CURRENT_SESSION_INFORMATION, sessionInformation);
            }
        }
    }
    // Dispatch request the relevant member
    String targetHost = getTargetHost(synCtx);
    ConfigurationContext configCtx = ((Axis2MessageContext) synCtx).getAxis2MessageContext().getConfigurationContext();
    if (slbMembershipHandler.getConfigurationContext() == null) {
        slbMembershipHandler.setConfigurationContext(configCtx);
    }
    ServiceDynamicLoadbalanceFaultHandlerImpl faultHandler = new ServiceDynamicLoadbalanceFaultHandlerImpl();
    faultHandler.setHost(targetHost);
    setupTransportHeaders(synCtx);
    if (sessionInformation != null && currentMember != null) {
        // send message on current session
        sessionInformation.updateExpiryTime();
        sendToApplicationMember(synCtx, currentMember, faultHandler, false);
    } else {
        // prepare for a new session
        currentMember = slbMembershipHandler.getNextApplicationMember(targetHost);
        if (currentMember == null) {
            String msg = "No application members available";
            log.error(msg);
            throw new SynapseException(msg);
        }
        sendToApplicationMember(synCtx, currentMember, faultHandler, true);
    }
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) SessionInformation(org.apache.synapse.endpoints.dispatch.SessionInformation) SynapseException(org.apache.synapse.SynapseException) Member(org.apache.axis2.clustering.Member)

Example 3 with SessionInformation

use of org.apache.synapse.endpoints.dispatch.SessionInformation in project wso2-synapse by wso2.

the class SALoadbalanceEndpoint method sendMessage.

public void sendMessage(MessageContext synCtx) {
    logSetter();
    if (log.isDebugEnabled()) {
        log.debug("Start : Session Affinity Load-balance Endpoint " + getName());
    }
    if (getContext().isState(EndpointContext.ST_OFF)) {
        informFailure(synCtx, SynapseConstants.ENDPOINT_LB_NONE_READY, "Loadbalance endpoint : " + getName() != null ? getName() : SynapseConstants.ANONYMOUS_ENDPOINT + " - is inactive");
        return;
    }
    // first check if this session is associated with a session. if so, get the endpoint
    // associated for that session.
    SessionInformation sessionInformation = (SessionInformation) synCtx.getProperty(SynapseConstants.PROP_SAL_CURRENT_SESSION_INFORMATION);
    List<Endpoint> endpoints = (List<Endpoint>) synCtx.getProperty(SynapseConstants.PROP_SAL_ENDPOINT_CURRENT_ENDPOINT_LIST);
    if (!(dispatcher instanceof HttpSessionDispatcher)) {
        try {
            org.apache.axis2.context.MessageContext axis2MsgCtx = ((Axis2MessageContext) synCtx).getAxis2MessageContext();
            MessageHandlerProvider.getMessageHandler(axis2MsgCtx).buildMessage(axis2MsgCtx, false);
        } catch (Exception e) {
            handleException("Error while building message", e, synCtx);
        }
    }
    // evaluate the properties
    evaluateProperties(synCtx);
    if (sessionInformation == null && endpoints == null) {
        sessionInformation = dispatcher.getSession(synCtx);
        if (sessionInformation != null) {
            if (log.isDebugEnabled()) {
                log.debug("Current session id : " + sessionInformation.getId());
            }
            endpoints = dispatcher.getEndpoints(sessionInformation);
            if (log.isDebugEnabled()) {
                log.debug("Endpoint sequence (path) on current session : " + this + endpoints);
            }
            synCtx.setProperty(SynapseConstants.PROP_SAL_ENDPOINT_CURRENT_ENDPOINT_LIST, endpoints);
            // This is for reliably recovery any session information if while response is getting ,
            // session information has been removed by cleaner.
            // This will not be a cost as  session information a not heavy data structure
            synCtx.setProperty(SynapseConstants.PROP_SAL_CURRENT_SESSION_INFORMATION, sessionInformation);
        }
    }
    if (sessionInformation != null && endpoints != null) {
        // send message on current session
        sendMessageOnCurrentSession(sessionInformation.getId(), endpoints, synCtx);
    } else {
        // prepare for a new session
        sendMessageOnNewSession(synCtx);
    }
}
Also used : SessionInformation(org.apache.synapse.endpoints.dispatch.SessionInformation) ArrayList(java.util.ArrayList) List(java.util.List) HttpSessionDispatcher(org.apache.synapse.endpoints.dispatch.HttpSessionDispatcher) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext)

Aggregations

SessionInformation (org.apache.synapse.endpoints.dispatch.SessionInformation)3 Member (org.apache.axis2.clustering.Member)2 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)2 SynapseException (org.apache.synapse.SynapseException)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)1 HttpSessionDispatcher (org.apache.synapse.endpoints.dispatch.HttpSessionDispatcher)1