Search in sources :

Example 31 with Endpoint

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

the class LoadbalanceEndpointFactory method createEndpoint.

protected Endpoint createEndpoint(OMElement epConfig, boolean anonymousEndpoint, Properties properties) {
    // create the endpoint, manager and the algorithms
    OMElement loadbalanceElement = epConfig.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "loadbalance"));
    if (loadbalanceElement != null) {
        LoadbalanceEndpoint loadbalanceEndpoint = new LoadbalanceEndpoint();
        // 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());
        }
        LoadbalanceAlgorithm algorithm = null;
        // set endpoints or members
        if (loadbalanceElement.getFirstChildWithName(XMLConfigConstants.ENDPOINT_ELT) != null) {
            if (loadbalanceElement.getChildrenWithName((MEMBER)).hasNext()) {
                String msg = "Invalid Synapse configuration. " + "child elements";
                log.error(msg);
                throw new SynapseException(msg);
            }
            List<Endpoint> endpoints = getEndpoints(loadbalanceElement, loadbalanceEndpoint, properties);
            loadbalanceEndpoint.setChildren(endpoints);
            algorithm = LoadbalanceAlgorithmFactory.createLoadbalanceAlgorithm(loadbalanceElement, endpoints);
            algorithm.setLoadBalanceEndpoint(loadbalanceEndpoint);
        } else if (loadbalanceElement.getFirstChildWithName(MEMBER) != null) {
            if (loadbalanceElement.getChildrenWithName((XMLConfigConstants.ENDPOINT_ELT)).hasNext()) {
                String msg = "Invalid Synapse configuration. " + "loadbalanceEndpoint element cannot have both member & endpoint " + "child elements";
                log.error(msg);
                throw new SynapseException(msg);
            }
            List<Member> members = getMembers(loadbalanceElement);
            loadbalanceEndpoint.setMembers(members);
            algorithm = LoadbalanceAlgorithmFactory.createLoadbalanceAlgorithm2(loadbalanceElement, members);
            loadbalanceEndpoint.startApplicationMembershipTimer();
        }
        if (loadbalanceEndpoint.getChildren() == null && loadbalanceEndpoint.getMembers() == null) {
            String msg = "Invalid Synapse configuration.\n" + "A LoadbalanceEndpoint must have child elements, but the LoadbalanceEndpoint " + "'" + loadbalanceEndpoint.getName() + "' does not have any child elements.";
            log.error(msg);
            throw new SynapseException(msg);
        }
        // set load balance algorithm
        loadbalanceEndpoint.setAlgorithm(algorithm);
        // set if failover is turned off
        String failover = loadbalanceElement.getAttributeValue(new QName("failover"));
        if (failover != null && failover.equalsIgnoreCase("false")) {
            loadbalanceEndpoint.setFailover(false);
        }
        // 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;
    }
    // ToDo
    return null;
}
Also used : LoadbalanceEndpoint(org.apache.synapse.endpoints.LoadbalanceEndpoint) SynapseException(org.apache.synapse.SynapseException) Endpoint(org.apache.synapse.endpoints.Endpoint) LoadbalanceEndpoint(org.apache.synapse.endpoints.LoadbalanceEndpoint) QName(javax.xml.namespace.QName) LoadbalanceAlgorithm(org.apache.synapse.endpoints.algorithms.LoadbalanceAlgorithm) OMElement(org.apache.axiom.om.OMElement) ArrayList(java.util.ArrayList) List(java.util.List) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 32 with Endpoint

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

the class LoadbalanceEndpointSerializer method serializeEndpoint.

