Search in sources :

Example 66 with OMAttribute

use of org.apache.axiom.om.OMAttribute 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 67 with OMAttribute

use of org.apache.axiom.om.OMAttribute 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 68 with OMAttribute

use of org.apache.axiom.om.OMAttribute 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 69 with OMAttribute

use of org.apache.axiom.om.OMAttribute in project wso2-synapse by wso2.

the class ResourceFactory method configureURLMappings.

private static void configureURLMappings(Resource resource, OMElement resourceElt) {
    OMAttribute urlMappingAtt = resourceElt.getAttribute(new QName("url-mapping"));
    OMAttribute uriTemplateAtt = resourceElt.getAttribute(new QName("uri-template"));
    if (urlMappingAtt != null && !"".equals(urlMappingAtt.getAttributeValue())) {
        resource.setDispatcherHelper(new URLMappingHelper(urlMappingAtt.getAttributeValue()));
    } else if (uriTemplateAtt != null && !"".equals(uriTemplateAtt.getAttributeValue())) {
        resource.setDispatcherHelper(new URITemplateHelper(uriTemplateAtt.getAttributeValue()));
    }
}
Also used : URITemplateHelper(org.apache.synapse.rest.dispatch.URITemplateHelper) QName(javax.xml.namespace.QName) URLMappingHelper(org.apache.synapse.rest.dispatch.URLMappingHelper) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 70 with OMAttribute

use of org.apache.axiom.om.OMAttribute in project wso2-synapse by wso2.

the class ResourceFactory method configureFilters.

private static void configureFilters(Resource resource, OMElement resourceElt) {
    OMAttribute protocolAtt = resourceElt.getAttribute(new QName("protocol"));
    if (protocolAtt != null && !"".equals(protocolAtt.getAttributeValue())) {
        if (Constants.TRANSPORT_HTTP.equals(protocolAtt.getAttributeValue())) {
            resource.setProtocol(RESTConstants.PROTOCOL_HTTP_ONLY);
        } else if (Constants.TRANSPORT_HTTPS.equals(protocolAtt.getAttributeValue())) {
            resource.setProtocol(RESTConstants.PROTOCOL_HTTPS_ONLY);
        } else {
            handleException("Invalid protocol name: " + protocolAtt.getAttributeValue());
        }
    }
    OMAttribute contentTypeAtt = resourceElt.getAttribute(new QName("content-type"));
    if (contentTypeAtt != null && !"".equals(contentTypeAtt.getAttributeValue())) {
        resource.setContentType(contentTypeAtt.getAttributeValue());
    }
    OMAttribute userAgentAtt = resourceElt.getAttribute(new QName("user-agent"));
    if (userAgentAtt != null && !"".equals(userAgentAtt.getAttributeValue())) {
        resource.setUserAgent(userAgentAtt.getAttributeValue());
    }
    OMAttribute methodsAtt = resourceElt.getAttribute(new QName("methods"));
    if (methodsAtt != null && !"".equals(methodsAtt.getAttributeValue())) {
        String[] methods = methodsAtt.getAttributeValue().trim().split(" ");
        for (String method : methods) {
            boolean added = resource.addMethod(method);
            if (!added) {
                handleException("Invalid or duplicate method definition for resource");
            }
        }
    }
}
Also used : QName(javax.xml.namespace.QName) OMAttribute(org.apache.axiom.om.OMAttribute)

Aggregations

OMAttribute (org.apache.axiom.om.OMAttribute)187 OMElement (org.apache.axiom.om.OMElement)116 QName (javax.xml.namespace.QName)82 Iterator (java.util.Iterator)41 OMFactory (org.apache.axiom.om.OMFactory)31 OMNamespace (org.apache.axiom.om.OMNamespace)28 SynapseException (org.apache.synapse.SynapseException)28 JaxenException (org.jaxen.JaxenException)28 OMNode (org.apache.axiom.om.OMNode)13 Value (org.apache.synapse.mediators.Value)12 SynapseXPath (org.apache.synapse.util.xpath.SynapseXPath)11 ArrayList (java.util.ArrayList)8 Endpoint (org.apache.synapse.endpoints.Endpoint)7 IOException (java.io.IOException)6 List (java.util.List)6 OMText (org.apache.axiom.om.OMText)6 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)6 StringReader (java.io.StringReader)5 SOAPHeaderBlock (org.apache.axiom.soap.SOAPHeaderBlock)5 EndpointDefinition (org.apache.synapse.endpoints.EndpointDefinition)5