Search in sources :

Example 16 with Endpoint

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

the class CalloutMediatorSerializer method serializeSpecificMediator.

public OMElement serializeSpecificMediator(Mediator m) {
    if (!(m instanceof CalloutMediator)) {
        handleException("Unsupported mediator passed in for serialization : " + m.getType());
    }
    CalloutMediator mediator = (CalloutMediator) m;
    OMElement callout = fac.createOMElement("callout", synNS);
    saveTracingState(callout, mediator);
    if (mediator.getServiceURL() != null) {
        callout.addAttribute(fac.createOMAttribute("serviceURL", nullNS, mediator.getServiceURL()));
    } else if (mediator.getEndpointKey() != null) {
        callout.addAttribute(fac.createOMAttribute("endpointKey", nullNS, mediator.getEndpointKey()));
    }
    Endpoint endpoint = mediator.getEndpoint();
    if (endpoint != null) {
        callout.addChild(EndpointSerializer.getElementFromEndpoint(endpoint));
    }
    if (mediator.getAction() != null) {
        callout.addAttribute(fac.createOMAttribute("action", nullNS, mediator.getAction()));
    }
    if (mediator.getUseServerConfig() != null) {
        callout.addAttribute(fac.createOMAttribute("useServerConfig", nullNS, mediator.getUseServerConfig()));
    }
    if (!mediator.getInitClientOptions()) {
        callout.addAttribute(fac.createOMAttribute("initAxis2ClientOptions", nullNS, Boolean.toString(mediator.getInitClientOptions())));
    }
    if (mediator.getClientRepository() != null || mediator.getAxis2xml() != null) {
        OMElement config = fac.createOMElement("configuration", synNS);
        if (mediator.getClientRepository() != null) {
            config.addAttribute(fac.createOMAttribute("repository", nullNS, mediator.getClientRepository()));
        }
        if (mediator.getAxis2xml() != null) {
            config.addAttribute(fac.createOMAttribute("axis2xml", nullNS, mediator.getAxis2xml()));
        }
        callout.addChild(config);
    }
    if (mediator.isUseEnvelopeAsSource()) {
        OMElement source = fac.createOMElement("source", synNS, callout);
        source.addAttribute(fac.createOMAttribute("type", nullNS, "envelope"));
    } else if (mediator.getRequestXPath() != null) {
        OMElement source = fac.createOMElement("source", synNS, callout);
        SynapseXPathSerializer.serializeXPath(mediator.getRequestXPath(), source, "xpath");
    } else if (mediator.getRequestKey() != null) {
        OMElement source = fac.createOMElement("source", synNS, callout);
        source.addAttribute(fac.createOMAttribute("key", nullNS, mediator.getRequestKey()));
    }
    if (mediator.getTargetXPath() != null) {
        OMElement target = fac.createOMElement("target", synNS, callout);
        SynapseXPathSerializer.serializeXPath(mediator.getTargetXPath(), target, "xpath");
    } else if (mediator.getTargetKey() != null) {
        OMElement target = fac.createOMElement("target", synNS, callout);
        target.addAttribute(fac.createOMAttribute("key", nullNS, mediator.getTargetKey()));
    }
    if (mediator.isSecurityOn()) {
        OMElement security = fac.createOMElement("enableSec", synNS);
        if (mediator.getWsSecPolicyKey() != null) {
            security.addAttribute(fac.createOMAttribute("policy", nullNS, mediator.getWsSecPolicyKey()));
            callout.addChild(security);
        } else if (mediator.getOutboundWsSecPolicyKey() != null || mediator.getInboundWsSecPolicyKey() != null) {
            if (mediator.getOutboundWsSecPolicyKey() != null) {
                security.addAttribute(fac.createOMAttribute("outboundPolicy", nullNS, mediator.getOutboundWsSecPolicyKey()));
            }
            if (mediator.getInboundWsSecPolicyKey() != null) {
                security.addAttribute(fac.createOMAttribute("inboundPolicy", nullNS, mediator.getInboundWsSecPolicyKey()));
            }
            callout.addChild(security);
        }
    }
    return callout;
}
Also used : Endpoint(org.apache.synapse.endpoints.Endpoint) CalloutMediator(org.apache.synapse.mediators.builtin.CalloutMediator) OMElement(org.apache.axiom.om.OMElement)

