Search in sources :

Example 26 with Endpoint

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

the class RecipientListEndpointSerializer method serializeEndpoint.

@Override
protected OMElement serializeEndpoint(Endpoint endpoint) {
    if (!(endpoint instanceof RecipientListEndpoint)) {
        handleException("Invalid endpoint type.");
    }
    fac = OMAbstractFactory.getOMFactory();
    OMElement endpointElement = fac.createOMElement("endpoint", SynapseConstants.SYNAPSE_OMNAMESPACE);
    RecipientListEndpoint recipientListEndpoint = (RecipientListEndpoint) endpoint;
    // serialize the parameters
    serializeProperties(recipientListEndpoint, endpointElement);
    serializeCommonAttributes(endpoint, endpointElement);
    OMElement recipientListElement = fac.createOMElement("recipientlist", SynapseConstants.SYNAPSE_OMNAMESPACE);
    endpointElement.addChild(recipientListElement);
    // element
    if (recipientListEndpoint.getChildren() != null) {
        for (Endpoint childEndpoint : recipientListEndpoint.getChildren()) {
            recipientListElement.addChild(EndpointSerializer.getElementFromEndpoint(childEndpoint));
        }
    } else if (recipientListEndpoint.getMembers() != null) {
        for (Member member : recipientListEndpoint.getMembers()) {
            OMElement memberEle = fac.createOMElement("member", SynapseConstants.SYNAPSE_OMNAMESPACE, recipientListElement);
            memberEle.addAttribute(fac.createOMAttribute("hostName", null, member.getHostName()));
            memberEle.addAttribute(fac.createOMAttribute("httpPort", null, String.valueOf(member.getHttpPort())));
            memberEle.addAttribute(fac.createOMAttribute("httpsPort", null, String.valueOf(member.getHttpsPort())));
            recipientListElement.addChild(memberEle);
        }
    } else {
        OMElement dynamicEpEle = fac.createOMElement("endpoints", SynapseConstants.SYNAPSE_OMNAMESPACE, recipientListElement);
        new ValueSerializer().serializeValue(recipientListEndpoint.getDynamicEnpointSet(), "value", dynamicEpEle);
        dynamicEpEle.addAttribute(fac.createOMAttribute("max-cache", null, String.valueOf(recipientListEndpoint.getCurrentPoolSize())));
        recipientListElement.addChild(dynamicEpEle);
    }
    return endpointElement;
}
Also used : RecipientListEndpoint(org.apache.synapse.endpoints.RecipientListEndpoint) Endpoint(org.apache.synapse.endpoints.Endpoint) RecipientListEndpoint(org.apache.synapse.endpoints.RecipientListEndpoint) OMElement(org.apache.axiom.om.OMElement) Member(org.apache.axis2.clustering.Member) ValueSerializer(org.apache.synapse.config.xml.ValueSerializer)

Example 27 with Endpoint

use of org.apache.synapse.endpoints.Endpoint 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 28 with Endpoint

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

the class EndpointFactory method getEndpoints.

/**
 * Helper method to construct children endpoints
 *
 * @param listEndpointElement OMElement representing  the children endpoints
 * @param parent Parent endpoint
 * @param properties bag of properties to pass in any information to the factory
 * @return List of children endpoints
 */
protected ArrayList<Endpoint> getEndpoints(OMElement listEndpointElement, Endpoint parent, Properties properties) {
    ArrayList<Endpoint> endpoints = new ArrayList<Endpoint>();
    ArrayList<String> keys = new ArrayList<String>();
    Iterator iter = listEndpointElement.getChildrenWithName(XMLConfigConstants.ENDPOINT_ELT);
    while (iter.hasNext()) {
        OMElement endptElem = (OMElement) iter.next();
        Endpoint endpoint = EndpointFactory.getEndpointFromElement(endptElem, true, properties);
        if (endpoint instanceof IndirectEndpoint) {
            String key = ((IndirectEndpoint) endpoint).getKey();
            if (!keys.contains(key)) {
                keys.add(key);
            } else {
                handleException("Same endpoint definition cannot be used with in the siblings");
            }
        }
        endpoint.setParentEndpoint(parent);
        endpoints.add(endpoint);
    }
    return endpoints;
}
Also used : IndirectEndpoint(org.apache.synapse.endpoints.IndirectEndpoint) IndirectEndpoint(org.apache.synapse.endpoints.IndirectEndpoint) Endpoint(org.apache.synapse.endpoints.Endpoint) AbstractEndpoint(org.apache.synapse.endpoints.AbstractEndpoint) OMElement(org.apache.axiom.om.OMElement)

Example 29 with Endpoint

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

the class EndpointFactory method createEndpointWithName.

/**
 *  Make sure that the endpoints created by the factory has a name
 *
 * @param epConfig          OMElement containing the endpoint configuration.
 * @param anonymousEndpoint false if the endpoint has a name. true otherwise.
 * @param properties bag of properties to pass in any information to the factory
 * @return Endpoint implementation for the given configuration.
 */
