Search in sources :

Example 1 with RecipientListEndpoint

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

the class RecipientListEndpointFactory method createEndpoint.

@Override
protected Endpoint createEndpoint(OMElement epConfig, boolean anonymousEndpoint, Properties properties) {
    OMElement recipientListElement = epConfig.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "recipientlist"));
    if (recipientListElement != null) {
        // create endpoint
        RecipientListEndpoint recipientListEndpoint = new RecipientListEndpoint();
        // set endpoint name
        OMAttribute name = epConfig.getAttribute(new QName(org.apache.synapse.config.xml.XMLConfigConstants.NULL_NAMESPACE, "name"));
        if (name != null) {
            recipientListEndpoint.setName(name.getAttributeValue());
        }
        // set endpoints or members
        if (recipientListElement.getFirstChildWithName(XMLConfigConstants.ENDPOINT_ELT) != null) {
            if (recipientListElement.getChildrenWithName((MEMBER)).hasNext()) {
                String msg = "Invalid Synapse configuration. " + "child elements";
                log.error(msg);
                throw new SynapseException(msg);
            }
            List<Endpoint> endpoints = getEndpoints(recipientListElement, recipientListEndpoint, properties);
            recipientListEndpoint.setChildren(endpoints);
        } else if (recipientListElement.getFirstChildWithName(MEMBER) != null) {
            if (recipientListElement.getChildrenWithName((XMLConfigConstants.ENDPOINT_ELT)).hasNext()) {
                String msg = "Invalid Synapse configuration. " + "recipientListElement element cannot have both member & endpoint " + "child elements";
                log.error(msg);
                throw new SynapseException(msg);
            }
            List<Member> members = getMembers(recipientListElement);
            recipientListEndpoint.setMembers(members);
        } else if (recipientListElement.getFirstChildWithName(DYNAMIC_SET) != null) {
            OMElement dynamicSetElement = recipientListElement.getFirstChildWithName(DYNAMIC_SET);
            Value dynamicEndpointSet = new ValueFactory().createValue("value", dynamicSetElement);
            String maxStr = dynamicSetElement.getAttributeValue(new QName("max-cache"));
            int maxCache = -1;
            try {
                maxCache = Integer.parseInt(maxStr);
            } catch (NumberFormatException e) {
            }
            recipientListEndpoint = new RecipientListEndpoint(maxCache < 0 ? RecipientListEndpoint.DEFAULT_MAX_POOL : maxCache);
            if (name != null) {
                recipientListEndpoint.setName(name.getAttributeValue());
            }
            recipientListEndpoint.setDynamicEnpointSet(dynamicEndpointSet);
        }
        if (recipientListEndpoint.getChildren() == null && recipientListEndpoint.getMembers() == null && recipientListEndpoint.getDynamicEnpointSet() == null) {
            String msg = "Invalid Synapse configuration.\n" + "A RecipientListEndpoint must have child/member elements, but the RecipientListEndpoint " + "'" + recipientListEndpoint.getName() + "' does not have any child/member/dynamic endpoint elements.";
            log.error(msg);
            throw new SynapseException(msg);
        }
        // process the parameters
        processProperties(recipientListEndpoint, epConfig);
        return recipientListEndpoint;
    }
    return null;
}
Also used : SynapseException(org.apache.synapse.SynapseException) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement) ValueFactory(org.apache.synapse.config.xml.ValueFactory) Endpoint(org.apache.synapse.endpoints.Endpoint) RecipientListEndpoint(org.apache.synapse.endpoints.RecipientListEndpoint) RecipientListEndpoint(org.apache.synapse.endpoints.RecipientListEndpoint) Endpoint(org.apache.synapse.endpoints.Endpoint) RecipientListEndpoint(org.apache.synapse.endpoints.RecipientListEndpoint) Value(org.apache.synapse.mediators.Value) ArrayList(java.util.ArrayList) List(java.util.List) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 2 with RecipientListEndpoint

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

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

the class RecipientListEndpointTest method test.

public void test() throws Exception {
    String inputXml = "<endpoint  xmlns=\"http://ws.apache.org/ns/synapse\">" + "<recipientlist>" + "<endpoint  xmlns=\"http://ws.apache.org/ns/synapse\">" + "<http uri-template=\"URI Template\" method=\"GET\" />" + "</endpoint>" + "</recipientlist>" + "</endpoint>";
    OMElement inputElement = createOMElement(inputXml);
    RecipientListEndpoint endpoint = (RecipientListEndpoint) RecipientListEndpointFactory.getEndpointFromElement(inputElement, true, null);
    OMElement serializedResponse = RecipientListEndpointSerializer.getElementFromEndpoint(endpoint);
    assertTrue("Endpoint not serialized!", compare(serializedResponse, inputElement));
}
Also used : RecipientListEndpoint(org.apache.synapse.endpoints.RecipientListEndpoint) OMElement(org.apache.axiom.om.OMElement)

Aggregations

OMElement (org.apache.axiom.om.OMElement)3 RecipientListEndpoint (org.apache.synapse.endpoints.RecipientListEndpoint)3 Endpoint (org.apache.synapse.endpoints.Endpoint)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 QName (javax.xml.namespace.QName)1 OMAttribute (org.apache.axiom.om.OMAttribute)1 Member (org.apache.axis2.clustering.Member)1 SynapseException (org.apache.synapse.SynapseException)1 ValueFactory (org.apache.synapse.config.xml.ValueFactory)1 ValueSerializer (org.apache.synapse.config.xml.ValueSerializer)1 Value (org.apache.synapse.mediators.Value)1