Search in sources :

Example 36 with Endpoint

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

the class CallMediatorSerializer method serializeSpecificMediator.

public OMElement serializeSpecificMediator(Mediator m) {
    if (!(m instanceof CallMediator)) {
        handleException("Unsupported mediator passed in for serialization : " + m.getType());
    }
    CallMediator mediator = (CallMediator) m;
    OMElement call = fac.createOMElement("call", synNS);
    saveTracingState(call, mediator);
    Endpoint activeEndpoint = mediator.getEndpoint();
    if (activeEndpoint != null) {
        call.addChild(EndpointSerializer.getElementFromEndpoint(activeEndpoint));
    }
    if (mediator.isBlocking()) {
        call.addAttribute(fac.createOMAttribute("blocking", nullNS, "true"));
        if (!mediator.getInitClientOptions()) {
            call.addAttribute(fac.createOMAttribute("initAxis2ClientOptions", nullNS, "false"));
        }
        if (mediator.getClientRepository() != null) {
            call.addAttribute(fac.createOMAttribute("repository", nullNS, mediator.getClientRepository()));
        }
        if (mediator.getAxis2xml() != null) {
            call.addAttribute(fac.createOMAttribute("axis2xml", nullNS, mediator.getAxis2xml()));
        }
    }
    return call;
}
Also used : Endpoint(org.apache.synapse.endpoints.Endpoint) OMElement(org.apache.axiom.om.OMElement) CallMediator(org.apache.synapse.mediators.builtin.CallMediator)

Example 37 with Endpoint

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

the class CalloutMediatorFactory method createSpecificMediator.

public Mediator createSpecificMediator(OMElement elem, Properties properties) {
    CalloutMediator callout = new CalloutMediator();
    processAuditStatus(callout, elem);
    OMAttribute attServiceURL = elem.getAttribute(ATT_URL);
    OMAttribute attEndpoint = elem.getAttribute(ATT_ENDPOINT);
    OMAttribute attAction = elem.getAttribute(ATT_ACTION);
    OMAttribute attUseServerConfig = elem.getAttribute(ATT_USESERVERCONFIG);
    OMAttribute initAxis2ClientOptions = elem.getAttribute(ATT_INIT_AXI2_CLIENT_OPTIONS);
    OMElement configElt = elem.getFirstChildWithName(Q_CONFIG);
    OMElement epElement = elem.getFirstChildWithName(Q_ENDPOINT);
    OMElement sourceElt = elem.getFirstChildWithName(Q_SOURCE);
    OMElement targetElt = elem.getFirstChildWithName(Q_TARGET);
    OMElement wsSec = elem.getFirstChildWithName(Q_SEC);
    if (attServiceURL != null) {
        callout.setServiceURL(attServiceURL.getAttributeValue());
    } else if (attEndpoint != null) {
        callout.setEndpointKey(attEndpoint.getAttributeValue());
    }
    if (epElement != null) {
        Endpoint endpoint = EndpointFactory.getEndpointFromElement(epElement, true, properties);
        if (endpoint != null) {
            callout.setEndpoint(endpoint);
        }
    }
    if (attAction != null) {
        callout.setAction(attAction.getAttributeValue());
    }
    if (attUseServerConfig != null) {
        callout.setUseServerConfig(attUseServerConfig.getAttributeValue());
    }
    if (initAxis2ClientOptions != null) {
        if ("true".equals(initAxis2ClientOptions.getAttributeValue().toLowerCase())) {
            callout.setInitClientOptions(true);
        } else if ("false".equals(initAxis2ClientOptions.getAttributeValue().toLowerCase())) {
            callout.setInitClientOptions(false);
        } else {
            handleException("The 'initAxis2ClientOptions' attribute only accepts a boolean value.");
        }
    }
    if (configElt != null) {
        OMAttribute axis2xmlAttr = configElt.getAttribute(ATT_AXIS2XML);
        OMAttribute repoAttr = configElt.getAttribute(ATT_REPOSITORY);
        if (axis2xmlAttr != null && axis2xmlAttr.getAttributeValue() != null) {
            File axis2xml = new File(axis2xmlAttr.getAttributeValue());
            if (axis2xml.exists() && axis2xml.isFile()) {
                callout.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()) {
                callout.setClientRepository(repoAttr.getAttributeValue());
            } else {
                handleException("Invalid repository path: " + repoAttr.getAttributeValue());
            }
        }
    }
    if (sourceElt != null) {
        OMAttribute sourceType = sourceElt.getAttribute(ATT_SOURCE_TYPE);
        if (sourceType != null && sourceType.getAttributeValue().equals("envelope")) {
            callout.setUseEnvelopeAsSource(true);
        } else if (sourceElt.getAttribute(ATT_XPATH) != null) {
            try {
                callout.setRequestXPath(SynapseXPathFactory.getSynapseXPath(sourceElt, ATT_XPATH));
            } catch (JaxenException e) {
                handleException("Invalid source XPath : " + sourceElt.getAttributeValue(ATT_XPATH));
            }
        } else if (sourceElt.getAttribute(ATT_KEY) != null) {
            callout.setRequestKey(sourceElt.getAttributeValue(ATT_KEY));
        } else {
            handleException("A 'xpath' or 'key' attribute " + "is required for the Callout 'source'");
        }
    } else {
        callout.setUseEnvelopeAsSource(true);
    }
    if (targetElt != null) {
        if (targetElt.getAttribute(ATT_XPATH) != null) {
            try {
                callout.setTargetXPath(SynapseXPathFactory.getSynapseXPath(targetElt, ATT_XPATH));
            } catch (JaxenException e) {
                handleException("Invalid target XPath : " + targetElt.getAttributeValue(ATT_XPATH));
            }
        } else if (targetElt.getAttribute(ATT_KEY) != null) {
            callout.setTargetKey(targetElt.getAttributeValue(ATT_KEY));
        } else {
            handleException("A 'xpath' or 'key' attribute " + "is required for the Callout 'target'");
        }
    }
    if (wsSec != null) {
        callout.setSecurityOn(true);
        OMAttribute policyKey = wsSec.getAttribute(ATT_POLICY);
        OMAttribute outboundPolicyKey = wsSec.getAttribute(ATT_OUTBOUND_SEC_POLICY);
        OMAttribute inboundPolicyKey = wsSec.getAttribute(ATT_INBOUND_SEC_POLICY);
        if (policyKey != null) {
            callout.setWsSecPolicyKey(policyKey.getAttributeValue());
        } else if (outboundPolicyKey != null || inboundPolicyKey != null) {
            if (outboundPolicyKey != null) {
                callout.setOutboundWsSecPolicyKey(outboundPolicyKey.getAttributeValue());
            }
            if (inboundPolicyKey != null) {
                callout.setInboundWsSecPolicyKey(inboundPolicyKey.getAttributeValue());
            }
        } else {
            callout.setSecurityOn(false);
            handleException("A policy key is required to enable security");
        }
    }
    return callout;
}
Also used : Endpoint(org.apache.synapse.endpoints.Endpoint) CalloutMediator(org.apache.synapse.mediators.builtin.CalloutMediator) JaxenException(org.jaxen.JaxenException) OMElement(org.apache.axiom.om.OMElement) OMAttribute(org.apache.axiom.om.OMAttribute) File(java.io.File)

