use of org.apache.synapse.mediators.base.SequenceMediator 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;
}
use of org.apache.synapse.mediators.base.SequenceMediator in project wso2-synapse by wso2.
the class ProxyServiceSerializer method serializeProxy.
public static OMElement serializeProxy(OMElement parent, ProxyService service) {
OMElement proxy = fac.createOMElement("proxy", synNS);
if (service.getName() != null) {
proxy.addAttribute(fac.createOMAttribute("name", nullNS, service.getName()));
} else {
handleException("Invalid proxy service. Service name is required");
}
String descriptionStr = service.getDescription();
if (descriptionStr != null) {
OMElement description = fac.createOMElement("description", synNS);
description.addChild(fac.createOMText(descriptionStr));
proxy.addChild(description);
}
ArrayList transports = service.getTransports();
if (transports != null && !transports.isEmpty()) {
String transportStr = "" + transports.get(0);
for (int i = 1; i < transports.size(); i++) {
transportStr = transportStr.concat(" " + transports.get(i));
}
proxy.addAttribute(fac.createOMAttribute("transports", nullNS, transportStr));
}
if (service.getServiceGroup() != null) {
proxy.addAttribute(fac.createOMAttribute("serviceGroup", nullNS, service.getServiceGroup()));
}
List pinnedServers = service.getPinnedServers();
if (pinnedServers != null && !pinnedServers.isEmpty()) {
String pinnedServersStr = "" + pinnedServers.get(0);
for (int i = 1; i < pinnedServers.size(); i++) {
pinnedServersStr = pinnedServersStr.concat(" " + pinnedServers.get(i));
}
proxy.addAttribute(fac.createOMAttribute("pinnedServers", nullNS, pinnedServersStr));
}
if (service.isStartOnLoad()) {
proxy.addAttribute(fac.createOMAttribute("startOnLoad", nullNS, "true"));
} else {
proxy.addAttribute(fac.createOMAttribute("startOnLoad", nullNS, "false"));
}
String endpoint = service.getTargetEndpoint();
OMElement target = fac.createOMElement("target", synNS);
Endpoint inLineEndpoint = service.getTargetInLineEndpoint();
if (endpoint != null) {
target.addAttribute(fac.createOMAttribute("endpoint", nullNS, endpoint));
proxy.addChild(target);
} else if (inLineEndpoint != null) {
OMElement epElement = EndpointSerializer.getElementFromEndpoint(inLineEndpoint);
target.addChild(epElement);
proxy.addChild(target);
}
String inSeq = service.getTargetInSequence();
String outSeq = service.getTargetOutSequence();
String faultSeq = service.getTargetFaultSequence();
SequenceMediatorSerializer serializer = new SequenceMediatorSerializer();
if (inSeq != null) {
target.addAttribute(fac.createOMAttribute("inSequence", nullNS, inSeq));
proxy.addChild(target);
} else {
SequenceMediator inLineInSeq = service.getTargetInLineInSequence();
if (inLineInSeq != null) {
OMElement inSeqElement = serializer.serializeAnonymousSequence(null, inLineInSeq);
inSeqElement.setLocalName("inSequence");
target.addChild(inSeqElement);
proxy.addChild(target);
}
}
if (outSeq != null) {
target.addAttribute(fac.createOMAttribute("outSequence", nullNS, outSeq));
proxy.addChild(target);
} else {
SequenceMediator inLineOutSeq = service.getTargetInLineOutSequence();
if (inLineOutSeq != null) {
OMElement outSeqElement = serializer.serializeAnonymousSequence(null, inLineOutSeq);
outSeqElement.setLocalName("outSequence");
target.addChild(outSeqElement);
proxy.addChild(target);
}
}
if (faultSeq != null) {
target.addAttribute(fac.createOMAttribute("faultSequence", nullNS, faultSeq));
proxy.addChild(target);
} else {
SequenceMediator inLineFaultSeq = service.getTargetInLineFaultSequence();
if (inLineFaultSeq != null) {
OMElement faultSeqElement = serializer.serializeAnonymousSequence(null, inLineFaultSeq);
faultSeqElement.setLocalName("faultSequence");
target.addChild(faultSeqElement);
proxy.addChild(target);
}
}
String wsdlKey = service.getWSDLKey();
String wsdlEndpoint = service.getPublishWSDLEndpoint();
String preservePolicy = service.getPreservePolicy();
URI wsdlUri = service.getWsdlURI();
Object inLineWSDL = service.getInLineWSDL();
if (wsdlKey != null || wsdlUri != null || inLineWSDL != null || wsdlEndpoint != null) {
OMElement wsdl = fac.createOMElement("publishWSDL", synNS);
if (wsdlEndpoint != null) {
wsdl.addAttribute(fac.createOMAttribute("endpoint", nullNS, wsdlEndpoint));
} else if (wsdlKey != null) {
wsdl.addAttribute(fac.createOMAttribute("key", nullNS, wsdlKey));
} else if (inLineWSDL != null) {
wsdl.addChild((OMNode) inLineWSDL);
} else if (wsdlUri != null) {
wsdl.addAttribute(fac.createOMAttribute("uri", nullNS, wsdlUri.toString()));
}
if (preservePolicy != null) {
wsdl.addAttribute(fac.createOMAttribute("preservePolicy", nullNS, preservePolicy));
}
ResourceMapSerializer.serializeResourceMap(wsdl, service.getResourceMap());
proxy.addChild(wsdl);
}
for (PolicyInfo pi : service.getPolicies()) {
OMElement policy = fac.createOMElement("policy", synNS);
if (pi.getPolicyKey() != null) {
policy.addAttribute(fac.createOMAttribute("key", nullNS, pi.getPolicyKey()));
} else {
handleException("Policy without a key has been found");
}
if (pi.getOperation() != null) {
policy.addAttribute(fac.createOMAttribute("operationName", nullNS, pi.getOperation().getLocalPart()));
if (pi.getOperation().getNamespaceURI() != null) {
policy.addAttribute(fac.createOMAttribute("operationNamespace", nullNS, pi.getOperation().getNamespaceURI()));
}
}
if (pi.getType() != 0) {
policy.addAttribute(fac.createOMAttribute("type", nullNS, pi.getMessageLable().toLowerCase()));
}
proxy.addChild(policy);
}
for (String propertyName : service.getParameterMap().keySet()) {
OMElement property = fac.createOMElement("parameter", synNS);
property.addAttribute(fac.createOMAttribute("name", nullNS, propertyName));
Object value = service.getParameterMap().get(propertyName);
if (value != null) {
if (value instanceof String) {
property.setText(((String) value).trim());
proxy.addChild(property);
} else if (value instanceof OMNode) {
property.addChild((OMNode) value);
proxy.addChild(property);
}
}
}
if (service.isWsAddrEnabled()) {
proxy.addChild(fac.createOMElement("enableAddressing", synNS));
}
if (service.isWsSecEnabled()) {
proxy.addChild(fac.createOMElement("enableSec", synNS));
}
StatisticsConfigurable statisticsConfigurable = service.getAspectConfiguration();
if (statisticsConfigurable != null && statisticsConfigurable.isStatisticsEnable()) {
proxy.addAttribute(fac.createOMAttribute(XMLConfigConstants.STATISTICS_ATTRIB_NAME, nullNS, XMLConfigConstants.STATISTICS_ENABLE));
}
if (statisticsConfigurable != null && statisticsConfigurable.isTracingEnabled()) {
proxy.addAttribute(fac.createOMAttribute(XMLConfigConstants.TRACE_ATTRIB_NAME, nullNS, XMLConfigConstants.TRACE_ENABLE));
}
if (parent != null) {
parent.addChild(proxy);
}
return proxy;
}
use of org.apache.synapse.mediators.base.SequenceMediator in project wso2-synapse by wso2.
the class SequenceMediatorFactory method createSpecificMediator.
public Mediator createSpecificMediator(OMElement elem, Properties properties) {
SequenceMediator seqMediator = new SequenceMediator();
OMAttribute n = elem.getAttribute(ATT_NAME);
OMAttribute e = elem.getAttribute(ATT_ONERROR);
if (n != null) {
seqMediator.setName(n.getAttributeValue());
if (e != null) {
seqMediator.setErrorHandler(e.getAttributeValue());
}
processAuditStatus(seqMediator, elem);
addChildren(elem, seqMediator, properties);
} else {
n = elem.getAttribute(ATT_KEY);
if (n != null) {
// ValueFactory for creating dynamic or static Value
ValueFactory keyFac = new ValueFactory();
// create dynamic or static key based on OMElement
Value generatedKey = keyFac.createValue(XMLConfigConstants.KEY, elem);
// setKey
seqMediator.setKey(generatedKey);
if (e != null) {
String msg = "A sequence mediator with a reference to another " + "sequence can not have 'ErrorHandler'";
log.error(msg);
throw new SynapseException(msg);
}
} else {
String msg = "A sequence mediator should be a named sequence or a reference " + "to another sequence (i.e. a name attribute or key attribute is required)";
log.error(msg);
throw new SynapseException(msg);
}
}
return seqMediator;
}
use of org.apache.synapse.mediators.base.SequenceMediator in project wso2-synapse by wso2.
the class Axis2MessageContext method getSequence.
public Mediator getSequence(String key) {
Object o = localEntries.get(key);
if (o != null && o instanceof Mediator) {
return (Mediator) o;
} else {
Mediator m = getConfiguration().getSequence(key);
if (m instanceof SequenceMediator) {
SequenceMediator seqMediator = (SequenceMediator) m;
synchronized (m) {
if (!seqMediator.isInitialized()) {
seqMediator.init(synEnv);
}
}
}
localEntries.put(key, m);
return m;
}
}
use of org.apache.synapse.mediators.base.SequenceMediator in project wso2-synapse by wso2.
the class Axis2SynapseEnvironment method mediateFromContinuationStateStack.
/**
* When request is sent using a Call Mediator, mediate the response message using the
* ContinuationState Stack
* @param synCtx MessageContext
* @return whether mediation is completed
*/
private boolean mediateFromContinuationStateStack(MessageContext synCtx) {
if (log.isDebugEnabled()) {
log.debug("Mediating response using the ContinuationStateStack");
}
if (synCtx.getContinuationStateStack().isEmpty()) {
// ideally this should never happens
log.warn("ContinuationStateStack empty. No ContinuationState to mediate the response ");
return false;
}
if (RuntimeStatisticCollector.isStatisticsEnabled()) {
OpenEventCollector.openContinuationEvents(synCtx);
}
// First push fault handlers for first continuation state.
SeqContinuationState seqContinuationState = (SeqContinuationState) ContinuationStackManager.peakContinuationStateStack(synCtx);
if (seqContinuationState != null) {
ContinuationStackManager.pushFaultHandler(synCtx, seqContinuationState);
} else {
return false;
}
boolean result = false;
do {
seqContinuationState = (SeqContinuationState) ContinuationStackManager.peakContinuationStateStack(synCtx);
if (seqContinuationState != null) {
SequenceMediator sequenceMediator = ContinuationStackManager.retrieveSequence(synCtx, seqContinuationState);
// Report Statistics for this continuation call
result = sequenceMediator.mediate(synCtx, seqContinuationState);
if (RuntimeStatisticCollector.isStatisticsEnabled()) {
sequenceMediator.reportCloseStatistics(synCtx, null);
}
} else {
break;
}
// for any result close the sequence as it will be handled by the callback method in statistics
} while (result && !synCtx.getContinuationStateStack().isEmpty());
return result;
}
Aggregations