private Endpoint createEndpointWithName(OMElement epConfig, boolean anonymousEndpoint, Properties properties) {
    Endpoint ep = createEndpoint(epConfig, anonymousEndpoint, properties);
    OMElement descriptionElem = epConfig.getFirstChildWithName(DESCRIPTION_Q);
    if (descriptionElem != null) {
        ep.setDescription(descriptionElem.getText());
    }
    // if the endpoint doesn't have a name we will generate a unique name.
    if (anonymousEndpoint && ep.getName() == null) {
        // ep.setName(ENDPOINT_NAME_PREFIX + uuid);
        if (ep instanceof AbstractEndpoint) {
            ((AbstractEndpoint) ep).setAnonymous(true);
        }
    }
    OMAttribute onFaultAtt = epConfig.getAttribute(ON_FAULT_Q);
    if (onFaultAtt != null) {
        ep.setErrorHandler(onFaultAtt.getAttributeValue());
    }
    return ep;
}
Also used : AbstractEndpoint(org.apache.synapse.endpoints.AbstractEndpoint) IndirectEndpoint(org.apache.synapse.endpoints.IndirectEndpoint) Endpoint(org.apache.synapse.endpoints.Endpoint) AbstractEndpoint(org.apache.synapse.endpoints.AbstractEndpoint) OMElement(org.apache.axiom.om.OMElement) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 30 with Endpoint

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

the class FailoverEndpointFactory method createEndpoint.

protected Endpoint createEndpoint(OMElement epConfig, boolean anonymousEndpoint, Properties properties) {
    OMElement failoverElement = epConfig.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "failover"));
    if (failoverElement != null) {
        FailoverEndpoint failoverEndpoint = new FailoverEndpoint();
        // set endpoint name
        String name = epConfig.getAttributeValue(new QName("name"));
        if (name != null) {
            failoverEndpoint.setName(name);
        }
        List<Endpoint> childEndpoints = getEndpoints(failoverElement, failoverEndpoint, properties);
        if (childEndpoints == null || childEndpoints.size() == 0) {
            String msg = "Invalid Synapse configuration.\n" + "A FailOver must have child elements, but the FailOver " + "'" + failoverEndpoint.getName() + "' does not have any child elements.";
            log.error(msg);
            throw new SynapseException(msg);
        }
        // set endpoints and return
        failoverEndpoint.setChildren(getEndpoints(failoverElement, failoverEndpoint, properties));
        String dynamicFO = failoverElement.getAttributeValue(new QName("dynamic"));
        if (dynamicFO != null && JavaUtils.isFalseExplicitly(dynamicFO)) {
            failoverEndpoint.setDynamic(false);
        }
        // set buildMassage property
        String buildMessageAtt = failoverElement.getAttributeValue(new QName(XMLConfigConstants.BUILD_MESSAGE));
        if (buildMessageAtt != null) {
            failoverEndpoint.setBuildMessageAttAvailable(true);
            if (JavaUtils.isTrueExplicitly(buildMessageAtt)) {
                failoverEndpoint.setBuildMessageAtt(true);
            }
        }
        // process the parameters
        processProperties(failoverEndpoint, epConfig);
        return failoverEndpoint;
    }
    return null;
}
Also used : Endpoint(org.apache.synapse.endpoints.Endpoint) FailoverEndpoint(org.apache.synapse.endpoints.FailoverEndpoint) SynapseException(org.apache.synapse.SynapseException) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement) FailoverEndpoint(org.apache.synapse.endpoints.FailoverEndpoint)

Aggregations

Endpoint (org.apache.synapse.endpoints.Endpoint)64 OMElement (org.apache.axiom.om.OMElement)22 SynapseException (org.apache.synapse.SynapseException)13 AddressEndpoint (org.apache.synapse.endpoints.AddressEndpoint)13 SequenceMediator (org.apache.synapse.mediators.base.SequenceMediator)11 ArrayList (java.util.ArrayList)10 MessageContext (org.apache.synapse.MessageContext)9 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)8 SynapseEnvironment (org.apache.synapse.core.SynapseEnvironment)8 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)8 IndirectEndpoint (org.apache.synapse.endpoints.IndirectEndpoint)8 SALoadbalanceEndpoint (org.apache.synapse.endpoints.SALoadbalanceEndpoint)8 InboundEndpoint (org.apache.synapse.inbound.InboundEndpoint)8 OMAttribute (org.apache.axiom.om.OMAttribute)7 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)7 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)7 Axis2SynapseEnvironment (org.apache.synapse.core.axis2.Axis2SynapseEnvironment)7 QName (javax.xml.namespace.QName)6 AbstractEndpoint (org.apache.synapse.endpoints.AbstractEndpoint)6 DynamicLoadbalanceEndpoint (org.apache.synapse.endpoints.DynamicLoadbalanceEndpoint)6