Example 38 with Endpoint

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

the class CloneMediator method destroy.

public void destroy() {
    for (Target target : targets) {
        ManagedLifecycle seq = target.getSequence();
        if (seq != null) {
            seq.destroy();
        } else if (target.getSequenceRef() != null) {
            SequenceMediator targetSequence = (SequenceMediator) synapseEnv.getSynapseConfiguration().getSequence(target.getSequenceRef());
            if (targetSequence == null || targetSequence.isDynamic()) {
                synapseEnv.removeUnavailableArtifactRef(target.getSequenceRef());
            }
        }
        Endpoint endpoint = target.getEndpoint();
        if (endpoint != null) {
            endpoint.destroy();
        }
    }
}
Also used : Target(org.apache.synapse.mediators.eip.Target) Endpoint(org.apache.synapse.endpoints.Endpoint) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) ManagedLifecycle(org.apache.synapse.ManagedLifecycle)

Example 39 with Endpoint

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

the class IterateMediator method init.

public void init(SynapseEnvironment se) {
    synapseEnv = se;
    if (target != null) {
        Endpoint endpoint = target.getEndpoint();
        if (endpoint != null) {
            endpoint.init(se);
        }
        ManagedLifecycle seq = target.getSequence();
        if (seq != null) {
            seq.init(se);
        } else if (target.getSequenceRef() != null) {
            SequenceMediator targetSequence = (SequenceMediator) se.getSynapseConfiguration().getSequence(target.getSequenceRef());
            if (targetSequence == null || targetSequence.isDynamic()) {
                se.addUnavailableArtifactRef(target.getSequenceRef());
            }
        }
    }
}
Also used : Endpoint(org.apache.synapse.endpoints.Endpoint) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) ManagedLifecycle(org.apache.synapse.ManagedLifecycle)

Example 40 with Endpoint

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

the class IterateMediator method destroy.

public void destroy() {
    if (target != null) {
        Endpoint endpoint = target.getEndpoint();
        if (endpoint != null && endpoint.isInitialized()) {
            endpoint.destroy();
        }
        ManagedLifecycle seq = target.getSequence();
        if (seq != null) {
            seq.destroy();
        } else if (target.getSequenceRef() != null) {
            SequenceMediator targetSequence = (SequenceMediator) synapseEnv.getSynapseConfiguration().getSequence(target.getSequenceRef());
            if (targetSequence == null || targetSequence.isDynamic()) {
                synapseEnv.removeUnavailableArtifactRef(target.getSequenceRef());
            }
        }
    }
}
Also used : Endpoint(org.apache.synapse.endpoints.Endpoint) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) ManagedLifecycle(org.apache.synapse.ManagedLifecycle)

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