Search in sources :

Example 1 with HttpSessionDispatcher

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

the class DynamicLoadbalanceEndpointFactory method createEndpoint.

protected Endpoint createEndpoint(OMElement epConfig, boolean anonymousEndpoint, Properties properties) {
    OMElement loadbalanceElement = epConfig.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "dynamicLoadbalance"));
    if (loadbalanceElement != null) {
        DynamicLoadbalanceEndpoint loadbalanceEndpoint = new DynamicLoadbalanceEndpoint();
        // set endpoint name
        OMAttribute name = epConfig.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "name"));
        if (name != null) {
            loadbalanceEndpoint.setName(name.getAttributeValue());
        }
        // 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);
            }
            loadbalanceEndpoint.setSessionAffinity(true);
        }
        // set if failover is turned off
        String failover = loadbalanceElement.getAttributeValue(new QName("failover"));
        if (failover != null && failover.equalsIgnoreCase("false")) {
            loadbalanceEndpoint.setFailover(false);
        } else {
            loadbalanceEndpoint.setFailover(true);
        }
        OMElement eventHandler = loadbalanceElement.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "membershipHandler"));
        if (eventHandler != null) {
            String clazz = eventHandler.getAttributeValue(new QName(XMLConfigConstants.NULL_NAMESPACE, "class")).trim();
            try {
                LoadBalanceMembershipHandler lbMembershipHandler = (LoadBalanceMembershipHandler) Class.forName(clazz).newInstance();
                Properties lbProperties = new Properties();
                for (Iterator props = eventHandler.getChildrenWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "property")); props.hasNext(); ) {
                    OMElement prop = (OMElement) props.next();
                    String propName = prop.getAttributeValue(new QName(XMLConfigConstants.NULL_NAMESPACE, "name")).trim();
                    String propValue = prop.getAttributeValue(new QName(XMLConfigConstants.NULL_NAMESPACE, "value")).trim();
                    lbProperties.put(propName, propValue);
                }
                // Set load balance algorithm
                LoadbalanceAlgorithm algorithm = LoadbalanceAlgorithmFactory.createLoadbalanceAlgorithm(loadbalanceElement, null);
                lbMembershipHandler.init(lbProperties, algorithm);
                loadbalanceEndpoint.setLoadBalanceMembershipHandler(lbMembershipHandler);
            } catch (Exception e) {
                String msg = "Could not instantiate " + "LoadBalanceMembershipHandler implementation " + clazz;
                log.error(msg, e);
                throw new SynapseException(msg, e);
            }
        }
        processProperties(loadbalanceEndpoint, epConfig);
        return loadbalanceEndpoint;
    }
    return null;
}
Also used : SynapseException(org.apache.synapse.SynapseException) 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) Properties(java.util.Properties) DynamicLoadbalanceEndpoint(org.apache.synapse.endpoints.DynamicLoadbalanceEndpoint) SynapseException(org.apache.synapse.SynapseException) LoadBalanceMembershipHandler(org.apache.synapse.core.LoadBalanceMembershipHandler) Iterator(java.util.Iterator) LoadbalanceAlgorithm(org.apache.synapse.endpoints.algorithms.LoadbalanceAlgorithm) OMAttribute(org.apache.axiom.om.OMAttribute) HttpSessionDispatcher(org.apache.synapse.endpoints.dispatch.HttpSessionDispatcher) SoapSessionDispatcher(org.apache.synapse.endpoints.dispatch.SoapSessionDispatcher)

Example 2 with HttpSessionDispatcher

use of org.apache.synapse.endpoints.dispatch.HttpSessionDispatcher 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 HttpSessionDispatcher

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

the class ServiceDynamicLoadbalanceEndpointSerializer method serializeEndpoint.