Example 17 with Endpoint

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

the class SynapseConfiguration method getDefinedEndpoints.

/**
 * Returns the map of defined endpoints in the configuration excluding the
 * fetched endpoints from remote registry
 *
 * @return Map of Endpoints defined in the local configuration
 */
public Map<String, Endpoint> getDefinedEndpoints() {
    Map<String, Endpoint> definedEndpoints = new HashMap<String, Endpoint>();
    synchronized (this) {
        for (Object o : localRegistry.values()) {
            if (o instanceof Endpoint) {
                Endpoint ep = (Endpoint) o;
                definedEndpoints.put(ep.getName(), ep);
            }
        }
    }
    return definedEndpoints;
}
Also used : InboundEndpoint(org.apache.synapse.inbound.InboundEndpoint) Endpoint(org.apache.synapse.endpoints.Endpoint) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 18 with Endpoint

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

the class MultiXMLConfigurationBuilder method createEndpoints.

private static void createEndpoints(SynapseConfiguration synapseConfig, String rootDirPath, Properties properties) {
    File endpointsDir = new File(rootDirPath, ENDPOINTS_DIR);
    if (endpointsDir.exists()) {
        if (log.isDebugEnabled()) {
            log.debug("Loading endpoints from : " + endpointsDir.getPath());
        }
        Iterator endpoints = FileUtils.iterateFiles(endpointsDir, extensions, false);
        while (endpoints.hasNext()) {
            File file = (File) endpoints.next();
            try {
                OMElement document = getOMElement(file);
                Endpoint endpoint = SynapseXMLConfigurationFactory.defineEndpoint(synapseConfig, document, properties);
                if (endpoint != null) {
                    endpoint.setFileName(file.getName());
                    synapseConfig.getArtifactDeploymentStore().addArtifact(file.getAbsolutePath(), endpoint.getName());
                }
            } catch (Exception e) {
                String msg = "Endpoint configuration cannot be built from : " + file.getName();
                handleConfigurationError(SynapseConstants.FAIL_SAFE_MODE_EP, msg, e);
            }
        }
    }
}
Also used : Endpoint(org.apache.synapse.endpoints.Endpoint) InboundEndpoint(org.apache.synapse.inbound.InboundEndpoint) Iterator(java.util.Iterator) OMElement(org.apache.axiom.om.OMElement) XMLStreamException(javax.xml.stream.XMLStreamException) SynapseException(org.apache.synapse.SynapseException)

Example 19 with Endpoint

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

the class SynapseXMLConfigurationFactory method defineEndpoint.

public static Endpoint defineEndpoint(SynapseConfiguration config, OMElement ele, Properties properties) {
    String name = ele.getAttributeValue(new QName(XMLConfigConstants.NULL_NAMESPACE, "name"));
    Endpoint endpoint = null;
    if (name != null) {
        try {
            endpoint = EndpointFactory.getEndpointFromElement(ele, false, properties);
            if (endpoint != null) {
                config.addEndpoint(name.trim(), endpoint);
            }
        } catch (Exception e) {
            String msg = "Endpoint configuration: " + name + " cannot be built";
            handleConfigurationError(SynapseConstants.FAIL_SAFE_MODE_EP, msg, e);
        }
        return endpoint;
    } else {
        String msg = "Invalid endpoint definition without a name";
        handleConfigurationError(SynapseConstants.FAIL_SAFE_MODE_SEQUENCES, msg);
    }
    return null;
}
Also used : Endpoint(org.apache.synapse.endpoints.Endpoint) InboundEndpoint(org.apache.synapse.inbound.InboundEndpoint) QName(javax.xml.namespace.QName) SynapseException(org.apache.synapse.SynapseException)

Example 20 with Endpoint

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

the class SynapseXMLConfigurationSerializer method serializeConfiguration.

/**
 * Order of entries is irrelevant, however its nice to have some order.
 *
 * @param synCfg configuration to be serialized
 * @return serialized element of the configuration
 */
