Search in sources :

Example 6 with ConfigurationContext

use of org.apache.axis2.context.ConfigurationContext 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 7 with ConfigurationContext

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

the class ServiceDynamicLoadbalanceEndpoint method init.

@Override
public void init(SynapseEnvironment synapseEnvironment) {
    if (!initialized) {
        super.init(synapseEnvironment);
        ConfigurationContext cfgCtx = ((Axis2SynapseEnvironment) synapseEnvironment).getAxis2ConfigurationContext();
        ClusteringAgent clusteringAgent = cfgCtx.getAxisConfiguration().getClusteringAgent();
        if (clusteringAgent == null) {
            throw new SynapseException("Axis2 ClusteringAgent not defined in axis2.xml");
        }
        // Add the Axis2 GroupManagement agents
        for (String domain : hostDomainMap.values()) {
            if (clusteringAgent.getGroupManagementAgent(domain) == null) {
                clusteringAgent.addGroupManagementAgent(new DefaultGroupManagementAgent(), domain);
            }
        }
        slbMembershipHandler = new ServiceLoadBalanceMembershipHandler(hostDomainMap, getAlgorithm(), cfgCtx, isClusteringEnabled, getName());
        // Initialize the SAL Sessions if already has not been initialized.
        SALSessions salSessions = SALSessions.getInstance();
        if (!salSessions.isInitialized()) {
            salSessions.initialize(isClusteringEnabled, cfgCtx);
        }
        initialized = true;
        log.info("ServiceDynamicLoadbalanceEndpoint initialized");
    }
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) DefaultGroupManagementAgent(org.apache.axis2.clustering.management.DefaultGroupManagementAgent) SynapseException(org.apache.synapse.SynapseException) ClusteringAgent(org.apache.axis2.clustering.ClusteringAgent) SALSessions(org.apache.synapse.endpoints.dispatch.SALSessions) ServiceLoadBalanceMembershipHandler(org.apache.synapse.core.axis2.ServiceLoadBalanceMembershipHandler)

Example 8 with ConfigurationContext

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

the class AbstractEndpoint method init.

// ----------------------- default method implementations and common code -----------------------
public void init(SynapseEnvironment synapseEnvironment) {
    ConfigurationContext cc = ((Axis2SynapseEnvironment) synapseEnvironment).getAxis2ConfigurationContext();
    if (!initialized) {
        // The check for clustering environment
        ClusteringAgent clusteringAgent = cc.getAxisConfiguration().getClusteringAgent();
        if (clusteringAgent != null && clusteringAgent.getStateManager() != null) {
            isClusteringEnabled = Boolean.TRUE;
        } else {
            isClusteringEnabled = Boolean.FALSE;
        }
        context = new EndpointContext(getName(), getDefinition(), isClusteringEnabled, cc, metricsMBean);
    }
    initialized = true;
    if (children != null) {
        for (Endpoint e : children) {
            e.init(synapseEnvironment);
        }
    }
    contentAware = definition != null && ((definition.getFormat() != null && !definition.getFormat().equals(SynapseConstants.FORMAT_REST)) || definition.isSecurityOn() || definition.isReliableMessagingOn() || definition.isAddressingOn() || definition.isUseMTOM() || definition.isUseSwa());
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) ClusteringAgent(org.apache.axis2.clustering.ClusteringAgent)

Example 9 with ConfigurationContext

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

the class LoadbalanceEndpoint method init.

@Override
public void init(SynapseEnvironment synapseEnvironment) {
    ConfigurationContext cc = ((Axis2SynapseEnvironment) synapseEnvironment).getAxis2ConfigurationContext();
    if (!initialized) {
        super.init(synapseEnvironment);
        if (algorithmContext == null) {
            algorithmContext = new AlgorithmContext(isClusteringEnabled, cc, getName());
        }
        // initlize the algorithm
        if (algorithm != null && algorithm instanceof ManagedLifecycle) {
            ManagedLifecycle lifecycle = (ManagedLifecycle) algorithm;
            lifecycle.init(synapseEnvironment);
        }
        loadBalanceEPInitialized = true;
        buildMessage = Boolean.parseBoolean(SynapsePropertiesLoader.getPropertyValue(SynapseConstants.BUILD_MESSAGE_ON_FAILOVER, "false"));
    }
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) AlgorithmContext(org.apache.synapse.endpoints.algorithms.AlgorithmContext) ManagedLifecycle(org.apache.synapse.ManagedLifecycle)

Example 10 with ConfigurationContext

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

the class SALoadbalanceEndpoint method init.

public void init(SynapseEnvironment synapseEnvironment) {
    ConfigurationContext cc = ((Axis2SynapseEnvironment) synapseEnvironment).getAxis2ConfigurationContext();
    if (!initialized) {
        super.init(synapseEnvironment);
        // Initialize the SAL Sessions if already has not been initialized.
        SALSessions salSessions = SALSessions.getInstance();
        if (!salSessions.isInitialized()) {
            salSessions.initialize(isClusteringEnabled, cc);
        }
        // and it needs way to pick endpoints by name
        if (isClusteringEnabled && (this.getParentEndpoint() == null || !(this.getParentEndpoint() instanceof SALoadbalanceEndpoint))) {
            SALSessions.getInstance().registerChildren(this, getChildren());
        }
    }
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) SALSessions(org.apache.synapse.endpoints.dispatch.SALSessions)

Aggregations

ConfigurationContext (org.apache.axis2.context.ConfigurationContext)184 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)119 Axis2SynapseEnvironment (org.apache.synapse.core.axis2.Axis2SynapseEnvironment)70 Test (org.junit.Test)64 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)62 Parameter (org.apache.axis2.description.Parameter)56 SynapseEnvironment (org.apache.synapse.core.SynapseEnvironment)48 OMElement (org.apache.axiom.om.OMElement)43 AxisFault (org.apache.axis2.AxisFault)34 MessageContext (org.apache.synapse.MessageContext)34 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)31 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)30 AxisService (org.apache.axis2.description.AxisService)26 EndpointReference (org.apache.axis2.addressing.EndpointReference)24 MessageContext (org.apache.axis2.context.MessageContext)23 Options (org.apache.axis2.client.Options)22 HashMap (java.util.HashMap)20 ServiceContext (org.apache.axis2.context.ServiceContext)19 Map (java.util.Map)18 TransportOutDescription (org.apache.axis2.description.TransportOutDescription)16