protected OMElement serializeEndpoint(Endpoint endpoint) {
    if (!(endpoint instanceof ServiceDynamicLoadbalanceEndpoint)) {
        handleException("Invalid endpoint type.");
    }
    fac = OMAbstractFactory.getOMFactory();
    OMElement endpointElement = fac.createOMElement("endpoint", SynapseConstants.SYNAPSE_OMNAMESPACE);
    ServiceDynamicLoadbalanceEndpoint dynamicLoadbalanceEndpoint = (ServiceDynamicLoadbalanceEndpoint) endpoint;
    // serialize the parameters
    serializeProperties(dynamicLoadbalanceEndpoint, endpointElement);
    serializeCommonAttributes(endpoint, endpointElement);
    Dispatcher dispatcher = dynamicLoadbalanceEndpoint.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 = dynamicLoadbalanceEndpoint.getSessionTimeout();
        if (sessionTimeout != -1) {
            OMElement sessionTimeoutElement = fac.createOMElement("sessionTimeout", SynapseConstants.SYNAPSE_OMNAMESPACE);
            sessionTimeoutElement.setText(String.valueOf(sessionTimeout));
            sessionElement.addChild(sessionTimeoutElement);
        }
        endpointElement.addChild(sessionElement);
    }
    OMElement dynamicLoadbalanceElement = fac.createOMElement("serviceDynamicLoadbalance", SynapseConstants.SYNAPSE_OMNAMESPACE);
    endpointElement.addChild(dynamicLoadbalanceElement);
    // Load balance algorithm
    dynamicLoadbalanceElement.addAttribute(XMLConfigConstants.LOADBALANCE_ALGORITHM, dynamicLoadbalanceEndpoint.getAlgorithm().getClass().getName(), null);
    // Host-domain map
    OMElement servicesEle = fac.createOMElement("services", SynapseConstants.SYNAPSE_OMNAMESPACE);
    dynamicLoadbalanceElement.addChild(servicesEle);
    Map<String, String> hostDomainMap = dynamicLoadbalanceEndpoint.getHostDomainMap();
    for (Map.Entry<String, String> entry : hostDomainMap.entrySet()) {
        OMElement serviceEle = fac.createOMElement("service", SynapseConstants.SYNAPSE_OMNAMESPACE);
        servicesEle.addChild(serviceEle);
        OMElement hostEle = fac.createOMElement("host", SynapseConstants.SYNAPSE_OMNAMESPACE);
        hostEle.setText(entry.getKey());
        serviceEle.addChild(hostEle);
        OMElement domainEle = fac.createOMElement("domain", SynapseConstants.SYNAPSE_OMNAMESPACE);
        domainEle.setText(entry.getValue());
        serviceEle.addChild(domainEle);
    }
    return endpointElement;
}
Also used : ServiceDynamicLoadbalanceEndpoint(org.apache.synapse.endpoints.ServiceDynamicLoadbalanceEndpoint) 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) Map(java.util.Map) SoapSessionDispatcher(org.apache.synapse.endpoints.dispatch.SoapSessionDispatcher)

Example 4 with HttpSessionDispatcher

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

the class DynamicLoadbalanceEndpointSerializer method serializeEndpoint.

