Search in sources :

Example 1 with SALoadbalanceEndpoint

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

the class SALSessions method createSessionInformation.

/*
     * Factory method to create a session information using given endpoint list,
     * session id and other informations
     */
private SessionInformation createSessionInformation(MessageContext synCtx, String id, List<Endpoint> endpoints) {
    if (endpoints == null || endpoints.isEmpty()) {
        handleException("Invalid request to create sessions . Cannot find a endpoint sequence.");
    }
    if (log.isDebugEnabled()) {
        log.debug("Creating a session information for given session id  " + id + " with endpoint sequence " + endpoints);
    }
    long expireTimeWindow = -1;
    if (endpoints != null) {
        for (Endpoint endpoint : endpoints) {
            if (endpoint instanceof SALoadbalanceEndpoint) {
                long sessionsTimeout = ((SALoadbalanceEndpoint) endpoint).getSessionTimeout();
                if (expireTimeWindow == -1) {
                    expireTimeWindow = sessionsTimeout;
                } else if (expireTimeWindow > sessionsTimeout) {
                    expireTimeWindow = sessionsTimeout;
                }
            }
        }
    }
    if (expireTimeWindow == -1) {
        expireTimeWindow = synCtx.getConfiguration().getProperty(SynapseConstants.PROP_SAL_ENDPOINT_DEFAULT_SESSION_TIMEOUT, SynapseConstants.SAL_ENDPOINTS_DEFAULT_SESSION_TIMEOUT);
    }
    if (log.isDebugEnabled()) {
        log.debug("For session with id " + id + " : expiry time interval : " + expireTimeWindow);
    }
    long expiryTime = System.currentTimeMillis() + expireTimeWindow;
    Endpoint rootEndpoint = endpoints.get(0);
    SessionInformation information = new SessionInformation(id, endpoints, expiryTime);
    if (isClustered) {
        List<String> epNameList = getEndpointNames(endpoints);
        information.setPath(epNameList);
        information.setRootEndpointName(getEndpointName(rootEndpoint));
    }
    return information;
}
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) SALoadbalanceEndpoint(org.apache.synapse.endpoints.SALoadbalanceEndpoint)

Example 2 with SALoadbalanceEndpoint

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

the class SALoadbalanceEndpointFactory method createEndpoint.

protected Endpoint createEndpoint(OMElement epConfig, boolean anonymousEndpoint, Properties properties) {
    // create the endpoint, manager and the algorithms
    SALoadbalanceEndpoint loadbalanceEndpoint = new SALoadbalanceEndpoint();
    // get the session for this endpoint
    OMElement sessionElement = epConfig.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "session"));
    if (sessionElement != null) {
        OMElement sessionTimeout = sessionElement.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "sessionTimeout"));
        if (sessionTimeout != null) {
            try {
                loadbalanceEndpoint.setSessionTimeout(Long.parseLong(sessionTimeout.getText().trim()));
            } catch (NumberFormatException nfe) {
                handleException("Invalid session timeout value : " + sessionTimeout.getText());
            }
        }
        String type = sessionElement.getAttributeValue(new QName("type"));
        if (type.equalsIgnoreCase("soap")) {
            Dispatcher soapDispatcher = new SoapSessionDispatcher();
            loadbalanceEndpoint.setDispatcher(soapDispatcher);
        } else if (type.equalsIgnoreCase("http")) {
            Dispatcher httpDispatcher = new HttpSessionDispatcher();
            loadbalanceEndpoint.setDispatcher(httpDispatcher);
        } else if (type.equalsIgnoreCase("simpleClientSession")) {
            Dispatcher csDispatcher = new SimpleClientSessionDispatcher();
            loadbalanceEndpoint.setDispatcher(csDispatcher);
        }
    } else {
        handleException("Session affinity endpoints should " + "have a session element in the configuration.");
    }
    // set endpoint name
    OMAttribute name = epConfig.getAttribute(new QName(org.apache.synapse.config.xml.XMLConfigConstants.NULL_NAMESPACE, "name"));
    if (name != null) {
        loadbalanceEndpoint.setName(name.getAttributeValue());
    }
    OMElement loadbalanceElement;
    loadbalanceElement = epConfig.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "loadbalance"));
    if (loadbalanceElement != null) {
        // set endpoints
        List<Endpoint> endpoints = getEndpoints(loadbalanceElement, loadbalanceEndpoint, properties);
        loadbalanceEndpoint.setChildren(endpoints);
        // set load balance algorithm
        LoadbalanceAlgorithm algorithm = LoadbalanceAlgorithmFactory.createLoadbalanceAlgorithm(loadbalanceElement, endpoints);
        loadbalanceEndpoint.setAlgorithm(algorithm);
        // set buildMessage attribute
        String buildMessageAtt = loadbalanceElement.getAttributeValue(new QName(XMLConfigConstants.BUILD_MESSAGE));
        if (buildMessageAtt != null) {
            loadbalanceEndpoint.setBuildMessageAttAvailable(true);
            if (JavaUtils.isTrueExplicitly(buildMessageAtt)) {
                loadbalanceEndpoint.setBuildMessageAtt(true);
            }
        }
        // process the parameters
        processProperties(loadbalanceEndpoint, epConfig);
        return loadbalanceEndpoint;
    }
    return null;
}
Also used : QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement) SoapSessionDispatcher(org.apache.synapse.endpoints.dispatch.SoapSessionDispatcher) Dispatcher(org.apache.synapse.endpoints.dispatch.Dispatcher) HttpSessionDispatcher(org.apache.synapse.endpoints.dispatch.HttpSessionDispatcher) SimpleClientSessionDispatcher(org.apache.synapse.endpoints.dispatch.SimpleClientSessionDispatcher) SimpleClientSessionDispatcher(org.apache.synapse.endpoints.dispatch.SimpleClientSessionDispatcher) SALoadbalanceEndpoint(org.apache.synapse.endpoints.SALoadbalanceEndpoint) Endpoint(org.apache.synapse.endpoints.Endpoint) SALoadbalanceEndpoint(org.apache.synapse.endpoints.SALoadbalanceEndpoint) LoadbalanceAlgorithm(org.apache.synapse.endpoints.algorithms.LoadbalanceAlgorithm) HttpSessionDispatcher(org.apache.synapse.endpoints.dispatch.HttpSessionDispatcher) OMAttribute(org.apache.axiom.om.OMAttribute) SoapSessionDispatcher(org.apache.synapse.endpoints.dispatch.SoapSessionDispatcher)