protected OMElement serializeEndpoint(Endpoint endpoint) {
    if (!(endpoint instanceof LoadbalanceEndpoint)) {
        handleException("Invalid endpoint type.");
    }
    fac = OMAbstractFactory.getOMFactory();
    OMElement endpointElement = fac.createOMElement("endpoint", SynapseConstants.SYNAPSE_OMNAMESPACE);
    LoadbalanceEndpoint loadbalanceEndpoint = (LoadbalanceEndpoint) endpoint;
    serializeCommonAttributes(endpoint, endpointElement);
    OMElement loadbalanceElement = fac.createOMElement("loadbalance", SynapseConstants.SYNAPSE_OMNAMESPACE);
    endpointElement.addChild(loadbalanceElement);
    loadbalanceElement.addAttribute(XMLConfigConstants.LOADBALANCE_ALGORITHM, loadbalanceEndpoint.getAlgorithm().getClass().getName(), null);
    // set if failover is turned off in the endpoint
    if (!loadbalanceEndpoint.isFailover()) {
        loadbalanceElement.addAttribute("failover", "false", null);
    }
    if (loadbalanceEndpoint.isBuildMessageAtt()) {
        loadbalanceElement.addAttribute(XMLConfigConstants.BUILD_MESSAGE, Boolean.toString(loadbalanceEndpoint.isBuildMessageAtt()), null);
    }
    // Serialize endpoint elements which are children of the loadbalance element
    if (loadbalanceEndpoint.getChildren() != null) {
        for (Endpoint childEndpoint : loadbalanceEndpoint.getChildren()) {
            loadbalanceElement.addChild(EndpointSerializer.getElementFromEndpoint(childEndpoint));
        }
    } else {
        for (Member member : loadbalanceEndpoint.getMembers()) {
            OMElement memberEle = fac.createOMElement("member", SynapseConstants.SYNAPSE_OMNAMESPACE, loadbalanceElement);
            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())));
            loadbalanceElement.addChild(memberEle);
        }
    }
    // serialize the parameters
    serializeProperties(loadbalanceEndpoint, endpointElement);
    return endpointElement;
}
Also used : LoadbalanceEndpoint(org.apache.synapse.endpoints.LoadbalanceEndpoint) Endpoint(org.apache.synapse.endpoints.Endpoint) LoadbalanceEndpoint(org.apache.synapse.endpoints.LoadbalanceEndpoint) OMElement(org.apache.axiom.om.OMElement) Member(org.apache.axis2.clustering.Member)

Example 33 with Endpoint

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

the class MultiXMLConfigurationSerializer method serializeLocalEntry.

public OMElement serializeLocalEntry(Object o, SynapseConfiguration synapseConfig, OMElement parent) throws Exception {
    if (o instanceof TemplateMediator) {
        return serializeTemplate((TemplateMediator) o, synapseConfig, parent);
    } else if (o instanceof SequenceMediator) {
        return serializeSequence((SequenceMediator) o, synapseConfig, parent);
    } else if (o instanceof Template) {
        return serializeTemplate((Template) o, synapseConfig, parent);
    } else if (o instanceof Endpoint) {
        return serializeEndpoint((Endpoint) o, synapseConfig, parent);
    } else if (o instanceof Entry) {
        Entry entry = (Entry) o;
        if ((SynapseConstants.SERVER_HOST.equals(entry.getKey()) || SynapseConstants.SERVER_IP.equals(entry.getKey())) || entry.getType() == Entry.REMOTE_ENTRY) {
            return null;
        }
        File entriesDir = createDirectory(currentDirectory, MultiXMLConfigurationBuilder.LOCAL_ENTRY_DIR);
        OMElement entryElem = EntrySerializer.serializeEntry(entry, null);
        String fileName = entry.getFileName();
        if (fileName != null) {
            if (currentDirectory == rootDirectory) {
                handleDeployment(entriesDir, fileName, entry.getKey(), synapseConfig.getArtifactDeploymentStore());
            }
            File entryFile = new File(entriesDir, fileName);
            writeToFile(entryElem, entryFile);
        } else if (parent != null) {
            parent.addChild(entryElem);
        }
        return entryElem;
    }
    return null;
}
Also used : Entry(org.apache.synapse.config.Entry) TemplateMediator(org.apache.synapse.mediators.template.TemplateMediator) Endpoint(org.apache.synapse.endpoints.Endpoint) AbstractEndpoint(org.apache.synapse.endpoints.AbstractEndpoint) InboundEndpoint(org.apache.synapse.inbound.InboundEndpoint) OMElement(org.apache.axiom.om.OMElement) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) Template(org.apache.synapse.endpoints.Template)