protected OMElement serializeEndpoint(Endpoint endpoint) {
    if (!(endpoint instanceof DynamicLoadbalanceEndpoint)) {
        handleException("Invalid endpoint type.");
    }
    fac = OMAbstractFactory.getOMFactory();
    OMElement endpointElement = fac.createOMElement("endpoint", SynapseConstants.SYNAPSE_OMNAMESPACE);
    DynamicLoadbalanceEndpoint dynamicLoadbalanceEndpoint = (DynamicLoadbalanceEndpoint) endpoint;
    // serialize the parameters
    serializeProperties(dynamicLoadbalanceEndpoint, endpointElement);
    serializeCommonAttributes(endpoint, endpointElement);
    Dispatcher dispatcher = dynamicLoadbalanceEndpoint.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 = dynamicLoadbalanceEndpoint.getSessionTimeout();
        if (sessionTimeout != -1) {
            OMElement sessionTimeoutElement = fac.createOMElement("sessionTimeout", SynapseConstants.SYNAPSE_OMNAMESPACE);
            sessionTimeoutElement.setText(String.valueOf(sessionTimeout));
            sessionElement.addChild(sessionTimeoutElement);
        }
        endpointElement.addChild(sessionElement);
    }
    OMElement dynamicLoadbalanceElement = fac.createOMElement("dynamicLoadbalance", SynapseConstants.SYNAPSE_OMNAMESPACE);
    endpointElement.addChild(dynamicLoadbalanceElement);
    // set if failover is turned off in the endpoint
    if (!dynamicLoadbalanceEndpoint.isFailover()) {
        dynamicLoadbalanceElement.addAttribute("failover", "false", null);
    }
    LoadBalanceMembershipHandler loadBalanceMembershipHandler = dynamicLoadbalanceEndpoint.getLbMembershipHandler();
    dynamicLoadbalanceElement.addAttribute(XMLConfigConstants.LOADBALANCE_ALGORITHM, loadBalanceMembershipHandler.getLoadbalanceAlgorithm().getClass().getName(), null);
    OMElement membershipHandlerElement = fac.createOMElement("membershipHandler", SynapseConstants.SYNAPSE_OMNAMESPACE);
    dynamicLoadbalanceElement.addChild(membershipHandlerElement);
    membershipHandlerElement.addAttribute("class", loadBalanceMembershipHandler.getClass().getName(), null);
    Properties membershipHandlerProperties = loadBalanceMembershipHandler.getProperties();
    OMElement propertyElement;
    for (Object property : membershipHandlerProperties.keySet()) {
        propertyElement = fac.createOMElement("property", SynapseConstants.SYNAPSE_OMNAMESPACE);
        membershipHandlerElement.addChild(propertyElement);
        propertyElement.addAttribute("name", property.toString(), null);
        propertyElement.addAttribute("value", membershipHandlerProperties.getProperty((String) property), null);
    }
    return endpointElement;
}
Also used : LoadBalanceMembershipHandler(org.apache.synapse.core.LoadBalanceMembershipHandler) 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) Properties(java.util.Properties) DynamicLoadbalanceEndpoint(org.apache.synapse.endpoints.DynamicLoadbalanceEndpoint) HttpSessionDispatcher(org.apache.synapse.endpoints.dispatch.HttpSessionDispatcher) SoapSessionDispatcher(org.apache.synapse.endpoints.dispatch.SoapSessionDispatcher)

Example 5 with HttpSessionDispatcher

use of org.apache.synapse.endpoints.dispatch.HttpSessionDispatcher 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)

Aggregations

HttpSessionDispatcher (org.apache.synapse.endpoints.dispatch.HttpSessionDispatcher)7 OMElement (org.apache.axiom.om.OMElement)6 Dispatcher (org.apache.synapse.endpoints.dispatch.Dispatcher)6 SoapSessionDispatcher (org.apache.synapse.endpoints.dispatch.SoapSessionDispatcher)6 SimpleClientSessionDispatcher (org.apache.synapse.endpoints.dispatch.SimpleClientSessionDispatcher)4 QName (javax.xml.namespace.QName)3 OMAttribute (org.apache.axiom.om.OMAttribute)3 LoadbalanceAlgorithm (org.apache.synapse.endpoints.algorithms.LoadbalanceAlgorithm)3 Properties (java.util.Properties)2 LoadBalanceMembershipHandler (org.apache.synapse.core.LoadBalanceMembershipHandler)2 DynamicLoadbalanceEndpoint (org.apache.synapse.endpoints.DynamicLoadbalanceEndpoint)2 Endpoint (org.apache.synapse.endpoints.Endpoint)2 SALoadbalanceEndpoint (org.apache.synapse.endpoints.SALoadbalanceEndpoint)2 ServiceDynamicLoadbalanceEndpoint (org.apache.synapse.endpoints.ServiceDynamicLoadbalanceEndpoint)2 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 StAXOMBuilder (org.apache.axiom.om.impl.builder.StAXOMBuilder)1