Example 3 with SALoadbalanceEndpoint

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

the class SALoadbalanceEndpointSerializer method serializeEndpoint.

protected OMElement serializeEndpoint(Endpoint endpoint) {
    if (!(endpoint instanceof SALoadbalanceEndpoint)) {
        handleException("Invalid endpoint type for serializing. " + "Expected: SALoadbalanceEndpoint Found: " + endpoint.getClass().getName());
    }
    SALoadbalanceEndpoint loadbalanceEndpoint = (SALoadbalanceEndpoint) endpoint;
    fac = OMAbstractFactory.getOMFactory();
    OMElement endpointElement = fac.createOMElement("endpoint", SynapseConstants.SYNAPSE_OMNAMESPACE);
    // serialize the parameters
    serializeProperties(loadbalanceEndpoint, endpointElement);
    serializeCommonAttributes(endpoint, endpointElement);
    OMElement loadbalanceElement = fac.createOMElement("loadbalance", SynapseConstants.SYNAPSE_OMNAMESPACE);
    endpointElement.addChild(loadbalanceElement);
    Dispatcher dispatcher = loadbalanceEndpoint.getDispatcher();
    if (dispatcher != null) {
        OMElement sessionElement = fac.createOMElement("session", SynapseConstants.SYNAPSE_OMNAMESPACE);
        if (dispatcher instanceof SoapSessionDispatcher) {
            sessionElement.addAttribute("type", "soap", null);
        } else if (dispatcher instanceof HttpSessionDispatcher) {
            sessionElement.addAttribute("type", "http", null);
        } else if (dispatcher instanceof SimpleClientSessionDispatcher) {
            sessionElement.addAttribute("type", "simpleClientSession", null);
        } else {
            handleException("invalid session dispatcher : " + dispatcher.getClass().getName());
        }
        long sessionTimeout = loadbalanceEndpoint.getSessionTimeout();
        if (sessionTimeout != -1) {
            OMElement sessionTimeoutElement = fac.createOMElement("sessionTimeout", SynapseConstants.SYNAPSE_OMNAMESPACE);
            sessionTimeoutElement.setText(String.valueOf(sessionTimeout));
            sessionElement.addChild(sessionTimeoutElement);
        }
        endpointElement.addChild(sessionElement);
    }
    loadbalanceElement.addAttribute(XMLConfigConstants.LOADBALANCE_ALGORITHM, loadbalanceEndpoint.getAlgorithm().getClass().getName(), null);
    if (loadbalanceEndpoint.isBuildMessageAtt()) {
        loadbalanceElement.addAttribute(XMLConfigConstants.BUILD_MESSAGE, Boolean.toString(loadbalanceEndpoint.isBuildMessageAtt()), null);
    }
    for (Endpoint childEndpoint : loadbalanceEndpoint.getChildren()) {
        loadbalanceElement.addChild(EndpointSerializer.getElementFromEndpoint(childEndpoint));
    }
    return endpointElement;
}
Also used : Endpoint(org.apache.synapse.endpoints.Endpoint) SALoadbalanceEndpoint(org.apache.synapse.endpoints.SALoadbalanceEndpoint) SALoadbalanceEndpoint(org.apache.synapse.endpoints.SALoadbalanceEndpoint) OMElement(org.apache.axiom.om.OMElement) HttpSessionDispatcher(org.apache.synapse.endpoints.dispatch.HttpSessionDispatcher) SoapSessionDispatcher(org.apache.synapse.endpoints.dispatch.SoapSessionDispatcher) Dispatcher(org.apache.synapse.endpoints.dispatch.Dispatcher) SimpleClientSessionDispatcher(org.apache.synapse.endpoints.dispatch.SimpleClientSessionDispatcher) SimpleClientSessionDispatcher(org.apache.synapse.endpoints.dispatch.SimpleClientSessionDispatcher) HttpSessionDispatcher(org.apache.synapse.endpoints.dispatch.HttpSessionDispatcher) SoapSessionDispatcher(org.apache.synapse.endpoints.dispatch.SoapSessionDispatcher)