public OMElement serializeConfiguration(SynapseConfiguration synCfg) {
    OMElement definitions = fac.createOMElement("definitions", synNS);
    // first add the description
    if (synCfg.getDescription() != null) {
        OMElement descElem = fac.createOMElement("description", synNS);
        descElem.setText(synCfg.getDescription());
        definitions.addChild(descElem);
    }
    // then process a remote registry if present
    if (synCfg.getRegistry() != null) {
        RegistrySerializer.serializeRegistry(definitions, synCfg.getRegistry());
    }
    // then process a remote registry if present
    if (synCfg.getTaskManager() != null) {
        TaskManagerSerializer.serializetaskManager(definitions, synCfg.getTaskManager());
    }
    serializeImports(definitions, synCfg.getSynapseImports().values());
    // add proxy services
    Iterator itr = synCfg.getProxyServices().iterator();
    while (itr.hasNext()) {
        ProxyService service = (ProxyService) itr.next();
        ProxyServiceSerializer.serializeProxy(definitions, service);
    }
    // Add Event sources
    for (SynapseEventSource eventSource : synCfg.getEventSources()) {
        EventSourceSerializer.serializeEventSource(definitions, eventSource);
    }
    Map<String, Entry> entries = new HashMap<String, Entry>();
    Map<String, Endpoint> endpoints = new HashMap<String, Endpoint>();
    Map<String, SequenceMediator> sequences = new HashMap<String, SequenceMediator>();
    Map<String, TemplateMediator> templates = new HashMap<String, TemplateMediator>();
    Map<String, Template> endpointTemplates = new HashMap<String, Template>();
    itr = synCfg.getLocalRegistry().keySet().iterator();
    while (itr.hasNext()) {
        Object key = itr.next();
        if (SynapseConstants.SERVER_IP.equals(key) || SynapseConstants.SERVER_HOST.equals(key)) {
            continue;
        }
        Object o = synCfg.getLocalRegistry().get(key);
        if (o instanceof TemplateMediator) {
            templates.put(key.toString(), (TemplateMediator) o);
        } else if (o instanceof SequenceMediator) {
            sequences.put(key.toString(), (SequenceMediator) o);
        } else if (o instanceof Endpoint) {
            endpoints.put(key.toString(), (Endpoint) o);
        } else if (o instanceof Template) {
            endpointTemplates.put(key.toString(), (Template) o);
        } else if (o instanceof Entry) {
            entries.put(key.toString(), (Entry) o);
        } else {
            handleException("Unknown object : " + o.getClass() + " for serialization into Synapse configuration");
        }
    }
    // process entries
    serializeEntries(definitions, entries);
    // process endpoints
    serializeEndpoints(definitions, endpoints);
    // process sequences
    serializeSequences(definitions, sequences);
    // process templates
    serializeMediatorTemplates(definitions, templates);
    // serialize the endpoint templates
    serializeEndpointTemplates(definitions, endpointTemplates);
    // handle startups
    serializeStartups(definitions, synCfg.getStartups());
    // Executors
    serializeExecutors(definitions, synCfg.getPriorityExecutors());
    // Message stores
    serializeMessageStores(definitions, synCfg.getMessageStores());
    // Message Processors
    serializeMessageProcessors(definitions, synCfg.getMessageProcessors());
    serializeAPIs(definitions, synCfg.getAPIs());
    // XML comments
    serializeComments(definitions, synCfg.getCommentedTextList());
    if (synCfg.getInboundEndpoints() != null && synCfg.getInboundEndpoints().size() > 0) {
        Collection<InboundEndpoint> inboundEndpoints = synCfg.getInboundEndpoints();
        for (InboundEndpoint inboundEndpoint : inboundEndpoints) {
            InboundEndpointSerializer.serializeInboundEndpoint(definitions, inboundEndpoint);
        }
    }
    return definitions;
}
Also used : SynapseEventSource(org.apache.synapse.eventing.SynapseEventSource) Template(org.apache.synapse.endpoints.Template) InboundEndpoint(org.apache.synapse.inbound.InboundEndpoint) Entry(org.apache.synapse.config.Entry) Endpoint(org.apache.synapse.endpoints.Endpoint) InboundEndpoint(org.apache.synapse.inbound.InboundEndpoint) TemplateMediator(org.apache.synapse.mediators.template.TemplateMediator) ProxyService(org.apache.synapse.core.axis2.ProxyService) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator)

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