Example 34 with Endpoint

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

the class SendMediatorFactory method createSpecificMediator.

public Mediator createSpecificMediator(OMElement elem, Properties properties) {
    SendMediator sm = new SendMediator();
    // after successfully creating the mediator
    // set its common attributes such as tracing etc
    processAuditStatus(sm, elem);
    OMElement epElement = elem.getFirstChildWithName(ENDPOINT_Q);
    if (epElement != null) {
        // create the endpoint and set it in the send mediator
        Endpoint endpoint = EndpointFactory.getEndpointFromElement(epElement, true, properties);
        if (endpoint != null) {
            sm.setEndpoint(endpoint);
        }
    }
    String receivingSequence = elem.getAttributeValue(RECEIVING_SEQUENCE);
    if (receivingSequence != null) {
        ValueFactory valueFactory = new ValueFactory();
        Value value = valueFactory.createValue(XMLConfigConstants.RECEIVE, elem);
        sm.setReceivingSequence(value);
    }
    String buildMessage = elem.getAttributeValue(BUILD_MESSAGE);
    if ("true".equals(buildMessage)) {
        sm.setBuildMessage(true);
    }
    return sm;
}
Also used : Endpoint(org.apache.synapse.endpoints.Endpoint) Value(org.apache.synapse.mediators.Value) OMElement(org.apache.axiom.om.OMElement) SendMediator(org.apache.synapse.mediators.builtin.SendMediator)

Example 35 with Endpoint

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

the class CallMediatorFactory method createSpecificMediator.

public Mediator createSpecificMediator(OMElement elem, Properties properties) {
    CallMediator callMediator = new CallMediator();
    // after successfully creating the mediator
    // set its common attributes such as tracing etc
    processAuditStatus(callMediator, elem);
    OMElement epElement = elem.getFirstChildWithName(ENDPOINT_Q);
    if (epElement != null) {
        // create the endpoint and set it in the call mediator
        Endpoint endpoint = EndpointFactory.getEndpointFromElement(epElement, true, properties);
        if (endpoint != null) {
            callMediator.setEndpoint(endpoint);
        }
    }
    OMAttribute blockingAtt = elem.getAttribute(BLOCKING_Q);
    if (blockingAtt != null) {
        callMediator.setBlocking(Boolean.parseBoolean(blockingAtt.getAttributeValue()));
        if (callMediator.isBlocking()) {
            OMAttribute initAxis2ClientOptions = elem.getAttribute(ATT_INIT_AXIS2_CLIENT_OPTIONS);
            OMAttribute axis2xmlAttr = elem.getAttribute(ATT_AXIS2XML);
            OMAttribute repoAttr = elem.getAttribute(ATT_REPOSITORY);
            if (initAxis2ClientOptions != null) {
                callMediator.setInitClientOptions(Boolean.parseBoolean(initAxis2ClientOptions.getAttributeValue()));
            }
            if (axis2xmlAttr != null && axis2xmlAttr.getAttributeValue() != null) {
                File axis2xml = new File(axis2xmlAttr.getAttributeValue());
                if (axis2xml.exists() && axis2xml.isFile()) {
                    callMediator.setAxis2xml(axis2xmlAttr.getAttributeValue());
                } else {
                    handleException("Invalid axis2.xml path: " + axis2xmlAttr.getAttributeValue());
                }
            }
            if (repoAttr != null && repoAttr.getAttributeValue() != null) {
                File repo = new File(repoAttr.getAttributeValue());
                if (repo.exists() && repo.isDirectory()) {
                    callMediator.setClientRepository(repoAttr.getAttributeValue());
                } else {
                    handleException("Invalid repository path: " + repoAttr.getAttributeValue());
                }
            }
        }
    }
    return callMediator;
}
Also used : Endpoint(org.apache.synapse.endpoints.Endpoint) OMElement(org.apache.axiom.om.OMElement) CallMediator(org.apache.synapse.mediators.builtin.CallMediator) OMAttribute(org.apache.axiom.om.OMAttribute) File(java.io.File)

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