Example 4 with SALoadbalanceEndpoint

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

the class SALSessions method createSessionInformation.

/*
     * Factory method to create a session information using given endpoint list, list of paths
     * session id and other informations
     */
private SessionInformation createSessionInformation(MessageContext synCtx, String id, List<Endpoint> endpoints, List<String> paths) {
    if (endpoints == null || endpoints.isEmpty()) {
        handleException("Invalid request to create sessions . Cannot find a endpoint sequence.");
    }
    if (log.isDebugEnabled()) {
        log.debug("Creating a session information for given session id  " + id + " with endpoint sequence " + endpoints);
    }
    long expireTimeWindow = -1;
    assert endpoints != null;
    for (Endpoint endpoint : endpoints) {
        if (endpoint instanceof SALoadbalanceEndpoint) {
            long sessionsTimeout = ((SALoadbalanceEndpoint) endpoint).getSessionTimeout();
            if (expireTimeWindow == -1) {
                expireTimeWindow = sessionsTimeout;
            } else if (expireTimeWindow > sessionsTimeout) {
                expireTimeWindow = sessionsTimeout;
            }
        }
    }
    if (expireTimeWindow == -1) {
        expireTimeWindow = synCtx.getConfiguration().getProperty(SynapseConstants.PROP_SAL_ENDPOINT_DEFAULT_SESSION_TIMEOUT, SynapseConstants.SAL_ENDPOINTS_DEFAULT_SESSION_TIMEOUT);
    }
    if (log.isDebugEnabled()) {
        log.debug("For session with id " + id + " : expiry time interval : " + expireTimeWindow);
    }
    long expiryTime = System.currentTimeMillis() + expireTimeWindow;
    Endpoint rootEndpoint = endpoints.get(0);
    SessionInformation information = new SessionInformation(id, endpoints, expiryTime);
    information.setPath(paths);
    if (isClustered) {
        information.setRootEndpointName(getEndpointName(rootEndpoint));
    }
    return information;
}
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) SALoadbalanceEndpoint(org.apache.synapse.endpoints.SALoadbalanceEndpoint)

Aggregations

Endpoint (org.apache.synapse.endpoints.Endpoint)4 SALoadbalanceEndpoint (org.apache.synapse.endpoints.SALoadbalanceEndpoint)4 OMElement (org.apache.axiom.om.OMElement)2 DynamicLoadbalanceEndpoint (org.apache.synapse.endpoints.DynamicLoadbalanceEndpoint)2 IndirectEndpoint (org.apache.synapse.endpoints.IndirectEndpoint)2 Dispatcher (org.apache.synapse.endpoints.dispatch.Dispatcher)2 HttpSessionDispatcher (org.apache.synapse.endpoints.dispatch.HttpSessionDispatcher)2 SimpleClientSessionDispatcher (org.apache.synapse.endpoints.dispatch.SimpleClientSessionDispatcher)2 SoapSessionDispatcher (org.apache.synapse.endpoints.dispatch.SoapSessionDispatcher)2 QName (javax.xml.namespace.QName)1 OMAttribute (org.apache.axiom.om.OMAttribute)1 LoadbalanceAlgorithm (org.apache.synapse.endpoints.algorithms.LoadbalanceAlgorithm)1